Skip to content

Commit

Permalink
feature: added username for group_bills
Browse files Browse the repository at this point in the history
  • Loading branch information
SpeedReach committed Jun 1, 2024
1 parent e29d89b commit d0c9ef2
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 130 deletions.
20 changes: 16 additions & 4 deletions internal/services/group_bill/list_bills.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ func getGroupBills(ctx context.Context, db *sql.DB, logger *zap.Logger, groupId
func getGroupBillSplits(ctx context.Context, db *sql.DB, logger *zap.Logger, billId uuid.UUID) ([]*monify.SplitPerson, error) {
var splits []*monify.SplitPerson
rows, err := db.QueryContext(ctx, `
SELECT person, amount FROM group_split_bill WHERE bill_id = $1
SELECT person, amount ,ui.name
FROM group_split_bill
LEFT JOIN group_member gm ON group_split_bill.person = gm.group_member_id
LEFT JOIN user_identity ui ON gm.user_id = ui.user_id
WHERE bill_id = $1
`, billId)
if err != nil {
logger.Error("", zap.Error(err))
Expand All @@ -99,13 +103,15 @@ func getGroupBillSplits(ctx context.Context, db *sql.DB, logger *zap.Logger, bil
for rows.Next() {
var memberId uuid.UUID
var amount float64
err = rows.Scan(&memberId, &amount)
var username string
err = rows.Scan(&memberId, &amount, &username)
if err != nil {
return []*monify.SplitPerson{}, err
}
splits = append(splits, &monify.SplitPerson{
MemberId: memberId.String(),
Amount: amount,
Username: username,
})
}
return splits, nil
Expand All @@ -114,7 +120,11 @@ func getGroupBillSplits(ctx context.Context, db *sql.DB, logger *zap.Logger, bil
func getGroupBillPrepaid(ctx context.Context, db *sql.DB, logger *zap.Logger, billId uuid.UUID) ([]*monify.PrepaidPerson, error) {
var prepaid []*monify.PrepaidPerson
rows, err := db.QueryContext(ctx, `
SELECT person, amount FROM group_prepaid_bill WHERE bill_id = $1
SELECT person, amount , ui.name
FROM group_prepaid_bill
LEFT JOIN group_member gm ON group_prepaid_bill.person = gm.group_member_id
LEFT JOIN user_identity ui ON gm.user_id = ui.user_id
WHERE bill_id = $1
`, billId)
if err != nil {
logger.Error("", zap.Error(err))
Expand All @@ -124,13 +134,15 @@ func getGroupBillPrepaid(ctx context.Context, db *sql.DB, logger *zap.Logger, bi
for rows.Next() {
var memberId uuid.UUID
var amount float64
err = rows.Scan(&memberId, &amount)
var username string
err = rows.Scan(&memberId, &amount, &username)
if err != nil {
return []*monify.PrepaidPerson{}, err
}
prepaid = append(prepaid, &monify.PrepaidPerson{
MemberId: memberId.String(),
Amount: amount,
Username: username,
})
}
return prepaid, nil
Expand Down
Loading

0 comments on commit d0c9ef2

Please sign in to comment.