mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
adjust get all phase activity
This commit is contained in:
@@ -28,20 +28,12 @@ func (u *PhaseActivityController) GetAll(c *fiber.Ctx) error {
|
|||||||
Limit: c.QueryInt("limit", 10),
|
Limit: c.QueryInt("limit", 10),
|
||||||
Search: c.Query("search", ""),
|
Search: c.Query("search", ""),
|
||||||
}
|
}
|
||||||
|
query.PhaseIDs = c.Query("phase_ids", "")
|
||||||
|
|
||||||
if query.Page < 1 || query.Limit < 1 {
|
if query.Page < 1 || query.Limit < 1 {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
if phaseParam := c.Query("phase_id", ""); phaseParam != "" {
|
|
||||||
id, err := strconv.Atoi(phaseParam)
|
|
||||||
if err != nil || id <= 0 {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, "invalid phase_id")
|
|
||||||
}
|
|
||||||
temp := uint(id)
|
|
||||||
query.PhaseId = &temp
|
|
||||||
}
|
|
||||||
|
|
||||||
result, totalResults, err := u.PhaseActivityService.GetAll(c, query)
|
result, totalResults, err := u.PhaseActivityService.GetAll(c, query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||||
@@ -57,8 +58,11 @@ func (s phaseActivityService) GetAll(c *fiber.Ctx, params *validation.Query) ([]
|
|||||||
if params.Search != "" {
|
if params.Search != "" {
|
||||||
db = db.Where("name LIKE ?", "%"+params.Search+"%")
|
db = db.Where("name LIKE ?", "%"+params.Search+"%")
|
||||||
}
|
}
|
||||||
if params.PhaseId != nil {
|
if params.PhaseIDs != "" {
|
||||||
db = db.Where("phase_id = ?", *params.PhaseId)
|
ids := parseIDs(params.PhaseIDs)
|
||||||
|
if len(ids) > 0 {
|
||||||
|
db = db.Where("phase_id IN ?", ids)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||||
})
|
})
|
||||||
@@ -166,3 +170,18 @@ func (s phaseActivityService) DeleteOne(c *fiber.Ctx, id uint) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseIDs(raw string) []uint {
|
||||||
|
parts := strings.Split(raw, ",")
|
||||||
|
results := make([]uint, 0, len(parts))
|
||||||
|
for _, part := range parts {
|
||||||
|
value := strings.TrimSpace(part)
|
||||||
|
if value == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if n, err := strconv.ParseUint(value, 10, 64); err == nil {
|
||||||
|
results = append(results, uint(n))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ type Update struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Query struct {
|
type Query struct {
|
||||||
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
|
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
|
||||||
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"`
|
||||||
PhaseId *uint `query:"phase_id" validate:"omitempty"`
|
PhaseIDs string `query:"phase_ids" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user