Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
238b542aeb | |||
70d446b067 | |||
36322af284 |
2
go.mod
2
go.mod
|
@ -5,6 +5,7 @@ go 1.22.3
|
||||||
require (
|
require (
|
||||||
github.com/dchest/uniuri v1.2.0
|
github.com/dchest/uniuri v1.2.0
|
||||||
github.com/gofiber/fiber/v2 v2.52.5
|
github.com/gofiber/fiber/v2 v2.52.5
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
github.com/h2non/bimg v1.1.9
|
github.com/h2non/bimg v1.1.9
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
gorm.io/driver/sqlite v1.5.6
|
gorm.io/driver/sqlite v1.5.6
|
||||||
|
@ -13,7 +14,6 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
|
|
|
@ -5,13 +5,13 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
DB "log101/konulu-konum-backend/db"
|
DB "log101/konulu-konum-backend/db"
|
||||||
"log101/konulu-konum-backend/models"
|
"log101/konulu-konum-backend/models"
|
||||||
|
|
||||||
"github.com/dchest/uniuri"
|
"github.com/dchest/uniuri"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/h2non/bimg"
|
"github.com/h2non/bimg"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
@ -62,9 +62,9 @@ func KonuluKonumCreate(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save image file in public folder
|
// Save image file in public folder
|
||||||
imageName := strings.Split(file[0].Filename, ".")[0]
|
imageName := uuid.New()
|
||||||
imagePath := fmt.Sprintf("./public/%s.webp", imageName)
|
imagePath := fmt.Sprintf("./public/%s.webp", imageName)
|
||||||
imageURL := fmt.Sprintf("%s.webp", imageName)
|
imageNameWithExtension := fmt.Sprintf("%s.webp", imageName)
|
||||||
err = bimg.Write(imagePath, newImage)
|
err = bimg.Write(imagePath, newImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
@ -80,7 +80,7 @@ func KonuluKonumCreate(c *fiber.Ctx) error {
|
||||||
|
|
||||||
// Write to DB
|
// Write to DB
|
||||||
db := DB.GetDB()
|
db := DB.GetDB()
|
||||||
db.Create(&models.KonuluKonum{URI: imageUri, ImageURL: imageURL, Coordinates: geolocation, AuthorName: author, Description: description, UnlockedCounter: 0, Radius: radiusInt})
|
db.Create(&models.KonuluKonum{URI: imageUri, ImageURL: imageNameWithExtension, Coordinates: geolocation, AuthorName: author, Description: description, UnlockedCounter: 0, Radius: radiusInt})
|
||||||
|
|
||||||
// Return URL
|
// Return URL
|
||||||
redirectURL := fmt.Sprintf("%s/x?id=%s", clientURL, imageUri)
|
redirectURL := fmt.Sprintf("%s/x?id=%s", clientURL, imageUri)
|
||||||
|
@ -112,6 +112,7 @@ func KonuluKonumGet(c *fiber.Ctx) error {
|
||||||
"description": konuluKonum.Description,
|
"description": konuluKonum.Description,
|
||||||
"radius": konuluKonum.Radius,
|
"radius": konuluKonum.Radius,
|
||||||
"unlocked_counter": konuluKonum.UnlockedCounter,
|
"unlocked_counter": konuluKonum.UnlockedCounter,
|
||||||
|
"created_at": konuluKonum.CreatedAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
|
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ func main() {
|
||||||
DB.InitDB()
|
DB.InitDB()
|
||||||
|
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
app.Use(recover.New())
|
||||||
app.Use(logger.New())
|
app.Use(logger.New())
|
||||||
app.Use(cors.New(cors.Config{
|
app.Use(cors.New(cors.Config{
|
||||||
AllowOrigins: "http://localhost:4321",
|
AllowOrigins: "http://localhost:4321",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user