changed things... (#29)

Reviewed-on: rrise/reloading-manager#29
Co-authored-by: Ron Rise <ron@siteworxpro.com>
Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit is contained in:
2025-04-18 19:31:31 -04:00
committed by Siteworx Pro Gitea
parent a9b82332e1
commit d0fbac51aa
3 changed files with 196 additions and 10 deletions

View File

@@ -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
}