Skip to content

Commit

Permalink
Merge pull request #187 from swm-nodriversomabus/BUS-195-profile-imag…
Browse files Browse the repository at this point in the history
…e-process

feat(BE): 프로필 이미지 인증 수락/거절 BUS-195-profile-image-process #171
  • Loading branch information
namhyo01 authored Nov 8, 2023
2 parents 9807119 + 70f300f commit 2ab3586
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ public FindUserDto updateUser(@Valid @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);
}

/**
* 전체 사용자 삭제 (비상시 외 사용 금지)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public interface UserMapperInterface {
UserAuthorityCheckDto toAuthorityDto(UserEntity userEntity);
FindUserDto toDto(UpdateUserDto updateUserDto);
ProfileImageEntity toEntity(ProfileImage profileImage);
ProfileImage toDomain(ProfileImageEntity profileImageEntity);
}
Original file line number Diff line number Diff line change
@@ -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);
}
13 changes: 13 additions & 0 deletions src/main/java/com/example/api/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ public String getProfileImageName(UUID userId) {
return profileImageEntity.get().getProfileImage();
}

@Override
public void updateProfileImageState(UUID userId, ApplicationStateEnum state) {
Optional<ProfileImageEntity> 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) {
Expand Down

0 comments on commit 2ab3586

Please sign in to comment.