You've already forked gun-manager-backend
Never gonna let you down
This commit is contained in:
@@ -73,9 +73,13 @@ func Post(c echo.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.JSON(http.StatusAccepted, Handlers.Response[struct{ Id int64 }]{
|
||||
Status: http.StatusText(http.StatusOK),
|
||||
Payload: struct{ Id int64 }{Id: id},
|
||||
err = c.JSON(http.StatusAccepted, Handlers.Response[struct {
|
||||
Id int64 `json:"id"`
|
||||
}]{
|
||||
Status: http.StatusText(http.StatusOK),
|
||||
Payload: struct {
|
||||
Id int64 `json:"id"`
|
||||
}{Id: id},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -129,6 +133,78 @@ func GetPhotoResize(c echo.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeletePhoto(c echo.Context) error {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
getDb := sql.GetDb()
|
||||
err = getDb.Queries.DeleteGunPhotosById(context.Background(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.JSON(http.StatusNoContent, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func PostPhoto(c echo.Context) error {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
err := c.JSON(http.StatusNotFound, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
files, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
getDb := sql.GetDb()
|
||||
byId, err := getDb.Queries.GetGunById(context.Background(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, handler := range files.File {
|
||||
for _, file := range handler {
|
||||
open, err := file.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileData := make([]byte, file.Size)
|
||||
_, err = open.Read(fileData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = getDb.Queries.InsertGunPhoto(context.Background(), db.InsertGunPhotoParams{
|
||||
GunID: sql2.NullInt64{
|
||||
Int64: byId.ID,
|
||||
Valid: true,
|
||||
},
|
||||
Filename: sql2.NullString{
|
||||
String: file.Filename,
|
||||
Valid: true,
|
||||
},
|
||||
Photo: fileData,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetPhoto(c echo.Context) error {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
@@ -153,13 +229,35 @@ func GetPhoto(c echo.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteById(c echo.Context) error {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
getDb := sql.GetDb()
|
||||
err = getDb.Queries.DeleteGunPhotosByGunId(context.Background(), sql2.NullInt64{
|
||||
Int64: id,
|
||||
Valid: true,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = getDb.Queries.DeleteGun(context.Background(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.JSON(http.StatusNoContent, "")
|
||||
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 {
|
||||
err := c.JSON(http.StatusNotFound, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -183,6 +281,10 @@ func GetById(c echo.Context) error {
|
||||
getDb := sql.GetDb()
|
||||
byId, err := getDb.Queries.GetGunById(context.Background(), id)
|
||||
if err != nil {
|
||||
err := c.JSON(http.StatusNotFound, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user