@@ -78,8 +78,6 @@ func (appr *appreciationsStore) GetAppreciationById(ctx context.Context, tx repo
7878 return repository.AppreciationResponse {}, apperrors .InternalServer
7979 }
8080
81-
82- // Build the SQL query
8381 query , args , err := repository .Sq .Select (
8482 "a.id" ,
8583 "cv.name AS core_value_name" ,
@@ -93,7 +91,7 @@ func (appr *appreciationsStore) GetAppreciationById(ctx context.Context, tx repo
9391 "u_sender.last_name AS sender_last_name" ,
9492 "u_sender.profile_image_url AS sender_image_url" ,
9593 "u_sender.designation AS sender_designation" ,
96- "g_sender.name AS sender_grade_name " ,
94+ "u_sender.grade_id AS sender_grade_id " ,
9795 "u_receiver.id AS receiver_id" ,
9896 "u_receiver.first_name AS receiver_first_name" ,
9997 "u_receiver.last_name AS receiver_last_name" ,
@@ -104,21 +102,20 @@ func (appr *appreciationsStore) GetAppreciationById(ctx context.Context, tx repo
104102 "COUNT(r.id) AS total_rewards" ,
105103 fmt .Sprintf (
106104 `COALESCE((
107- SELECT SUM(r2.point)
108- FROM rewards r2
109- WHERE r2.appreciation_id = a.id AND r2.sender = %d
110- ), 0) AS given_reward_point` , userID ),
105+ SELECT SUM(r2.point)
106+ FROM rewards r2
107+ WHERE r2.appreciation_id = a.id AND r2.sender = %d
108+ ), 0) AS given_reward_point` , userID ),
111109 ).From (appr .AppreciationsTable + " a" ).
112110 LeftJoin (appr .UsersTable + " u_sender ON a.sender = u_sender.id" ).
113- LeftJoin ("grades g_sender ON u_sender.grade_id = g_sender.id" ).
114111 LeftJoin (appr .UsersTable + " u_receiver ON a.receiver = u_receiver.id" ).
115112 LeftJoin (appr .CoreValuesTable + " cv ON a.core_value_id = cv.id" ).
116113 LeftJoin (appr .RewardsTable + " r ON a.id = r.appreciation_id" ).
117114 Where (squirrel.And {
118115 squirrel.Eq {"a.id" : apprId },
119116 squirrel.Eq {"a.is_valid" : true },
120117 }).
121- GroupBy ("a.id" , "cv.name" , "cv.description" , "u_sender.id" , "g_sender.name" , " u_receiver.id" ).
118+ GroupBy ("a.id" , "cv.name" , "cv.description" , "u_sender.id" , "u_receiver.id" ). // Removed g_sender.name from GroupBy
122119 ToSql ()
123120
124121 if err != nil {
@@ -217,7 +214,7 @@ func (appr *appreciationsStore) ListAppreciations(ctx context.Context, tx reposi
217214 "u_sender.profile_image_url AS sender_image_url" ,
218215 "u_sender.designation AS sender_designation" ,
219216 "u_sender.employee_id AS sender_employee_id" ,
220- "g_sender.name AS sender_grade_name" ,
217+ "u_sender.grade_id AS sender_grade_id" , // Select grade_id directly
221218 "u_receiver.id AS receiver_id" ,
222219 "u_receiver.first_name AS receiver_first_name" ,
223220 "u_receiver.last_name AS receiver_last_name" ,
@@ -234,9 +231,8 @@ func (appr *appreciationsStore) ListAppreciations(ctx context.Context, tx reposi
234231 WHERE r2.appreciation_id = a.id AND r2.sender = %d
235232 ), 0) AS given_reward_point` , userID ),
236233 ).
237- LeftJoin ("grades g_sender ON u_sender.grade_id = g_sender.id" ).
238234 LeftJoin ("rewards r ON a.id = r.appreciation_id" ).
239- GroupBy ("a.id" , "cv.name" , "cv.description" , "u_sender.id" , "g_sender.name" , " u_receiver.id" )
235+ GroupBy ("a.id" , "cv.name" , "cv.description" , "u_sender.id" , "u_receiver.id" )
240236
241237 if filter .SortOrder != "" {
242238 queryBuilder = queryBuilder .OrderBy (fmt .Sprintf ("a.created_at %s" , filter .SortOrder ))
0 commit comments