Initial commit
This commit is contained in:
27
backend/internal/routes/food.go
Normal file
27
backend/internal/routes/food.go
Normal file
@@ -0,0 +1,27 @@
|
||||
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})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user