Skip to content

Commit

Permalink
refactor : 이미지 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hwan committed Jan 21, 2025
1 parent fe9983e commit f54dfd3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
public record EditGroupRequest(@Size(min = 1, max = 15, message = "스터디 이름은 1글자 이상 15글자 이하로 작성해야 합니다.") String name,
LocalDate startDate,
LocalDate endDate,
String introduction) {
String introduction,
Boolean isDefaultImage) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void editGroup(User user, Long groupId, EditGroupRequest request, Multipa
if (!RoleOfGroupMember.isOwner(groupMember))
throw new StudyGroupValidationException(HttpStatus.FORBIDDEN.value(), "그룹 정보 수정에 대한 권한이 없습니다.");

editGroupImage(groupImage, group);
editGroupImage(groupImage, group, request.isDefaultImage());
group.editGroupInfo(
request.name(),
request.startDate(),
Expand All @@ -334,21 +334,26 @@ public void editGroup(User user, Long groupId, EditGroupRequest request, Multipa
log.info("success to edit group info");
}

private void editGroupImage(MultipartFile inputImage, StudyGroup group) {
if (inputImage == null || inputImage.isEmpty()) {
private void editGroupImage(MultipartFile inputImage, StudyGroup group, Boolean isDefaultImage) {
if (inputImage == null && isDefaultImage) {
handleNullInputImage(group);
log.info("group image change as default image ");
return;
}
if (inputImage == null && !isDefaultImage) {
log.info("group image does not change ");
return;
}

if (group.getGroupImage() != null) {
if (group.getGroupImage() != null && !isDefaultImage) {
if (isEqualToGroupImage(group, inputImage)) {
return;
}
imageService.deleteImage(group.getGroupImage());
}

saveGroupImage(inputImage, group);
log.info("success to edit group image");
log.info("success to edit group image : {}", group.getGroupImage());
}

private void saveGroupImage(MultipartFile inputImage, StudyGroup group) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ public void userUpdate(User user, UpdateUserRequest updateUserRequest, Multipart
private void editUserProfileImage(User user, MultipartFile inputImage, Boolean isDefaultImage) {
if (inputImage == null && isDefaultImage) {
handleNullInputImage(user);
log.info("change user profile image as default image");
log.info("user profile image change as default image");
return;
}

if (inputImage == null && !isDefaultImage) {
log.info("user profile image does not change : {}", user.getProfileImage());
log.info("user profile image does not change ");
return;
}

Expand Down

0 comments on commit f54dfd3

Please sign in to comment.