mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix(BE): multiple filter, all search
This commit is contained in:
@@ -24,46 +24,81 @@ func NewTransactionController(transactionService service.TransactionService) *Tr
|
||||
}
|
||||
|
||||
func (u *TransactionController) GetAll(c *fiber.Ctx) error {
|
||||
parseOptionalUint := func(key string) (*uint, error) {
|
||||
parseUintListParam := func(key string) ([]uint, error) {
|
||||
raw := strings.TrimSpace(c.Query(key, ""))
|
||||
if raw == "" {
|
||||
return nil, nil
|
||||
}
|
||||
parsed, err := strconv.ParseUint(raw, 10, 64)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Invalid "+key)
|
||||
parts := strings.Split(raw, ",")
|
||||
ids := make([]uint, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
trimmed := strings.TrimSpace(part)
|
||||
if trimmed == "" {
|
||||
return nil, strconv.ErrSyntax
|
||||
}
|
||||
parsed, err := strconv.ParseUint(trimmed, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if parsed == 0 {
|
||||
continue
|
||||
}
|
||||
ids = append(ids, uint(parsed))
|
||||
}
|
||||
if parsed == 0 {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
value := uint(parsed)
|
||||
return &value, nil
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
bankId, err := parseOptionalUint("bank_id")
|
||||
if err != nil {
|
||||
return err
|
||||
parseStringListParam := func(key string) ([]string, error) {
|
||||
raw := strings.TrimSpace(c.Query(key, ""))
|
||||
if raw == "" {
|
||||
return nil, nil
|
||||
}
|
||||
parts := strings.Split(raw, ",")
|
||||
values := make([]string, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
trimmed := strings.TrimSpace(part)
|
||||
if trimmed == "" {
|
||||
return nil, strconv.ErrSyntax
|
||||
}
|
||||
values = append(values, trimmed)
|
||||
}
|
||||
if len(values) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
customerId, err := parseOptionalUint("customer_id")
|
||||
|
||||
bankIDs, err := parseUintListParam("bank_ids")
|
||||
if err != nil {
|
||||
return err
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid bank_ids")
|
||||
}
|
||||
supplierId, err := parseOptionalUint("supplier_id")
|
||||
customerIDs, err := parseUintListParam("customer_ids")
|
||||
if err != nil {
|
||||
return err
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid customer_ids")
|
||||
}
|
||||
supplierIDs, err := parseUintListParam("supplier_ids")
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid supplier_ids")
|
||||
}
|
||||
transactionTypes, err := parseStringListParam("transaction_types")
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid transaction_types")
|
||||
}
|
||||
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
TransactionType: c.Query("transaction_type", ""),
|
||||
BankId: bankId,
|
||||
CustomerId: customerId,
|
||||
SupplierId: supplierId,
|
||||
SortDate: c.Query("sort_date", ""),
|
||||
StartDate: c.Query("start_date", ""),
|
||||
EndDate: c.Query("end_date", ""),
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
TransactionTypes: transactionTypes,
|
||||
BankIDs: bankIDs,
|
||||
CustomerIDs: customerIDs,
|
||||
SupplierIDs: supplierIDs,
|
||||
SortDate: c.Query("sort_date", ""),
|
||||
StartDate: c.Query("start_date", ""),
|
||||
EndDate: c.Query("end_date", ""),
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
|
||||
Reference in New Issue
Block a user