This commit is contained in:
Aditya Siregar
2025-07-30 23:18:20 +07:00
parent 4a921df55d
commit a759e0f57c
57 changed files with 3633 additions and 190 deletions
+44 -2
View File
@@ -8,6 +8,7 @@ import (
"apskel-pos-be/internal/contract"
"apskel-pos-be/internal/logger"
"apskel-pos-be/internal/transformer"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
@@ -288,8 +289,49 @@ func (h *UserHandler) DeactivateUser(c *gin.Context) {
return
}
logger.FromContext(c).Info("UserHandler::DeactivateUser -> Successfully deactivated user")
c.JSON(http.StatusOK, transformer.CreateSuccessResponse("User deactivated successfully", nil))
logger.FromContext(c).Infof("UserHandler::DeactivateUser -> Successfully deactivated user with ID: %s", userID.String())
c.JSON(http.StatusOK, gin.H{"message": "User deactivated successfully"})
}
func (h *UserHandler) UpdateUserOutlet(c *gin.Context) {
userIDStr := c.Param("id")
userID, err := uuid.Parse(userIDStr)
if err != nil {
logger.FromContext(c).WithError(err).Error("UserHandler::UpdateUserOutlet -> Invalid user ID")
h.sendValidationErrorResponse(c, "Invalid user ID", constants.MalformedFieldErrorCode)
return
}
validationError, validationErrorCode := h.userValidator.ValidateUserID(userID)
if validationError != nil {
logger.FromContext(c).WithError(validationError).Error("UserHandler::UpdateUserOutlet -> user ID validation failed")
h.sendValidationErrorResponse(c, validationError.Error(), validationErrorCode)
return
}
var req contract.UpdateUserOutletRequest
if err := c.ShouldBindJSON(&req); err != nil {
logger.FromContext(c).WithError(err).Error("UserHandler::UpdateUserOutlet -> request binding failed")
h.sendValidationErrorResponse(c, "Invalid request body", constants.MissingFieldErrorCode)
return
}
validationError, validationErrorCode = h.userValidator.ValidateUpdateUserOutletRequest(&req)
if validationError != nil {
logger.FromContext(c).WithError(validationError).Error("UserHandler::UpdateUserOutlet -> request validation failed")
h.sendValidationErrorResponse(c, validationError.Error(), validationErrorCode)
return
}
userResponse, err := h.userService.UpdateUserOutlet(c.Request.Context(), userID, &req)
if err != nil {
logger.FromContext(c).WithError(err).Error("UserHandler::UpdateUserOutlet -> Failed to update user outlet from service")
h.sendErrorResponse(c, err.Error(), http.StatusInternalServerError)
return
}
logger.FromContext(c).Infof("UserHandler::UpdateUserOutlet -> Successfully updated user outlet = %+v", userResponse)
c.JSON(http.StatusOK, userResponse)
}
func (h *UserHandler) sendErrorResponse(c *gin.Context, message string, statusCode int) {