mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-22 14:25:45 +00:00
fix(BE): sorting by date approval get all
This commit is contained in:
@@ -44,6 +44,15 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
|
||||
page := c.QueryInt("page", 1)
|
||||
limit := c.QueryInt("limit", 10)
|
||||
search := strings.TrimSpace(c.Query("search", ""))
|
||||
sortByDate := strings.TrimSpace(c.Query("sort_by_date", ""))
|
||||
if sortByDate == "" {
|
||||
sortByDate = "DESC"
|
||||
} else {
|
||||
sortByDate = strings.ToUpper(sortByDate)
|
||||
if sortByDate != "ASC" && sortByDate != "DESC" {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "sort_by_date must be either ASC or DESC")
|
||||
}
|
||||
}
|
||||
|
||||
query := &validation.Query{
|
||||
ModuleName: moduleName,
|
||||
@@ -52,6 +61,7 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Search: search,
|
||||
SortByDate: sortByDate,
|
||||
}
|
||||
|
||||
records, totalResults, err := u.ApprovalService.List(
|
||||
@@ -61,6 +71,7 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
|
||||
query.Page,
|
||||
query.Limit,
|
||||
query.Search,
|
||||
query.SortByDate,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -7,4 +7,5 @@ type Query struct {
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
SortByDate string `query:"sort_by_date" validate:"omitempty,oneof=ASC DESC"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user