You've already forked gun-manager-backend
I don't know why. Just move on.
This commit is contained in:
@@ -24,6 +24,7 @@ type gunPayload struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type gunPost struct {
|
type gunPost struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
Make string `json:"make" validate:"required"`
|
Make string `json:"make" validate:"required"`
|
||||||
Model string `json:"model" validate:"required"`
|
Model string `json:"model" validate:"required"`
|
||||||
SerialNumber string `json:"serial_number" validate:"required"`
|
SerialNumber string `json:"serial_number" validate:"required"`
|
||||||
@@ -118,6 +119,57 @@ func DeleteById(c echo.Context) error {
|
|||||||
return nil
|
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 {
|
func GetById(c echo.Context) error {
|
||||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -36,6 +36,7 @@ func main() {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
e.GET("/gun", Guns.Get)
|
e.GET("/gun", Guns.Get)
|
||||||
|
e.PUT("/gun/:id", Guns.UpdateGun)
|
||||||
e.GET("/gun/:id", Guns.GetById)
|
e.GET("/gun/:id", Guns.GetById)
|
||||||
e.DELETE("/gun/:id", Guns.DeleteById)
|
e.DELETE("/gun/:id", Guns.DeleteById)
|
||||||
e.POST("/gun", Guns.Post)
|
e.POST("/gun", Guns.Post)
|
||||||
|
|||||||
Reference in New Issue
Block a user