Skip to content

Commit

Permalink
Revert "Merge pull request #23 from RECYTHNG/develop"
Browse files Browse the repository at this point in the history
This reverts commit df4c223, reversing
changes made to 7ca5d5b.
  • Loading branch information
Mark committed Jun 25, 2024
1 parent df4c223 commit 4c2d3f4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 42 deletions.
12 changes: 6 additions & 6 deletions internal/admin/handler/admin_handler_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (handler *adminHandlerImpl) AddAdminHandler(c echo.Context) error {

src, errOpen := file.Open()
if errOpen != nil {
return helper.ErrorHandler(c, http.StatusInternalServerError, "failed to open file")
return helper.ErrorHandler(c, http.StatusInternalServerError, "failed to open file: "+errOpen.Error())
}
defer src.Close()

Expand All @@ -64,7 +64,7 @@ func (handler *adminHandlerImpl) AddAdminHandler(c echo.Context) error {
if errors.Is(errUc, pkg.ErrUploadCloudinary) {
return helper.ErrorHandler(c, http.StatusInternalServerError, pkg.ErrUploadCloudinary.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+errUc.Error())
}

data := dto.AdminResponseRegister{
Expand Down Expand Up @@ -190,7 +190,7 @@ func (handler *adminHandlerImpl) UpdateAdminHandler(c echo.Context) error {
}
src, errOpen := reqFile.Open()
if errOpen != nil {
return helper.ErrorHandler(c, http.StatusInternalServerError, "failed to open file")
return helper.ErrorHandler(c, http.StatusInternalServerError, "failed to open file: "+errOpen.Error())
}
defer src.Close()

Expand All @@ -215,7 +215,7 @@ func (handler *adminHandlerImpl) UpdateAdminHandler(c echo.Context) error {
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrRole.Error())
}

return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+errUc.Error())
}

data := dto.AdminResponseUpdate{
Expand All @@ -236,7 +236,7 @@ func (handler *adminHandlerImpl) GetProfileAdminHandler(c echo.Context) error {
if errors.Is(err, pkg.ErrAdminNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, err.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}

data := dto.AdminResponseGetDataById{
Expand All @@ -259,7 +259,7 @@ func (handler *adminHandlerImpl) DeleteAdminHandler(c echo.Context) error {
if errors.Is(err, pkg.ErrAdminNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, err.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}
responseData := helper.ResponseData(http.StatusOK, "data successfully deleted", nil)
return c.JSON(http.StatusOK, responseData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (handler *ApprovalTaskHandlerImpl) GetAllApprovalTaskPaginationHandler(c ec

userTask, total, err := handler.usecase.GetAllApprovalTaskPaginationUseCase(limitInt, pageInt)
if err != nil {
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}

var data []dto.DataUserTask
Expand Down Expand Up @@ -91,7 +91,7 @@ func (handler *ApprovalTaskHandlerImpl) ApproveUserTaskHandler(c echo.Context) e
if errors.Is(err, pkg.ErrUserTaskNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrUserTaskNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}

responseData := helper.ResponseData(http.StatusOK, "success approve user task", nil)
Expand All @@ -106,7 +106,7 @@ func (handler *ApprovalTaskHandlerImpl) RejectUserTaskHandler(c echo.Context) er
return helper.ErrorHandler(c, http.StatusBadRequest, err.Error())
}
if err := c.Validate(&request); err != nil {
return helper.ErrorHandler(c, http.StatusBadRequest, "invalid request body")
return helper.ErrorHandler(c, http.StatusBadRequest, "invalid request body, detail : "+err.Error())
}
if err := handler.usecase.RejectUserTaskUseCase(&request, userTaskId); err != nil {
if errors.Is(err, pkg.ErrUserTaskAlreadyReject) {
Expand All @@ -115,7 +115,10 @@ func (handler *ApprovalTaskHandlerImpl) RejectUserTaskHandler(c echo.Context) er
if errors.Is(err, pkg.ErrUserTaskNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrUserTaskNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
if errors.Is(err, pkg.ErrUserTaskAlreadyAccepted) {
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrUserTaskAlreadyAccepted.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}

responseData := helper.ResponseData(http.StatusOK, "success reject user task", nil)
Expand All @@ -130,7 +133,7 @@ func (handler *ApprovalTaskHandlerImpl) GetUserTaskDetailsHandler(c echo.Context
if errors.Is(err, pkg.ErrUserTaskNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrUserTaskNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}

var dataImages []*dto.DataImages
Expand Down
10 changes: 5 additions & 5 deletions internal/task/manage_task/handler/manage_task_handler_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (handler *ManageTaskHandlerImpl) CreateTaskHandler(c echo.Context) error {
if errors.Is(err, pkg.ErrUploadCloudinary) {
return helper.ErrorHandler(c, http.StatusInternalServerError, pkg.ErrUploadCloudinary.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}

taskStep := []dto.TaskSteps{}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (handler *ManageTaskHandlerImpl) GetTaskChallengePaginationHandler(c echo.C

tasks, totalData, err := handler.Usecase.GetTaskChallengePagination(pageInt, limitInt, status, endDate)
if err != nil {
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var data []dto.DataTasks
Expand Down Expand Up @@ -181,7 +181,7 @@ func (handler *ManageTaskHandlerImpl) GetTaskByIdHandler(c echo.Context) error {
if errors.Is(err, pkg.ErrTaskNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrTaskNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var taskSteps []dto.TaskSteps
Expand Down Expand Up @@ -255,7 +255,7 @@ func (handler *ManageTaskHandlerImpl) UpdateTaskHandler(c echo.Context) error {
if errors.Is(err, pkg.ErrUploadCloudinary) {
return helper.ErrorHandler(c, http.StatusInternalServerError, pkg.ErrUploadCloudinary.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}
var taskSteps []dto.TaskSteps
for _, step := range task.TaskSteps {
Expand Down Expand Up @@ -286,7 +286,7 @@ func (handler *ManageTaskHandlerImpl) DeleteTaskHandler(c echo.Context) error {
if errors.Is(err, pkg.ErrTaskNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrTaskNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}
responseData := helper.ResponseData(http.StatusOK, "data deleted successfully", nil)
return c.JSON(http.StatusOK, responseData)
Expand Down
22 changes: 11 additions & 11 deletions internal/task/user_task/handler/user_task_handler_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewUserTaskHandler(usecase usecase.UserTaskUsecase) UserTaskHandler {
func (handler *UserTaskHandlerImpl) GetAllTasksHandler(c echo.Context) error {
userTask, err := handler.Usecase.GetAllTasksUsecase()
if err != nil {
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var data []dto.DataUserTask
Expand Down Expand Up @@ -61,7 +61,7 @@ func (handler *UserTaskHandlerImpl) GetTaskByIdHandler(c echo.Context) error {
if errors.Is(err, pkg.ErrTaskNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrTaskNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}
var taskStep []dto.TaskSteps
for _, step := range task.TaskSteps {
Expand Down Expand Up @@ -100,7 +100,7 @@ func (handler *UserTaskHandlerImpl) CreateUserTaskHandler(c echo.Context) error
if errors.Is(err, pkg.ErrTaskCannotBeFollowed) {
return helper.ErrorHandler(c, http.StatusConflict, pkg.ErrTaskCannotBeFollowed.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var taskStep []dto.TaskSteps
Expand Down Expand Up @@ -192,7 +192,7 @@ func (handler *UserTaskHandlerImpl) UploadImageTaskHandler(c echo.Context) error
if errors.Is(err, pkg.ErrUserTaskNotCompleted) {
return helper.ErrorHandler(c, http.StatusConflict, pkg.ErrUserTaskNotCompleted.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}
var taskStep []dto.TaskSteps
var urlImages []dto.Images
Expand Down Expand Up @@ -252,7 +252,7 @@ func (handler *UserTaskHandlerImpl) GetUserTaskByUserIdHandler(c echo.Context) e
if errors.Is(err, pkg.ErrUserNoHasTask) {
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrUserNoHasTask.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var data []dto.UserTaskGetByIdUserResponse
Expand Down Expand Up @@ -303,7 +303,7 @@ func (handler *UserTaskHandlerImpl) GetUserTaskDoneByUserIdHandler(c echo.Contex
if errors.Is(err, pkg.ErrUserNoHasTask) {
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrUserNoHasTask.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var data []dto.GetUserTaskDoneByIdUserResponse
Expand Down Expand Up @@ -398,7 +398,7 @@ func (handler *UserTaskHandlerImpl) UpdateUserTaskHandler(c echo.Context) error
if errors.Is(err, pkg.ErrUserTaskNotReject) {
return helper.ErrorHandler(c, http.StatusConflict, pkg.ErrUserTaskNotReject.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}
var taskStep []dto.TaskSteps
var urlImages []dto.Images
Expand Down Expand Up @@ -461,7 +461,7 @@ func (handler *UserTaskHandlerImpl) GetUserTaskDetailsHandler(c echo.Context) er
if errors.Is(err, pkg.ErrUserTaskNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrUserTaskNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var dataImages []*dto.DataImages
Expand Down Expand Up @@ -491,7 +491,7 @@ func (handler *UserTaskHandlerImpl) GetHistoryPointByUserIdHandler(c echo.Contex
if errors.Is(err, pkg.ErrUserNoHasTask) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrUserNoHasTask.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var dataHistoryPoints []*dto.DataHistoryPoint
Expand Down Expand Up @@ -540,7 +540,7 @@ func (handler *UserTaskHandlerImpl) UpdateTaskStepHandler(c echo.Context) error
if errors.Is(err, pkg.ErrUserTaskStepAlreadyCompleted) {
return helper.ErrorHandler(c, http.StatusConflict, pkg.ErrUserTaskStepAlreadyCompleted.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}

var taskStep []dto.TaskSteps
Expand Down Expand Up @@ -591,7 +591,7 @@ func (handler *UserTaskHandlerImpl) GetUserTaskByUserTaskIdHandler(c echo.Contex
if errors.Is(err, pkg.ErrUserTaskNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrUserTaskNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail: "+err.Error())
}
var taskStep []dto.TaskSteps
var userSteps []dto.DataUserSteps
Expand Down
24 changes: 14 additions & 10 deletions internal/video/manage_video/handler/manage_video_handler_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (handler *ManageVideoHandlerImpl) CreateDataVideoHandler(c echo.Context) er
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrNoVideoIdFoundOnUrl.Error())
}
if errors.Is(err, pkg.ErrVideoNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrVideoNotFound.Error())
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrVideoNotFound.Error())
}
if errors.Is(err, pkg.ErrVideoService) {
return helper.ErrorHandler(c, http.StatusInternalServerError, pkg.ErrVideoService.Error())
Expand All @@ -84,15 +84,15 @@ func (handler *ManageVideoHandlerImpl) CreateDataVideoHandler(c echo.Context) er
if errors.Is(err, pkg.ErrUploadCloudinary) {
return helper.ErrorHandler(c, http.StatusInternalServerError, pkg.ErrUploadCloudinary.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}
return helper.ResponseHandler(c, http.StatusCreated, "success create data video", nil)
}

func (handler *ManageVideoHandlerImpl) GetAllCategoryVideoHandler(c echo.Context) error {
videoCategories, trashCategories, err := handler.ManageVideoUsecase.GetAllCategoryVideoUseCase()
if err != nil {
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}
var dataVideoCategories []*dto.DataCategoryVideo
var dataTrashCategories []*dto.DataTrashCategory
Expand Down Expand Up @@ -175,9 +175,9 @@ func (handler *ManageVideoHandlerImpl) GetDetailsDataVideoByIdHandler(c echo.Con
video, err := handler.ManageVideoUsecase.GetDetailsDataVideoByIdUseCase(idInt)
if err != nil {
if errors.Is(err, pkg.ErrVideoNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrVideoNotFound.Error())
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrVideoNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}
uniqueContentCategories := make(map[uint]*dto.DataCategoryVideoResponse)
uniqueWasteCategories := make(map[uint]*dto.DataTrashCategoryResponse)
Expand All @@ -201,6 +201,7 @@ func (handler *ManageVideoHandlerImpl) GetDetailsDataVideoByIdHandler(c echo.Con
}
}

// Convert maps back to slices
var dataContentCategories []*dto.DataCategoryVideoResponse
for _, vc := range uniqueContentCategories {
dataContentCategories = append(dataContentCategories, vc)
Expand Down Expand Up @@ -249,11 +250,14 @@ func (handler *ManageVideoHandlerImpl) UpdateDataVideoHandler(c echo.Context) er
}

if err := handler.ManageVideoUsecase.UpdateDataVideoUseCase(&request, thumbnail, idInt); err != nil {
if errors.Is(err, pkg.ErrVideoNotFound) {
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrVideoNotFound.Error())
}
if errors.Is(err, pkg.ErrNameCategoryVideoNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrNameCategoryVideoNotFound.Error())
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrNameCategoryVideoNotFound.Error())
}
if errors.Is(err, pkg.ErrNameTrashCategoryNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrNameTrashCategoryNotFound.Error())
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrNameTrashCategoryNotFound.Error())
}
if errors.Is(err, pkg.ErrNoVideoIdFoundOnUrl) {
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrNoVideoIdFoundOnUrl.Error())
Expand Down Expand Up @@ -285,7 +289,7 @@ func (handler *ManageVideoHandlerImpl) UpdateDataVideoHandler(c echo.Context) er
if errors.Is(err, pkg.ErrUploadCloudinary) {
return helper.ErrorHandler(c, http.StatusInternalServerError, pkg.ErrUploadCloudinary.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}
return helper.ResponseHandler(c, http.StatusOK, "success update data video", nil)
}
Expand All @@ -298,9 +302,9 @@ func (handler *ManageVideoHandlerImpl) DeleteDataVideoHandler(c echo.Context) er
}
if err := handler.ManageVideoUsecase.DeleteDataVideoUseCase(idInt); err != nil {
if errors.Is(err, pkg.ErrVideoNotFound) {
return helper.ErrorHandler(c, http.StatusNotFound, pkg.ErrVideoNotFound.Error())
return helper.ErrorHandler(c, http.StatusBadRequest, pkg.ErrVideoNotFound.Error())
}
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error")
return helper.ErrorHandler(c, http.StatusInternalServerError, "internal server error, detail : "+err.Error())
}
return helper.ResponseHandler(c, http.StatusOK, "success delete data video", nil)
}
Loading

0 comments on commit 4c2d3f4

Please sign in to comment.