Skip to content

Commit

Permalink
Added swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-iaco committed Feb 22, 2023
1 parent b51fd72 commit 80576b7
Show file tree
Hide file tree
Showing 8 changed files with 1,784 additions and 20 deletions.
40 changes: 39 additions & 1 deletion controller/FoodConsumptionController.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func NewFoodConsumptionController(foodConsumptionService *service.FoodConsumptio
return &FoodConsumptionController{foodConsumptionService: foodConsumptionService, firebaseApp: fa}
}

// FindAllConsumptionForMeal godoc
// @Summary Get all consumption for the meal
// @Description find all the consumption for the meal by mealId
// @Tags food-consumption
// @Produce json
// @Param mealId path string true "Meal ID"
// @Success 200 {object} dto.BaseResponse[[]dto.FoodConsumptionDto]
// @Router /{mealId}/consumption/ [get]
func (s *FoodConsumptionController) FindAllConsumptionForMeal(c *gin.Context) {
_, err := s.validateTokenAndGetUserId(c.GetHeader("Authorization"))
if err != nil {
Expand All @@ -41,6 +49,16 @@ func (s *FoodConsumptionController) FindAllConsumptionForMeal(c *gin.Context) {
})
}

// AddFoodConsumption godoc
// @Summary Add consumption for the meal
// @Description add consumption for the meal by mealId
// @Tags food-consumption
// @Accept json
// @Produce json
// @Param mealId path string true "Meal ID"
// @Param foodConsumptionDto body dto.FoodConsumptionDto true "Food Consumption"
// @Success 200 {object} dto.BaseResponse[dto.FoodConsumptionDto]
// @Router /{mealId}/consumption/ [post]
func (s *FoodConsumptionController) AddFoodConsumption(c *gin.Context) {
mealId, err := uuid.Parse(c.Param("mealId"))
if err != nil {
Expand Down Expand Up @@ -69,6 +87,16 @@ func (s *FoodConsumptionController) AddFoodConsumption(c *gin.Context) {
})
}

// UpdateFoodConsumption godoc
// @Summary Update consumption for the meal
// @Description update consumption for the meal by mealId
// @Tags food-consumption
// @Accept json
// @Produce json
// @Param mealId path string true "Meal ID"
// @Param foodConsumptionDto body dto.FoodConsumptionDto true "Food Consumption"
// @Success 200 {object} dto.BaseResponse[dto.FoodConsumptionDto]
// @Router /{mealId}/consumption/ [patch]
func (s *FoodConsumptionController) UpdateFoodConsumption(c *gin.Context) {
mealId, err := uuid.Parse(c.Param("mealId"))
if err != nil {
Expand All @@ -93,6 +121,16 @@ func (s *FoodConsumptionController) UpdateFoodConsumption(c *gin.Context) {
})
}

// DeleteFoodConsumption godoc
// @Summary Delete consumption for the meal
// @Description delete consumption for the meal by mealId
// @Tags food-consumption
// @Accept json
// @Produce json
// @Param mealId path string true "Meal ID"
// @Param foodConsumptionId path string true "Food consumption ID"
// @Success 200 {object} dto.BaseResponse[bool]
// @Router /{mealId}/consumption/ [delete]
func (s *FoodConsumptionController) DeleteFoodConsumption(c *gin.Context) {
mealId, err := uuid.Parse(c.Param("mealId"))
foodConsumptionId, err := uuid.Parse(c.Param("foodConsumptionId"))
Expand All @@ -111,7 +149,7 @@ func (s *FoodConsumptionController) DeleteFoodConsumption(c *gin.Context) {
s.abortWithMessage(c, err.Error())
return
}
c.JSON(200, dto.BaseResponse[any]{
c.JSON(200, dto.BaseResponse[bool]{
Body: err != nil,
})
}
Expand Down
54 changes: 54 additions & 0 deletions controller/MealController.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ func NewMealController(mealService *service.MealService, fa *firebase.App) *Meal
return &MealController{mealService: mealService, firebaseApp: fa}
}

// FindAllMeals godoc
// @Summary Get all meals
// @Description get all the meals which satisfies the query parameters (startRange, endRange) or all meals if no query parameters are provided
// @Tags meal
// @Produce json
// @Param startRange query string false "Start date of the range"
// @Param endRange query string false "End date of the range"
// @Success 200 {object} dto.BaseResponse[[]dto.MealDto]
// @Router / [get]
func (s *MealController) FindAllMeals(c *gin.Context) {
var mealDtos = make([]dto.MealDto, 0)
startRangeParam := c.Query("startRange")
Expand Down Expand Up @@ -60,6 +69,14 @@ func (s *MealController) FindAllMeals(c *gin.Context) {
c.JSON(200, response)
}

// FindMealById godoc
// @Summary Get meal
// @Description get the meal with the provided id
// @Tags meal
// @Produce json
// @Param mealId path string true "Meal ID"
// @Success 200 {object} dto.BaseResponse[dto.MealDto]
// @Router /{mealId}/ [get]
func (s *MealController) FindMealById(c *gin.Context) {
id, _ := uuid.Parse(c.Param("mealId"))
userId, err := s.validateTokenAndGetUserId(c.GetHeader("Authorization"))
Expand All @@ -78,6 +95,15 @@ func (s *MealController) FindMealById(c *gin.Context) {
c.JSON(200, response)
}

// CreateMeal godoc
// @Summary Create meal
// @Description create a new meal
// @Tags meal
// @Accept json
// @Produce json
// @Param mealDto body dto.MealDto true "Meal to create"
// @Success 200 {object} dto.BaseResponse[dto.MealDto]
// @Router / [post]
func (s *MealController) CreateMeal(c *gin.Context) {
var mealDto dto.MealDto
err := c.BindJSON(&mealDto)
Expand All @@ -102,6 +128,16 @@ func (s *MealController) CreateMeal(c *gin.Context) {
c.JSON(200, response)
}

// UpdateMeal godoc
// @Summary Update meal
// @Description update the meal with the provided id
// @Tags meal
// @Accept json
// @Produce json
// @Param mealId path string true "Meal ID"
// @Param mealDto body dto.MealDto true "Meal to create"
// @Success 200 {object} dto.BaseResponse[dto.MealDto]
// @Router /{mealId}/ [patch]
func (s *MealController) UpdateMeal(c *gin.Context) {
var mealDto dto.MealDto
id, _ := uuid.Parse(c.Param("mealId"))
Expand All @@ -123,6 +159,15 @@ func (s *MealController) UpdateMeal(c *gin.Context) {
c.JSON(200, response)
}

// DeleteMeal godoc
// @Summary Delete meal
// @Description delete the meal with the provided id
// @Tags meal
// @Accept json
// @Produce json
// @Param mealId path string true "Meal ID"
// @Success 200 {object} dto.BaseResponse[bool]
// @Router /{mealId}/ [delete]
func (s *MealController) DeleteMeal(c *gin.Context) {
id, _ := uuid.Parse(c.Param("mealId"))
userId, err := s.validateTokenAndGetUserId(c.GetHeader("Authorization"))
Expand All @@ -141,6 +186,15 @@ func (s *MealController) DeleteMeal(c *gin.Context) {
c.JSON(200, response)
}

// GetMealStatistics godoc
// @Summary Get meal statistics
// @Description get the meal statistics for the provided date range (default is the past week)
// @Tags meal
// @Produce json
// @Param startRange query string false "Start date of the range"
// @Param endRange query string false "End date of the range"
// @Success 200 {object} dto.BaseResponse[dto.MealStatisticsDto]
// @Router /statistics/ [get]
func (s *MealController) GetMealStatistics(c *gin.Context) {
var mealStatisticsDto dto.MealStatisticsDto
startRangeParam := c.Query("startRange")
Expand Down
Loading

0 comments on commit 80576b7

Please sign in to comment.