Skip to content

Commit

Permalink
bugfix: to-claims-voucher (#91)
Browse files Browse the repository at this point in the history
bugfix: to-claims-voucher
  • Loading branch information
masnann authored Dec 6, 2023
2 parents 5293e57 + 18f443f commit a51ee04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion module/feature/voucher/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (h *VoucherHandler) GetAllVouchersToClaims() echo.HandlerFunc {
return response.SendStatusForbiddenResponse(c, "Tidak diizinkan: Anda tidak memiliki izin")
}

limit := 3
limit := 7
result, err := h.service.GetAllVoucherToClaims(limit, currentUser.ID)
if err != nil {
return response.SendStatusInternalServerResponse(c, "Gagal mendapatkan daftar kupon: "+err.Error())
Expand Down
23 changes: 17 additions & 6 deletions module/feature/voucher/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,23 @@ func (r *VoucherRepository) FindAllVoucherToClaims(limit int, userID uint64) ([]
}

var vouchers []*entities.VoucherModels
err = r.db.
Order("created_at DESC").
Limit(limit).
Where("deleted_at IS NULL AND (id NOT IN ? OR id IS NULL) AND end_date > ? AND stock > 0", claimedVoucherIDs, time.Now()).
Find(&vouchers).
Error

if len(claimedVoucherIDs) > 0 {
err = r.db.
Order("created_at DESC").
Limit(limit).
Where("deleted_at IS NULL AND (id NOT IN ? OR id IS NULL) AND end_date > ? AND stock > 0", claimedVoucherIDs, time.Now()).
Find(&vouchers).
Error
} else {
err = r.db.
Order("created_at DESC").
Limit(limit).
Where("deleted_at IS NULL AND end_date > ? AND stock > 0", time.Now()).
Find(&vouchers).
Error
}

if err != nil {
return nil, err
}
Expand Down

0 comments on commit a51ee04

Please sign in to comment.