Skip to content

Commit

Permalink
Merge pull request #106 from Capstone-Project-Alterra-Kelompok-8/feat…
Browse files Browse the repository at this point in the history
…ure/categories

update response
  • Loading branch information
Mifthahuddinnn authored Jun 23, 2024
2 parents 79b4c93 + 65c3b05 commit a370fa8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions controllers/category/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ func (cc *CategoryController) GetAll(c echo.Context) error {
return c.JSON(utils.ConvertResponseCode(err), base.NewErrorResponse(err.Error()))
}

return c.JSON(http.StatusOK, base.NewSuccessResponse("Success get all categories", categories))
responseCategories := make([]*response.Get, len(categories))
for i, category := range categories {
responseCategories[i] = response.GetFromEntitiesToResponse(&category)
}

return c.JSON(http.StatusOK, base.NewSuccessResponse("Success get all categories", responseCategories))
}

func (cc *CategoryController) GetByID(c echo.Context) error {
Expand All @@ -42,10 +47,6 @@ func (cc *CategoryController) GetByID(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, base.NewErrorResponse(err.Error()))
}

if err != nil {
return c.JSON(http.StatusBadRequest, base.NewErrorResponse(err.Error()))
}

category, err := cc.useCase.GetByID(id)
if err != nil {
if errors.Is(err, constants.ErrCategoryNotFound) {
Expand All @@ -54,7 +55,9 @@ func (cc *CategoryController) GetByID(c echo.Context) error {
return c.JSON(utils.ConvertResponseCode(err), base.NewErrorResponse(err.Error()))
}

return c.JSON(http.StatusOK, base.NewSuccessResponse("Success get category by ID", category))
responseCategory := response.GetFromEntitiesToResponse(&category)

return c.JSON(http.StatusOK, base.NewSuccessResponse("Success get category by ID", responseCategory))
}

func (cc *CategoryController) CreateCategory(c echo.Context) error {
Expand Down

0 comments on commit a370fa8

Please sign in to comment.