fix tpyo (#8)
All checks were successful
🧪 ✨ Unit Tests Workflow / 🧪 📜 JavaScript Tests (push) Successful in 7m28s
🧪 ✨ Unit Tests Workflow / 🧪 🐹 GolangCI-Lint (push) Successful in 7m40s
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 10m24s

Reviewed-on: Siteworxpro/reloading-manager#8
Co-authored-by: Ron Rise <ron@siteworxpro.com>
Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit was merged in pull request #8.
This commit is contained in:
2025-06-10 15:56:03 +00:00
committed by Siteworx Pro Gitea
parent e484aa7e31
commit dd383b6fb3
15 changed files with 211 additions and 90 deletions

View File

@@ -21,12 +21,15 @@ type BulletResponse struct {
func Photo(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
byId, err := db.Bullets.GetBulletById(context.Background(), *uid)
@@ -48,15 +51,18 @@ func Photo(c echo.Context) error {
func Delete(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
err := db.Bullets.DeleteBullet(context.Background(), *uid)
err = db.Bullets.DeleteBullet(context.Background(), *uid)
if err != nil {
return err
}
@@ -66,12 +72,14 @@ func Delete(c echo.Context) error {
func Put(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
byId, err := db.Bullets.GetBulletById(context.Background(), *uid)
@@ -101,9 +109,9 @@ func Put(c echo.Context) error {
weight, _ := strconv.ParseInt(c.FormValue("weight"), 10, 32)
diameter, _ := strconv.ParseInt(c.FormValue("diameter"), 10, 32)
manufacturerId := c.FormValue("manufacturer_id")
manufacturerUid := handlers.ParseUuidOrBadRequest(c, manufacturerId)
if manufacturerUid == nil {
return nil
manufacturerUid, err := handlers.ParseUuidOrBadRequest(c, manufacturerId)
if err == nil || manufacturerUid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
name := c.FormValue("name")
@@ -147,13 +155,15 @@ func Put(c echo.Context) error {
func Get(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
byId, err := db.Bullets.GetBulletById(context.Background(), *uid)
@@ -210,7 +220,6 @@ func Get(c echo.Context) error {
}
func Post(c echo.Context) error {
file, err := c.FormFile("photo")
if err != nil {
c.Logger().Error(err)
@@ -245,11 +254,13 @@ func Post(c echo.Context) error {
}
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
manufacturerUid := handlers.ParseUuidOrBadRequest(c, manufacturerId)
if manufacturerUid == nil {
return nil
manufacturerUid, err := handlers.ParseUuidOrBadRequest(c, manufacturerId)
if err != nil || manufacturerUid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
manufacturer, err := db.Manufacturer.GetById(context.Background(), *manufacturerUid)

View File

@@ -22,7 +22,9 @@ type postRequest struct {
func Get(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
cartridges, err := db.Loads.GetCartridges(context.Background())
if err != nil {
@@ -45,7 +47,9 @@ func Get(c echo.Context) error {
func Post(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
req := postRequest{}
@@ -79,14 +83,16 @@ func Post(c echo.Context) error {
func Delete(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
uid := handlers.ParseUuidOrBadRequest(c, c.Param("id"))
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, c.Param("id"))
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid id")
}
err := db.Loads.DeleteCartridge(context.Background(), *uid)
err = db.Loads.DeleteCartridge(context.Background(), *uid)
if err != nil {
return err

View File

@@ -66,7 +66,9 @@ type ResultChan[T any] struct {
func Post(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
cartridgeID, err := handlers.ParseUuid(c.FormValue("cartridge_id"))
if err != nil {
@@ -136,7 +138,6 @@ func Post(c echo.Context) error {
}
func Get(c echo.Context) error {
id := c.Param("id")
cResults := make(chan ResultChan[[]loadResponseResults])
@@ -182,7 +183,6 @@ func Get(c echo.Context) error {
} else {
ch <- ResultChan[int64]{Result: total}
}
}(cTotal)
go execResultsQuery(cResults, c)

View File

@@ -21,13 +21,15 @@ type manufacturerResponse struct {
func Get(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
byId, err := db.Manufacturer.GetById(context.Background(), *uid)
@@ -73,15 +75,17 @@ func Get(c echo.Context) error {
func Delete(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
_, err := db.Manufacturer.GetById(context.Background(), *uid)
_, err = db.Manufacturer.GetById(context.Background(), *uid)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound, "Not found")
}
@@ -97,16 +101,18 @@ func Delete(c echo.Context) error {
func Post(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID format")
}
_, err := db.Manufacturer.GetById(context.Background(), *uid)
_, err = db.Manufacturer.GetById(context.Background(), *uid)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound, "Not found")
}

View File

@@ -13,7 +13,9 @@ import (
func Photo(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid, err := handlers.ParseUuid(id)
@@ -41,7 +43,9 @@ func Photo(c echo.Context) error {
func Delete(c echo.Context) error {
id := c.Param("id")
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
uid, err := handlers.ParseUuid(id)
if err != nil {
@@ -58,7 +62,9 @@ func Delete(c echo.Context) error {
func Post(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")
@@ -163,7 +169,9 @@ func Post(c echo.Context) error {
func Get(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")

View File

@@ -3,6 +3,7 @@ package primers
import (
"context"
"encoding/json"
"fmt"
"git.siteworxpro.com/reloading-manager/backend/database"
"git.siteworxpro.com/reloading-manager/backend/handlers"
"git.siteworxpro.com/reloading-manager/backend/models/primers"
@@ -19,7 +20,9 @@ type PrimerResponse struct {
func Delete(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid, err := handlers.ParseUuid(id)
@@ -37,13 +40,15 @@ func Delete(c echo.Context) error {
func Post(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID.")
}
p, err := db.Primer.GetPrimerById(context.Background(), *uid)
@@ -56,9 +61,9 @@ func Post(c echo.Context) error {
}
if c.FormValue("manufacturer_id") != "" {
mid := handlers.ParseUuidOrBadRequest(c, c.FormValue("manufacturer_id"))
if mid == nil {
return nil
mid, err := handlers.ParseUuidOrBadRequest(c, c.FormValue("manufacturer_id"))
if err != nil || mid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Manufacturer ID.")
}
p.ManufacturerID = *mid
@@ -112,13 +117,14 @@ func Post(c echo.Context) error {
if metaString == "" {
metaString = "{}"
}
var meta json.RawMessage = []byte(metaString)
meta := []byte(metaString)
newUuid := uuid.New().String()
uid, _ := handlers.ParseUuid(newUuid)
mid := handlers.ParseUuidOrBadRequest(c, manufacturerId)
if mid == nil {
return nil
mid, err := handlers.ParseUuidOrBadRequest(c, manufacturerId)
if err != nil || mid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Manufacturer ID.")
}
err = db.Primer.InsertPrimer(context.Background(), primers.InsertPrimerParams{
@@ -145,12 +151,14 @@ func Post(c echo.Context) error {
func Photo(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID.")
}
byId, err := db.Primer.GetPrimerById(context.Background(), *uid)
@@ -172,18 +180,20 @@ func Photo(c echo.Context) error {
func Get(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID.")
}
row, err := db.Primer.GetPrimerById(context.Background(), *uid)
if err != nil {
return err
return fmt.Errorf("primer not found: %v", err)
}
return c.JSON(http.StatusOK, handlers.Response[PrimerResponse]{

View File

@@ -11,7 +11,6 @@ type TestContext struct {
}
func (t TestContext) JSON(code int, i interface{}) error {
if code != 400 {
t.t.Fatal("expected 400")
}

View File

@@ -1,6 +1,7 @@
package handlers
import (
"fmt"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/labstack/echo/v4"
@@ -23,7 +24,7 @@ func ParseUuidOrEmpty(s string) *pgtype.UUID {
func ParseUuid(s string) (*pgtype.UUID, error) {
uid, err := uuid.Parse(s)
if err != nil {
return nil, err
return nil, fmt.Errorf("invalid UUID format: %v", err)
}
return &pgtype.UUID{
@@ -32,14 +33,11 @@ func ParseUuid(s string) (*pgtype.UUID, error) {
}, nil
}
func ParseUuidOrBadRequest(c echo.Context, s string) *pgtype.UUID {
func ParseUuidOrBadRequest(c echo.Context, s string) (*pgtype.UUID, error) {
uid, err := ParseUuid(s)
if err != nil {
_ = BadRequest(c, "Invalid UUID.")
return nil
return nil, BadRequest(c, fmt.Sprintf("invalid UUID. %v", err))
}
return uid
return uid, nil
}