From 70f300fe83fc72c306f145361acdd15dce8db088 Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Mon, 6 Nov 2023 17:54:40 +0900 Subject: [PATCH] =?UTF-8?q?feat(BE):=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=9D=B8=EC=A6=9D=20=EC=88=98?= =?UTF-8?q?=EB=9D=BD/=EA=B1=B0=EC=A0=88=20BUS-195-profile-image-process=20?= =?UTF-8?q?#171?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/adapter/in/rest/UserController.java | 19 +++++++++++++++++++ .../out/persistence/UserMapperInterface.java | 1 + .../port/in/ProfileImageUsecase.java | 3 +++ .../example/api/user/service/UserService.java | 13 +++++++++++++ 4 files changed, 36 insertions(+) diff --git a/src/main/java/com/example/api/user/adapter/in/rest/UserController.java b/src/main/java/com/example/api/user/adapter/in/rest/UserController.java index 94e6bf5..4f3c35e 100644 --- a/src/main/java/com/example/api/user/adapter/in/rest/UserController.java +++ b/src/main/java/com/example/api/user/adapter/in/rest/UserController.java @@ -210,6 +210,25 @@ public FindUserDto updateUser(@RequestBody UpdateUserDto userDto) { } return saveUserUsecase.updateUser(securityUser.getUserId(), userDto); } + + @Operation(summary = "Update profile image state", description = "프로필 사진 승인 상태를 수정한다.") + @PutMapping("/user/image/state") + public void updateProfileImageState(UUID userId, ApplicationStateEnum state) { + SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); + if (securityUser == null) { + log.error("UserController::updateProfileImageState: Login is needed"); + throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); + } + if (!(findUserUsecase.getUser(securityUser.getUserId()).getRole().equals(UserRoleEnum.Admin))) { + log.error("UserController::updateProfileImageState: Admin authority is needed"); + throw new CustomException(ErrorCodeEnum.INVALID_PERMISSION); + } + if (findUserUsecase.getUser(userId) == null) { + log.error("UserController:updateProfileImageState: No such user"); + throw new CustomException(ErrorCodeEnum.USER_NOT_FOUND); + } + profileImageUsecase.updateProfileImageState(userId, state); + } /** * 전체 사용자 삭제 (비상시 외 사용 금지) diff --git a/src/main/java/com/example/api/user/adapter/out/persistence/UserMapperInterface.java b/src/main/java/com/example/api/user/adapter/out/persistence/UserMapperInterface.java index 16304b6..35d8082 100644 --- a/src/main/java/com/example/api/user/adapter/out/persistence/UserMapperInterface.java +++ b/src/main/java/com/example/api/user/adapter/out/persistence/UserMapperInterface.java @@ -26,4 +26,5 @@ public interface UserMapperInterface { UserAuthorityCheckDto toAuthorityDto(UserEntity userEntity); FindUserDto toDto(UpdateUserDto updateUserDto); ProfileImageEntity toEntity(ProfileImage profileImage); + ProfileImage toDomain(ProfileImageEntity profileImageEntity); } \ No newline at end of file diff --git a/src/main/java/com/example/api/user/application/port/in/ProfileImageUsecase.java b/src/main/java/com/example/api/user/application/port/in/ProfileImageUsecase.java index b81e09e..57a964f 100644 --- a/src/main/java/com/example/api/user/application/port/in/ProfileImageUsecase.java +++ b/src/main/java/com/example/api/user/application/port/in/ProfileImageUsecase.java @@ -1,9 +1,12 @@ package com.example.api.user.application.port.in; +import com.example.api.common.type.ApplicationStateEnum; + import java.util.UUID; public interface ProfileImageUsecase { void saveProfileImage(UUID userId, String filename); String getProfileImageName(UUID userId); + void updateProfileImageState(UUID userId, ApplicationStateEnum state); void initializeProfileImage(UUID userId); } \ No newline at end of file diff --git a/src/main/java/com/example/api/user/service/UserService.java b/src/main/java/com/example/api/user/service/UserService.java index 3e7ad4d..4c8981b 100644 --- a/src/main/java/com/example/api/user/service/UserService.java +++ b/src/main/java/com/example/api/user/service/UserService.java @@ -152,6 +152,19 @@ public String getProfileImageName(UUID userId) { return profileImageEntity.get().getProfileImage(); } + @Override + public void updateProfileImageState(UUID userId, ApplicationStateEnum state) { + Optional profileImageEntity = profileImagePort.getProfileImage(userId); + if (profileImageEntity.isEmpty()) { + log.error("UserService::updateProfileImageState: Failed loading profile image data"); + throw new CustomException(ErrorCodeEnum.USER_PROFILE_IMAGE_NOT_FOUND); + } + ProfileImage profileImage = userMapper.toDomain(profileImageEntity.get()); + profileImage.setState(state); + profileImage.setUpdatedAt(LocalDateTime.now()); + profileImagePort.saveProfileImage(profileImage); + } + @Override @Transactional public void initializeProfileImage(UUID userId) {