Backend: domain structs, FruitRepository interface + pg implementation,
9 Echo v4 handlers (list/get/create/update/delete, image sub-resources),
migration 000002 (fruit_type ENUM, fruits, fruit_synonyms, fruit_images),
route-scoped BodyLimit("5M") for uploads, http.DetectContentType for serving.
Frontend: typed fetch API layer, Pinia setup-style fruitStore, FruitList
(paginated), FruitCreate, and FruitDetail (edit + synonyms editor + image
gallery). 25 backend unit tests + integration test; 18 frontend tests.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/labstack/echo/v4/middleware"
|
|
|
|
"osdb/internal/handler"
|
|
"osdb/internal/repository"
|
|
)
|
|
|
|
// New creates and configures the Echo instance with all routes registered.
|
|
func New(pool *pgxpool.Pool) *echo.Echo {
|
|
e := echo.New()
|
|
e.HideBanner = true
|
|
|
|
e.Use(middleware.Logger())
|
|
e.Use(middleware.Recover())
|
|
|
|
health := handler.NewHealthHandler()
|
|
|
|
// Root health — used by docker healthcheck + ops tooling
|
|
e.GET("/health", health.Health)
|
|
|
|
// Versioned API group
|
|
api := e.Group("/api/v1")
|
|
api.GET("/health", health.Health)
|
|
|
|
// Fruits (story #02)
|
|
fruitRepo := repository.NewFruitRepo(pool)
|
|
fruits := handler.NewFruitHandler(fruitRepo)
|
|
|
|
g := api.Group("/fruits")
|
|
g.GET("", fruits.List)
|
|
g.POST("", fruits.Create)
|
|
g.GET("/:id", fruits.Get)
|
|
g.PUT("/:id", fruits.Update)
|
|
g.DELETE("/:id", fruits.Delete)
|
|
g.GET("/:id/images", fruits.ListImages)
|
|
g.POST("/:id/images", fruits.UploadImage, middleware.BodyLimit("5M"))
|
|
g.GET("/:id/images/:imageId", fruits.ServeImage)
|
|
g.DELETE("/:id/images/:imageId", fruits.DeleteImage)
|
|
|
|
return e
|
|
}
|