From 1aaf2bd91722dabfd437d539bbcf9f04b88008fb Mon Sep 17 00:00:00 2001 From: Caknoooo Date: Sat, 20 Jan 2024 20:08:42 +0700 Subject: [PATCH] feat: remove unused endpoint --- controller/user.go | 22 ---------------------- routes/user.go | 7 ++----- service/user.go | 36 ------------------------------------ 3 files changed, 2 insertions(+), 63 deletions(-) diff --git a/controller/user.go b/controller/user.go index 3e90985..5ccf938 100644 --- a/controller/user.go +++ b/controller/user.go @@ -16,7 +16,6 @@ type UserController interface { Me(ctx *gin.Context) SendVerificationEmail(ctx *gin.Context) VerifyEmail(ctx *gin.Context) - UpdateStatusIsVerified(ctx *gin.Context) Login(ctx *gin.Context) Update(ctx *gin.Context) Delete(ctx *gin.Context) @@ -78,27 +77,6 @@ func (c *userController) GetAllUser(ctx *gin.Context) { ctx.JSON(http.StatusOK, resp) } -func (c *userController) UpdateStatusIsVerified(ctx *gin.Context) { - adminId := ctx.MustGet("user_id").(string) - - var req dto.UpdateStatusIsVerifiedRequest - if err := ctx.ShouldBind(&req); err != nil { - res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil) - ctx.AbortWithStatusJSON(http.StatusBadRequest, res) - return - } - - result, err := c.userService.UpdateStatusIsVerified(ctx.Request.Context(), req, adminId) - if err != nil { - res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_UPDATE_USER, err.Error(), nil) - ctx.JSON(http.StatusBadRequest, res) - return - } - - res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_UPDATE_USER, result) - ctx.JSON(http.StatusOK, res) -} - func (c *userController) Me(ctx *gin.Context) { userId := ctx.MustGet("user_id").(string) diff --git a/routes/user.go b/routes/user.go index d427ca6..e300495 100644 --- a/routes/user.go +++ b/routes/user.go @@ -14,13 +14,10 @@ func User(route *gin.Engine, userController controller.UserController, jwtServic routes.POST("", userController.Register) routes.GET("", userController.GetAllUser) routes.POST("/login", userController.Login) - routes.DELETE("/", middleware.Authenticate(jwtService), userController.Delete) - routes.PATCH("/", middleware.Authenticate(jwtService), userController.Update) + routes.DELETE("", middleware.Authenticate(jwtService), userController.Delete) + routes.PATCH("", middleware.Authenticate(jwtService), userController.Update) routes.GET("/me", middleware.Authenticate(jwtService), userController.Me) routes.POST("/verify-email", userController.VerifyEmail) routes.POST("/verification-email", userController.SendVerificationEmail) - - // Admin - routes.PATCH("/admin/verify", middleware.Authenticate(jwtService), userController.UpdateStatusIsVerified) } } diff --git a/service/user.go b/service/user.go index ed3a529..aebb6d1 100644 --- a/service/user.go +++ b/service/user.go @@ -23,7 +23,6 @@ type UserService interface { GetAllUserWithPagination(ctx context.Context, req dto.PaginationRequest) (dto.UserPaginationResponse, error) GetUserById(ctx context.Context, userId string) (dto.UserResponse, error) GetUserByEmail(ctx context.Context, email string) (dto.UserResponse, error) - UpdateStatusIsVerified(ctx context.Context, req dto.UpdateStatusIsVerifiedRequest, adminId string) (dto.UserResponse, error) SendVerificationEmail(ctx context.Context, req dto.SendVerificationEmailRequest) error VerifyEmail(ctx context.Context, req dto.VerifyEmailRequest) (dto.VerifyEmailResponse, error) CheckUser(ctx context.Context, email string) (bool, error) @@ -238,41 +237,6 @@ func (s *userService) GetAllUserWithPagination(ctx context.Context, req dto.Pagi }, nil } -func (s *userService) UpdateStatusIsVerified(ctx context.Context, req dto.UpdateStatusIsVerifiedRequest, adminId string) (dto.UserResponse, error) { - admin, err := s.userRepo.GetUserById(ctx, adminId) - if err != nil { - return dto.UserResponse{}, dto.ErrUserNotFound - } - - if admin.Role != constants.ENUM_ROLE_ADMIN { - return dto.UserResponse{}, dto.ErrUserNotAdmin - } - - user, err := s.userRepo.GetUserById(ctx, req.UserId) - if err != nil { - return dto.UserResponse{}, dto.ErrUserNotFound - } - - data := entity.User{ - ID: user.ID, - IsVerified: req.IsVerified, - } - - userUpdate, err := s.userRepo.UpdateUser(ctx, data) - if err != nil { - return dto.UserResponse{}, dto.ErrUpdateUser - } - - return dto.UserResponse{ - ID: user.ID.String(), - Name: user.Name, - TelpNumber: user.TelpNumber, - Role: user.Role, - Email: user.Email, - IsVerified: userUpdate.IsVerified, - }, nil -} - func (s *userService) GetUserById(ctx context.Context, userId string) (dto.UserResponse, error) { user, err := s.userRepo.GetUserById(ctx, userId) if err != nil {