mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +00:00
Merge branch 'fix/daily-checklist' into 'development'
[FIX][BE] Daily Checklist See merge request mbugroup/lti-api!502
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_daily_checklists_unique_non_rejected;
|
||||||
|
|
||||||
|
ALTER TABLE daily_checklists
|
||||||
|
ADD CONSTRAINT daily_checklists_date_kandang_category_key
|
||||||
|
UNIQUE (date, kandang_id, category);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE daily_checklists
|
||||||
|
DROP CONSTRAINT IF EXISTS daily_checklists_date_kandang_category_key;
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_daily_checklists_unique_non_rejected
|
||||||
|
ON daily_checklists (date, kandang_id, category)
|
||||||
|
WHERE (status IS NULL OR status <> 'REJECTED');
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -277,7 +277,11 @@ func (s dailyChecklistService) GetAll(c *fiber.Ctx, params *validation.Query) ([
|
|||||||
normalizedSearch := re.ReplaceAllString(params.Search, "")
|
normalizedSearch := re.ReplaceAllString(params.Search, "")
|
||||||
if normalizedSearch != "" {
|
if normalizedSearch != "" {
|
||||||
like := "%" + normalizedSearch + "%"
|
like := "%" + normalizedSearch + "%"
|
||||||
db = db.Where("(regexp_replace(k.name, '[^a-zA-Z0-9]', '', 'g') ILIKE ? OR regexp_replace(dc.category::text, '[^a-zA-Z0-9]', '', 'g') ILIKE ?)", like, like)
|
db = db.Where(`(
|
||||||
|
regexp_replace(k.name, '[^a-zA-Z0-9]', '', 'g') ILIKE ? OR
|
||||||
|
regexp_replace(dc.category::text, '[^a-zA-Z0-9]', '', 'g') ILIKE ? OR
|
||||||
|
(dc.category = 'empty_kandang' AND regexp_replace('Kandang Kosong', '[^a-zA-Z0-9]', '', 'g') ILIKE ?)
|
||||||
|
)`, like, like, like)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,11 @@ func NewEmployeesController(employeesService service.EmployeesService) *Employee
|
|||||||
|
|
||||||
func (u *EmployeesController) GetAll(c *fiber.Ctx) error {
|
func (u *EmployeesController) GetAll(c *fiber.Ctx) error {
|
||||||
query := &validation.Query{
|
query := &validation.Query{
|
||||||
Page: c.QueryInt("page", 1),
|
Page: c.QueryInt("page", 1),
|
||||||
Limit: c.QueryInt("limit", 10),
|
Limit: c.QueryInt("limit", 10),
|
||||||
Search: c.Query("search", ""),
|
Search: c.Query("search", ""),
|
||||||
|
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 {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||||
@@ -126,11 +127,18 @@ func (s employeesService) GetAll(c *fiber.Ctx, params *validation.Query) ([]enti
|
|||||||
if params.IsActive != nil {
|
if params.IsActive != nil {
|
||||||
db = db.Where("employees.is_active = ?", *params.IsActive)
|
db = db.Where("employees.is_active = ?", *params.IsActive)
|
||||||
}
|
}
|
||||||
return db.
|
|
||||||
|
db = db.
|
||||||
Select("employees.id, employees.name, employees.is_active, employees.created_at, employees.updated_at").
|
Select("employees.id, employees.name, employees.is_active, employees.created_at, employees.updated_at").
|
||||||
Group("employees.id, employees.name, employees.is_active, employees.created_at, employees.updated_at").
|
Group("employees.id, employees.name, employees.is_active, employees.created_at, employees.updated_at")
|
||||||
Order("employees.created_at DESC").
|
|
||||||
Order("employees.updated_at DESC")
|
if params.OrderBy == "desc" || params.OrderBy == "" {
|
||||||
|
db = db.Order(fmt.Sprintf("employees.%s DESC", params.SortBy))
|
||||||
|
} else {
|
||||||
|
db = db.Order(fmt.Sprintf("employees.%s ASC", params.SortBy))
|
||||||
|
}
|
||||||
|
|
||||||
|
return db
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -18,4 +18,6 @@ type Query struct {
|
|||||||
Search string `query:"search" validate:"omitempty,max=50"`
|
Search string `query:"search" validate:"omitempty,max=50"`
|
||||||
KandangId *uint `query:"kandang_id" validate:"omitempty"`
|
KandangId *uint `query:"kandang_id" validate:"omitempty"`
|
||||||
IsActive *bool `query:"is_active" validate:"omitempty"`
|
IsActive *bool `query:"is_active" validate:"omitempty"`
|
||||||
|
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