@@ -46,6 +46,9 @@ pub struct ApplicationRating {
4646 /// ID of the application being rated
4747 #[ serde( serialize_with = "crate::models::serde_string::serialize" ) ]
4848 pub application_id : i64 ,
49+ /// ID of the user who created the rating
50+ #[ serde( serialize_with = "crate::models::serde_string::serialize" ) ]
51+ pub rater_user_id : i64 ,
4952 /// Optional comments about the application
5053 pub comment : Option < String > ,
5154 /// When the rating was created
@@ -184,7 +187,7 @@ impl Rating {
184187 /// * `Err(ChaosError)` - An error if creation fails
185188 ///
186189 pub async fn create_category (
187- new_category : NewCategoryRating ,
190+ name : String ,
188191 campaign_id : i64 ,
189192 snowflake_generator : & mut SnowflakeIdGenerator ,
190193 transaction : & mut Transaction < ' _ , Postgres > ,
@@ -193,11 +196,11 @@ impl Rating {
193196
194197 sqlx:: query!(
195198 "
196- INSERT INTO campaign_rating_categories (id, name, campaign_id)
197- VALUES ($1, $2, $3)
199+ INSERT INTO campaign_rating_categories (id, name, campaign_id)
200+ VALUES ($1, $2, $3)
198201 " ,
199202 id,
200- new_category . name,
203+ name,
201204 campaign_id
202205 )
203206 . execute ( transaction. deref_mut ( ) )
@@ -223,9 +226,9 @@ impl Rating {
223226 let categories = sqlx:: query_as!(
224227 CategoryRating ,
225228 "
226- SELECT id, name, campaign_id
227- FROM campaign_rating_categories
228- WHERE campaign_id = $1
229+ SELECT id, name, campaign_id
230+ FROM campaign_rating_categories
231+ WHERE campaign_id = $1
229232 " ,
230233 campaign_id
231234 )
@@ -248,18 +251,16 @@ impl Rating {
248251 /// * `Err(ChaosError)` - An error if update fails
249252 pub async fn update_category (
250253 category_id : i64 ,
251- updated_category : NewCategoryRating ,
254+ name : String ,
252255 transaction : & mut Transaction < ' _ , Postgres > ,
253256 ) -> Result < ( ) , ChaosError > {
254- let name = updated_category. name ;
255-
256257 let _ = sqlx:: query!(
257258 "
258- UPDATE campaign_rating_categories
259- SET name = $2
260- WHERE id = $1
261- RETURNING id
262- " ,
259+ UPDATE campaign_rating_categories
260+ SET name = $2
261+ WHERE id = $1
262+ RETURNING id
263+ " ,
263264 category_id,
264265 name,
265266 )
@@ -276,8 +277,8 @@ impl Rating {
276277 ) -> Result < ( ) , ChaosError > {
277278 let _ = sqlx:: query!(
278279 "
279- DELETE FROM campaign_rating_categories WHERE id = $1
280- RETURNING id
280+ DELETE FROM campaign_rating_categories WHERE id = $1
281+ RETURNING id
281282 " ,
282283 category_id
283284 )
@@ -304,20 +305,19 @@ impl Rating {
304305 /// * `Ok(())` - If the rating was created successfully
305306 /// * `Err(ChaosError)` - An error if creation fails
306307 pub async fn create_application_rating (
307- new_rating : NewApplicationRating ,
308+ comment : Option < String > ,
308309 application_id : i64 ,
309310 rater_id : i64 ,
310311 snowflake_generator : & mut SnowflakeIdGenerator ,
311312 transaction : & mut Transaction < ' _ , Postgres > ,
312313 ) -> Result < i64 , ChaosError > {
313314 let rating_id = snowflake_generator. real_time_generate ( ) ;
314- let comment = new_rating. comment ;
315315
316316 sqlx:: query!(
317317 "
318- INSERT INTO application_ratings (id, application_id, rater_id, comment)
319- VALUES ($1, $2, $3, $4)
320- " ,
318+ INSERT INTO application_ratings (id, application_id, rater_id, comment)
319+ VALUES ($1, $2, $3, $4)
320+ " ,
321321 rating_id,
322322 application_id,
323323 rater_id,
@@ -342,19 +342,18 @@ impl Rating {
342342 /// * `Err(ChaosError)` - An error if update fails
343343 pub async fn update_application_rating (
344344 rating_id : i64 ,
345- updated_rating : NewApplicationRating ,
345+ comment : Option < String > ,
346346 transaction : & mut Transaction < ' _ , Postgres > ,
347347 ) -> Result < ( ) , ChaosError > {
348- let comment = updated_rating. comment ;
349348 let current_time = Utc :: now ( ) ;
350349
351350 let _ = sqlx:: query!(
352351 "
353- UPDATE application_ratings
354- SET comment = $2, updated_at = $3
355- WHERE id = $1
356- RETURNING id
357- " ,
352+ UPDATE application_ratings
353+ SET comment = $2, updated_at = $3
354+ WHERE id = $1
355+ RETURNING id
356+ " ,
358357 rating_id,
359358 comment,
360359 current_time
@@ -382,9 +381,9 @@ impl Rating {
382381 // Throws error if rating id doesn't exist.
383382 let _ = sqlx:: query!(
384383 "
385- DELETE FROM application_ratings WHERE id = $1
386- RETURNING id
387- " ,
384+ DELETE FROM application_ratings WHERE id = $1
385+ RETURNING id
386+ " ,
388387 rating_id
389388 )
390389 . fetch_one ( transaction. deref_mut ( ) )
@@ -393,74 +392,6 @@ impl Rating {
393392 Ok ( ( ) )
394393 }
395394
396- // /// -------------- GET requests for ApplicationRating: ONLY COMMENT ----------------------
397- ///// ============================ NOT NEEDED (COMMNET IS IN ANOTHER FUNCTION ALR)===================
398-
399- // /// Retrieves a rating by its ID, able to see which application is being rated,
400- // /// ONLY THE COMMENT IS VIEWED,
401- // /// NOT Vector of numerical scores
402- // ///
403- // /// # Arguments
404- // /// * `rating_id` - The ID of the rating to retrieve
405- // /// * `transaction` - A mutable reference to the database transaction
406- // ///
407- // /// # Returns
408- // /// Returns a `Result` containing either:
409- // /// * `Ok(RatingDetails)` - The requested rating details
410- // /// * `Err(ChaosError)` - An error if retrieval fails
411- // pub async fn get_comment_rating(
412- // rating_id: i64,
413- // transaction: &mut Transaction<'_, Postgres>,
414- // ) -> Result<RatingDetails, ChaosError> {
415- // let rating = sqlx::query_as!(
416- // RatingDetails,
417- // "
418- // SELECT r.id, rater_id, u.name as rater_name, r.comment, r.updated_at
419- // FROM application_ratings r
420- // JOIN users u ON u.id = r.rater_id
421- // WHERE r.id = $1
422- // ",
423- // rating_id
424- // )
425- // .fetch_one(transaction.deref_mut())
426- // .await?;
427-
428- // Ok(rating)
429- // }
430-
431- // /// Retrieves a rating by application_ID. (UNCONFIRMED: Want it to be seperate?)
432- // /// ONLY THE COMMENT IS VIEWED,
433- // /// NOT Vector of numerical scores
434- // ///
435- // /// # Arguments
436- // /// * `application_id` - The ID of the application the rating is for
437- // /// * `rater_id` - The ID of the rater
438- // /// * `transaction` - A mutable reference to the database transaction
439- // ///
440- // /// # Returns
441- // /// Returns a `Result` containing either:
442- // /// * `Ok(RatingDetails)` - The requested rating details
443- // /// * `Err(ChaosError)` - An error if retrieval fails
444- // pub async fn get_comment_rating_by_application_id(
445- // application_id: i64,
446- // transaction: &mut Transaction<'_, Postgres>,
447- // ) -> Result<RatingDetails, ChaosError> {
448- // let rating = sqlx::query_as!(
449- // RatingDetails,
450- // "
451- // SELECT r.id, rater_id, u.name as rater_name, r.comment, r.updated_at
452- // FROM application_ratings r
453- // JOIN users u ON u.id = r.rater_id
454- // WHERE r.application_id = $1
455- // ",
456- // application_id,
457- // )
458- // .fetch_one(transaction.deref_mut())
459- // .await?;
460-
461- // Ok(rating)
462- // }
463-
464395 // ------------------- GET requests for ApplicationRating: Get Rating Details -------------------
465396
466397 /// Retrieves detailed rating information with
0 commit comments