Skip to content

Commit 26aa8f8

Browse files
authored
Merge pull request #57 from joshsoftware/refactore/show_sender_name
refactore/show_sender_name
2 parents 91d5e21 + 8b6ed58 commit 26aa8f8

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

internal/app/appreciation/helper.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package appreciation
22

33
import (
4+
"strconv"
5+
"strings"
46
"github.com/joshsoftware/peerly-backend/internal/pkg/dto"
57
"github.com/joshsoftware/peerly-backend/internal/repository"
68
)
@@ -33,13 +35,13 @@ func mapRepoGetAppreciationInfoToDTOGetAppreciationInfo(info repository.Apprecia
3335
TotalRewardPoints: info.TotalRewardPoints,
3436
Quarter: info.Quarter,
3537
SenderID: info.SenderID,
36-
SenderEmployeeID: info.SenderEmployeeID,
38+
SenderEmployeeID: info.SenderEmployeeID,
3739
SenderFirstName: info.SenderFirstName,
3840
SenderLastName: info.SenderLastName,
3941
SenderImageURL: senderImageURL,
4042
SenderDesignation: info.SenderDesignation,
4143
ReceiverID: info.ReceiverID,
42-
ReceiverEmployeeID: info.ReceiverEmployeeID,
44+
ReceiverEmployeeID: info.ReceiverEmployeeID,
4345
ReceiverFirstName: info.ReceiverFirstName,
4446
ReceiverLastName: info.ReceiverLastName,
4547
ReceiverImageURL: receiverImageURL,
@@ -51,6 +53,13 @@ func mapRepoGetAppreciationInfoToDTOGetAppreciationInfo(info repository.Apprecia
5153
UpdatedAt: info.UpdatedAt,
5254
}
5355

56+
grade := strings.ToUpper(info.SenderGradeName)
57+
if strings.HasPrefix(grade, "J") {
58+
if n, err := strconv.Atoi(strings.TrimPrefix(grade, "J")); err == nil && n >= 3 && n <= 6 {
59+
dtoApprResp.ByManagement = true
60+
}
61+
}
62+
5463
return dtoApprResp
5564
}
5665

internal/pkg/dto/appreciation.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ type AppreciationResponse struct {
4040
SenderImageURL string `json:"sender_image_url"`
4141
SenderDesignation string `json:"sender_designation"`
4242
ReceiverID int64 `json:"receiver_id"`
43-
ReceiverEmployeeID string `json:"receiver_employee_id"`
43+
ReceiverEmployeeID string `json:"receiver_employee_id"`
4444
ReceiverFirstName string `json:"receiver_first_name"`
4545
ReceiverLastName string `json:"receiver_last_name"`
4646
ReceiverImageURL string `json:"receiver_image_url"`
4747
ReceiverDesignation string `json:"receiver_designation"`
4848
TotalRewards int32 `json:"total_rewards"`
4949
GivenRewardPoint int8 `json:"given_reward_point"`
5050
ReportedFlag bool `json:"reported_flag"`
51+
ByManagement bool `json:"by_management"`
5152
CreatedAt int64 `json:"created_at"`
5253
UpdatedAt int64 `json:"updated_at"`
5354
}

internal/repository/appreciation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type AppreciationResponse struct {
4646
SenderImageURL sql.NullString `db:"sender_image_url"`
4747
SenderDesignation string `db:"sender_designation"`
4848
SenderEmployeeID string `db:"sender_employee_id"`
49+
SenderGradeName string `db:"sender_grade_name"`
4950
ReceiverID int64 `db:"receiver_id"`
5051
ReceiverFirstName string `db:"receiver_first_name"`
5152
ReceiverLastName string `db:"receiver_last_name"`

internal/repository/postgresdb/appreciation.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ func (appr *appreciationsStore) GetAppreciationById(ctx context.Context, tx repo
7878
return repository.AppreciationResponse{}, apperrors.InternalServer
7979
}
8080

81+
8182
// Build the SQL query
8283
query, args, err := repository.Sq.Select(
8384
"a.id",
8485
"cv.name AS core_value_name",
86+
"cv.description AS core_value_description",
8587
"a.description",
8688
"a.is_valid",
8789
"a.total_reward_points",
@@ -91,6 +93,7 @@ func (appr *appreciationsStore) GetAppreciationById(ctx context.Context, tx repo
9193
"u_sender.last_name AS sender_last_name",
9294
"u_sender.profile_image_url AS sender_image_url",
9395
"u_sender.designation AS sender_designation",
96+
"g_sender.name AS sender_grade_name",
9497
"u_receiver.id AS receiver_id",
9598
"u_receiver.first_name AS receiver_first_name",
9699
"u_receiver.last_name AS receiver_last_name",
@@ -107,14 +110,15 @@ func (appr *appreciationsStore) GetAppreciationById(ctx context.Context, tx repo
107110
), 0) AS given_reward_point`, userID),
108111
).From(appr.AppreciationsTable+" a").
109112
LeftJoin(appr.UsersTable+" u_sender ON a.sender = u_sender.id").
113+
LeftJoin("grades g_sender ON u_sender.grade_id = g_sender.id").
110114
LeftJoin(appr.UsersTable+" u_receiver ON a.receiver = u_receiver.id").
111115
LeftJoin(appr.CoreValuesTable+" cv ON a.core_value_id = cv.id").
112116
LeftJoin(appr.RewardsTable+" r ON a.id = r.appreciation_id").
113117
Where(squirrel.And{
114118
squirrel.Eq{"a.id": apprId},
115119
squirrel.Eq{"a.is_valid": true},
116120
}).
117-
GroupBy("a.id", "cv.name", "u_sender.id", "u_receiver.id").
121+
GroupBy("a.id", "cv.name", "cv.description", "u_sender.id", "g_sender.name", "u_receiver.id").
118122
ToSql()
119123

120124
if err != nil {
@@ -213,12 +217,13 @@ func (appr *appreciationsStore) ListAppreciations(ctx context.Context, tx reposi
213217
"u_sender.profile_image_url AS sender_image_url",
214218
"u_sender.designation AS sender_designation",
215219
"u_sender.employee_id AS sender_employee_id",
220+
"g_sender.name AS sender_grade_name",
216221
"u_receiver.id AS receiver_id",
217222
"u_receiver.first_name AS receiver_first_name",
218223
"u_receiver.last_name AS receiver_last_name",
219224
"u_receiver.profile_image_url AS receiver_image_url",
220225
"u_receiver.designation AS receiver_designation",
221-
"u_receiver.employee_id AS receiver_employee_id",
226+
"u_receiver.employee_id AS receiver_employee_id",
222227
"a.created_at",
223228
"a.updated_at",
224229
"COUNT(r.id) AS total_rewards",
@@ -229,8 +234,9 @@ func (appr *appreciationsStore) ListAppreciations(ctx context.Context, tx reposi
229234
WHERE r2.appreciation_id = a.id AND r2.sender = %d
230235
), 0) AS given_reward_point`, userID),
231236
).
237+
LeftJoin("grades g_sender ON u_sender.grade_id = g_sender.id").
232238
LeftJoin("rewards r ON a.id = r.appreciation_id").
233-
GroupBy("a.id", "cv.name", "cv.description", "u_sender.id", "u_receiver.id")
239+
GroupBy("a.id", "cv.name", "cv.description", "u_sender.id", "g_sender.name", "u_receiver.id")
234240

235241
if filter.SortOrder != "" {
236242
queryBuilder = queryBuilder.OrderBy(fmt.Sprintf("a.created_at %s", filter.SortOrder))

0 commit comments

Comments
 (0)