mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
Merge branch 'development' into 'production'
Development See merge request mbugroup/lti-api!414
This commit is contained in:
@@ -33,6 +33,14 @@ func (u *CustomerController) GetAll(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
|
||||
if hasMarketingParam := c.Query("has_marketing", ""); hasMarketingParam != "" {
|
||||
value, err := strconv.ParseBool(hasMarketingParam)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "invalid has_marketing value")
|
||||
}
|
||||
query.HasMarketing = &value
|
||||
}
|
||||
|
||||
result, totalResults, err := u.CustomerService.GetAll(c, query)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -53,7 +53,28 @@ func (s customerService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
customers, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
||||
db = s.withRelations(db)
|
||||
if params.Search != "" {
|
||||
return db.Where("name ILIKE ?", "%"+params.Search+"%")
|
||||
db = db.Where("name ILIKE ?", "%"+params.Search+"%")
|
||||
if params.HasMarketing != nil && *params.HasMarketing {
|
||||
db = db.Where(`
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM marketings
|
||||
WHERE marketings.customer_id = customers.id
|
||||
AND marketings.deleted_at IS NULL
|
||||
)
|
||||
`)
|
||||
}
|
||||
return db
|
||||
}
|
||||
if params.HasMarketing != nil && *params.HasMarketing {
|
||||
db = db.Where(`
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM marketings
|
||||
WHERE marketings.customer_id = customers.id
|
||||
AND marketings.deleted_at IS NULL
|
||||
)
|
||||
`)
|
||||
}
|
||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||
})
|
||||
|
||||
@@ -21,7 +21,8 @@ type Update struct {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
HasMarketing *bool `query:"has_marketing" validate:"omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user