Merge branch 'fix/sort-approval' into 'development'

fix(BE): change name from sort to order

See merge request mbugroup/lti-api!264
This commit is contained in:
Hafizh A. Y.
2026-01-27 08:31:17 +00:00
3 changed files with 15 additions and 15 deletions
@@ -15,7 +15,7 @@ type ApprovalService interface {
WorkflowSteps(workflow approvalutils.ApprovalWorkflowKey) map[approvalutils.ApprovalStep]string WorkflowSteps(workflow approvalutils.ApprovalWorkflowKey) map[approvalutils.ApprovalStep]string
WorkflowStepName(workflow approvalutils.ApprovalWorkflowKey, step approvalutils.ApprovalStep) (string, bool) WorkflowStepName(workflow approvalutils.ApprovalWorkflowKey, step approvalutils.ApprovalStep) (string, bool)
CreateApproval(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, step approvalutils.ApprovalStep, action *entity.ApprovalAction, actorID uint, note *string) (*entity.Approval, error) CreateApproval(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, step approvalutils.ApprovalStep, action *entity.ApprovalAction, actorID uint, note *string) (*entity.Approval, error)
List(ctx context.Context, module string, approvableID *uint, page, limit int, search string, sortByDate string) ([]entity.Approval, int64, error) List(ctx context.Context, module string, approvableID *uint, page, limit int, search string, orderByDate string) ([]entity.Approval, int64, error)
ListByTarget(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, modifier func(*gorm.DB) *gorm.DB) ([]entity.Approval, error) ListByTarget(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, modifier func(*gorm.DB) *gorm.DB) ([]entity.Approval, error)
LatestByTarget(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, modifier func(*gorm.DB) *gorm.DB) (*entity.Approval, error) LatestByTarget(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, modifier func(*gorm.DB) *gorm.DB) (*entity.Approval, error)
LatestByTargets(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableIDs []uint, modifier func(*gorm.DB) *gorm.DB) (map[uint]*entity.Approval, error) LatestByTargets(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableIDs []uint, modifier func(*gorm.DB) *gorm.DB) (map[uint]*entity.Approval, error)
@@ -70,13 +70,13 @@ func (s *approvalService) List(
approvableID *uint, approvableID *uint,
page, limit int, page, limit int,
search string, search string,
sortByDate string, orderByDate string,
) ([]entity.Approval, int64, error) { ) ([]entity.Approval, int64, error) {
module = strings.TrimSpace(strings.ToUpper(module)) module = strings.TrimSpace(strings.ToUpper(module))
search = strings.TrimSpace(search) search = strings.TrimSpace(search)
sortByDate = strings.TrimSpace(strings.ToUpper(sortByDate)) orderByDate = strings.TrimSpace(strings.ToUpper(orderByDate))
if sortByDate != "ASC" && sortByDate != "DESC" { if orderByDate != "ASC" && orderByDate != "DESC" {
sortByDate = "DESC" orderByDate = "DESC"
} }
if limit <= 0 { if limit <= 0 {
@@ -95,7 +95,7 @@ func (s *approvalService) List(
func(db *gorm.DB) *gorm.DB { func(db *gorm.DB) *gorm.DB {
query := db. query := db.
Where("approvable_type = ?", module). Where("approvable_type = ?", module).
Order("action_at " + sortByDate). Order("action_at " + orderByDate).
Preload("ActionUser") Preload("ActionUser")
if approvableID != nil { if approvableID != nil {
@@ -44,13 +44,13 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
page := c.QueryInt("page", 1) page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) limit := c.QueryInt("limit", 10)
search := strings.TrimSpace(c.Query("search", "")) search := strings.TrimSpace(c.Query("search", ""))
sortByDate := strings.TrimSpace(c.Query("sort_by_date", "")) orderByDate := strings.TrimSpace(c.Query("order_by_date", ""))
if sortByDate == "" { if orderByDate == "" {
sortByDate = "DESC" orderByDate = "DESC"
} else { } else {
sortByDate = strings.ToUpper(sortByDate) orderByDate = strings.ToUpper(orderByDate)
if sortByDate != "ASC" && sortByDate != "DESC" { if orderByDate != "ASC" && orderByDate != "DESC" {
return fiber.NewError(fiber.StatusBadRequest, "sort_by_date must be either ASC or DESC") return fiber.NewError(fiber.StatusBadRequest, "order_by_date must be either ASC or DESC")
} }
} }
@@ -61,7 +61,7 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
Page: page, Page: page,
Limit: limit, Limit: limit,
Search: search, Search: search,
SortByDate: sortByDate, OrderByDate: orderByDate,
} }
records, totalResults, err := u.ApprovalService.List( records, totalResults, err := u.ApprovalService.List(
@@ -71,7 +71,7 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
query.Page, query.Page,
query.Limit, query.Limit,
query.Search, query.Search,
query.SortByDate, query.OrderByDate,
) )
if err != nil { if err != nil {
return err return err
@@ -7,5 +7,5 @@ type Query struct {
Page int `query:"page" validate:"omitempty,number,min=1"` Page int `query:"page" validate:"omitempty,number,min=1"`
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"` Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
Search string `query:"search" validate:"omitempty,max=50"` Search string `query:"search" validate:"omitempty,max=50"`
SortByDate string `query:"sort_by_date" validate:"omitempty,oneof=ASC DESC"` OrderByDate string `query:"order_by_date" validate:"omitempty,oneof=ASC DESC"`
} }