I don't know why. Just move on.

This commit is contained in:
2023-08-07 22:01:06 -04:00
parent 4c9380c548
commit fdc22b8896
2 changed files with 53 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ type gunPayload struct {
}
type gunPost struct {
Id int64 `json:"id"`
Make string `json:"make" validate:"required"`
Model string `json:"model" validate:"required"`
SerialNumber string `json:"serial_number" validate:"required"`
@@ -118,6 +119,57 @@ func DeleteById(c echo.Context) error {
return nil
}
func UpdateGun(c echo.Context) error {
gun := new(gunPost)
err := c.Bind(gun)
if err != nil {
return err
}
getDb := sql.GetDb()
err = getDb.Queries.UpdateGun(context.Background(), db.UpdateGunParams{
Make: sql2.NullString{
String: gun.Make,
Valid: true,
},
Model: sql2.NullString{
String: gun.Model,
Valid: true,
},
SerialNumber: sql2.NullString{
String: gun.SerialNumber,
Valid: true,
},
PurchaseAmount: sql2.NullInt64{
Int64: gun.PurchaseAmount,
Valid: true,
},
ValueAmount: sql2.NullInt64{
Int64: gun.ValueAmount,
Valid: true,
},
DatePurchased: sql2.NullString{
String: gun.DatePurchased,
Valid: true,
},
Notes: sql2.NullString{
String: gun.Notes,
Valid: true,
},
ID: gun.Id,
})
if err != nil {
return err
}
err = c.JSON(http.StatusOK, "")
if err != nil {
return err
}
return nil
}
func GetById(c echo.Context) error {
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {

View File

@@ -36,6 +36,7 @@ func main() {
}))
e.GET("/gun", Guns.Get)
e.PUT("/gun/:id", Guns.UpdateGun)
e.GET("/gun/:id", Guns.GetById)
e.DELETE("/gun/:id", Guns.DeleteById)
e.POST("/gun", Guns.Post)