Skip to content

Commit

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

Update regency and category response
  • Loading branch information
mhmmdriz authored Jun 25, 2024
2 parents a0fca2e + 2609e25 commit 39880d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 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
8 changes: 7 additions & 1 deletion controllers/regency/regency.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package regency

import (
"e-complaint-api/controllers/base"
"e-complaint-api/controllers/regency/response"
"e-complaint-api/entities"
"net/http"

Expand All @@ -22,5 +23,10 @@ func (rc *RegencyController) GetAll(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, err.Error())
}

return c.JSON(http.StatusOK, base.NewSuccessResponse("Success get all regencies", regencies))
var responseRegencies []*response.Regency
for _, regency := range regencies {
responseRegencies = append(responseRegencies, response.FromEntitiesToResponse(&regency))
}

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

0 comments on commit 39880d4

Please sign in to comment.