28 lines
685 B
Go
28 lines
685 B
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
"sqlc_example/internal/services"
|
|
"sqlc_example/models/dto"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func setupFoodRoutes(router *gin.Engine, foodService services.FoodService) {
|
|
router.GET("/food", func(ctx *gin.Context) {
|
|
var newItemFoodDTO dto.NewFoodItemDTO
|
|
|
|
if err := ctx.ShouldBindJSON(newItemFoodDTO); err != nil {
|
|
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"err": err.Error()})
|
|
return
|
|
}
|
|
|
|
guid, serviceErr := foodService.AddFoodItem(newItemFoodDTO); if serviceErr != nil {
|
|
ctx.AbortWithStatusJSON(*&serviceErr.HttpCode, gin.H{"error": serviceErr.Error})
|
|
return
|
|
}
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{"guid": guid})
|
|
})
|
|
}
|