diff --git a/backend/handlers/loads/handler.go b/backend/handlers/loads/handler.go index 9b8315e..c8895c1 100644 --- a/backend/handlers/loads/handler.go +++ b/backend/handlers/loads/handler.go @@ -13,6 +13,7 @@ import ( "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" "net/http" + "strings" ) type row struct { @@ -325,7 +326,58 @@ func getQuery(c echo.Context, countOnly bool) postgres.SelectStatement { ) } + // where expressions expressions := make([]postgres.BoolExpression, 0) + + if c.QueryParam("cartridge_id") != "" { + ids := strings.Split(c.QueryParam("cartridge_id"), ",") + if len(ids) > 0 { + expressions = append(expressions, ctg.ID.IN(getUuidExpr(ids)...)) + } + } + + if c.QueryParam("bullet_manufacturer_id") != "" { + ids := strings.Split(c.QueryParam("bullet_manufacturer_id"), ",") + if len(ids) > 0 { + expressions = append(expressions, ctg.ID.IN(getUuidExpr(ids)...)) + } + } + + if c.QueryParam("bullet_id") != "" { + ids := strings.Split(c.QueryParam("bullet_id"), ",") + if len(ids) > 0 { + expressions = append(expressions, b.ID.IN(getUuidExpr(ids)...)) + } + } + + if c.QueryParam("primer_manufacturer_id") != "" { + ids := strings.Split(c.QueryParam("primer_manufacturer_id"), ",") + if len(ids) > 0 { + expressions = append(expressions, pm.ID.IN(getUuidExpr(ids)...)) + } + } + + if c.QueryParam("primer_id") != "" { + ids := strings.Split(c.QueryParam("primer_id"), ",") + if len(ids) > 0 { + expressions = append(expressions, p.ID.IN(getUuidExpr(ids)...)) + } + } + + if c.QueryParam("powder_manufacturer_id") != "" { + ids := strings.Split(c.QueryParam("powder_manufacturer_id"), ",") + if len(ids) > 0 { + expressions = append(expressions, pwdm.ID.IN(getUuidExpr(ids)...)) + } + } + + if c.QueryParam("powder_id") != "" { + ids := strings.Split(c.QueryParam("powder_id"), ",") + if len(ids) > 0 { + expressions = append(expressions, pwd.ID.IN(getUuidExpr(ids)...)) + } + } + if c.QueryParam("search_cartridge") != "" { expressions = append(expressions, ctg.Name.LIKE(postgres.String(c.QueryParam("search_cartridge")+"%"))) } @@ -396,3 +448,17 @@ func getQuery(c echo.Context, countOnly bool) postgres.SelectStatement { return q } + +func getUuidExpr(ids []string) []postgres.Expression { + expr := make([]postgres.Expression, 0) + for _, id := range ids { + uuid, err := handlers.ParseUuid(id) + if err != nil { + continue + } + + expr = append(expr, postgres.UUID(uuid)) + } + + return expr +} diff --git a/frontend/src/pages/loads/Search.vue b/frontend/src/pages/loads/Search.vue index 00fa07a..e1ca2af 100644 --- a/frontend/src/pages/loads/Search.vue +++ b/frontend/src/pages/loads/Search.vue @@ -8,6 +8,7 @@ :value="loads" filterDisplay="row" paginator + size="small" :sortField="sortField" :sortOrder="sortOrder" @update:sortField="(e: string) => {sortField = e; fetchLoads()}" @@ -25,7 +26,8 @@