mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'fix/master-data-kandang' into 'development'
[FIX][BE] Master Data Kandang See merge request mbugroup/lti-api!501
This commit is contained in:
@@ -29,6 +29,8 @@ func (u *KandangGroupController) GetAll(c *fiber.Ctx) error {
|
|||||||
Search: c.Query("search", ""),
|
Search: c.Query("search", ""),
|
||||||
LocationId: c.QueryInt("location_id", 0),
|
LocationId: c.QueryInt("location_id", 0),
|
||||||
PicId: c.QueryInt("pic_id", 0),
|
PicId: c.QueryInt("pic_id", 0),
|
||||||
|
OrderBy: c.Query("order_by", "desc"),
|
||||||
|
SortBy: c.Query("sort_by", "updated_at"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if query.Page < 1 || query.Limit < 1 {
|
if query.Page < 1 || query.Limit < 1 {
|
||||||
|
|||||||
@@ -70,7 +70,14 @@ func (s kandangGroupService) GetAll(c *fiber.Ctx, params *validation.Query) ([]e
|
|||||||
if params.PicId != 0 {
|
if params.PicId != 0 {
|
||||||
db = db.Where("kandang_groups.pic_id = ?", params.PicId)
|
db = db.Where("kandang_groups.pic_id = ?", params.PicId)
|
||||||
}
|
}
|
||||||
return db.Order("kandang_groups.created_at DESC").Order("kandang_groups.updated_at DESC")
|
|
||||||
|
if params.OrderBy == "desc" || params.OrderBy == "" {
|
||||||
|
db = db.Order(fmt.Sprintf("kandang_groups.%s DESC", params.SortBy))
|
||||||
|
} else {
|
||||||
|
db = db.Order(fmt.Sprintf("kandang_groups.%s ASC", params.SortBy))
|
||||||
|
}
|
||||||
|
|
||||||
|
return db
|
||||||
})
|
})
|
||||||
|
|
||||||
if scopeErr != nil {
|
if scopeErr != nil {
|
||||||
|
|||||||
@@ -20,4 +20,6 @@ type Query struct {
|
|||||||
Search string `query:"search" validate:"omitempty,max=50"`
|
Search string `query:"search" validate:"omitempty,max=50"`
|
||||||
LocationId int `query:"location_id" validate:"omitempty,number,gt=0"`
|
LocationId int `query:"location_id" validate:"omitempty,number,gt=0"`
|
||||||
PicId int `query:"pic_id" validate:"omitempty,number,gt=0"`
|
PicId int `query:"pic_id" validate:"omitempty,number,gt=0"`
|
||||||
|
SortBy string `query:"sort_by" validate:"omitempty,max=50,oneof=name created_at updated_at" default:"updated_at"`
|
||||||
|
OrderBy string `query:"order_by" validate:"omitempty,oneof=asc desc" default:"desc"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ func (u *KandangController) GetAll(c *fiber.Ctx) error {
|
|||||||
Search: c.Query("search", ""),
|
Search: c.Query("search", ""),
|
||||||
LocationId: c.QueryInt("location_id", 0),
|
LocationId: c.QueryInt("location_id", 0),
|
||||||
PicId: c.QueryInt("pic_id", 0),
|
PicId: c.QueryInt("pic_id", 0),
|
||||||
|
OrderBy: c.Query("order_by", "desc"),
|
||||||
|
SortBy: c.Query("sort_by", "created_at"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if query.Page < 1 || query.Limit < 1 {
|
if query.Page < 1 || query.Limit < 1 {
|
||||||
|
|||||||
@@ -66,7 +66,14 @@ func (s kandangService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity
|
|||||||
if params.PicId != 0 {
|
if params.PicId != 0 {
|
||||||
db = db.Where("pic_id = ?", params.PicId)
|
db = db.Where("pic_id = ?", params.PicId)
|
||||||
}
|
}
|
||||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
|
||||||
|
if params.OrderBy == "desc" || params.OrderBy == "" {
|
||||||
|
db = db.Order(fmt.Sprintf("%s DESC", params.SortBy))
|
||||||
|
} else {
|
||||||
|
db = db.Order(fmt.Sprintf("%s ASC", params.SortBy))
|
||||||
|
}
|
||||||
|
|
||||||
|
return db
|
||||||
})
|
})
|
||||||
|
|
||||||
if scopeErr != nil {
|
if scopeErr != nil {
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ type Query struct {
|
|||||||
Search string `query:"search" validate:"omitempty,max=50"`
|
Search string `query:"search" validate:"omitempty,max=50"`
|
||||||
LocationId int `query:"location_id" validate:"omitempty,number,gt=0"`
|
LocationId int `query:"location_id" validate:"omitempty,number,gt=0"`
|
||||||
PicId int `query:"pic_id" validate:"omitempty,number,gt=0"`
|
PicId int `query:"pic_id" validate:"omitempty,number,gt=0"`
|
||||||
|
SortBy string `query:"sort_by" validate:"omitempty,max=50,oneof=name created_at updated_at" default:"updated_at"`
|
||||||
|
OrderBy string `query:"order_by" validate:"omitempty,oneof=asc desc" default:"desc"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user