Copy-paste to fix previous copy-paste

This commit is contained in:
2023-08-07 18:49:25 -04:00
parent 5dd3fa9451
commit ca56ca7b29
4 changed files with 52 additions and 0 deletions

View File

@@ -1,12 +1,15 @@
package Guns
import (
"bytes"
"context"
sql2 "database/sql"
"git.siteworxpro.com/gun-manager/Handlers"
"git.siteworxpro.com/gun-manager/sql"
"git.siteworxpro.com/gun-manager/sql/db"
"github.com/labstack/echo/v4"
"github.com/nfnt/resize"
"image/jpeg"
"net/http"
"strconv"
)
@@ -81,6 +84,51 @@ func Post(c echo.Context) error {
return nil
}
func GetPhotoResize(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
}
size, err := strconv.ParseInt(c.Param("size"), 10, 64)
if err != nil {
err := c.JSON(http.StatusNotFound, "")
if err != nil {
return err
}
return nil
}
getDb := sql.GetDb()
photo, err := getDb.Queries.GetGunPhotoData(context.Background(), id)
if err != nil {
return err
}
img, err := jpeg.Decode(bytes.NewBuffer(photo))
if err != nil {
return err
}
m := resize.Resize(uint(size), 0, img, resize.Bicubic)
image := bytes.NewBuffer(make([]byte, 0))
err = jpeg.Encode(image, m, nil)
if err != nil {
return err
}
err = c.String(http.StatusOK, image.String())
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 {