From 842ef6e11992dc95f1952bf6c0de7b56042716e7 Mon Sep 17 00:00:00 2001 From: "@_.mung" Date: Tue, 26 Nov 2024 00:49:42 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84=ED=95=B4=EB=9D=BC=20-=20#30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 프로필 이미지 업로드 로직 구현해야 함. 구현한 내용: - 프로필 이미지 업로드 로직 구현 --- .../domain/diary/mapper/DiaryMapperImpl.java | 2 +- .../mapper/image/DiaryImageMapperImpl.java | 2 +- .../quddyTI/mapper/QuddyTIMapperImpl.java | 2 +- .../dto/request/ProfileReqUpdateDTO.java} | 9 ++--- .../dto/response/ProfileResDetailDTO.java} | 4 +- .../user/controller/UserApiController.java | 8 +--- .../domain/user/facade/UserFacade.java | 6 ++- .../domain/user/facade/UserFacadeImpl.java | 6 ++- .../domain/user/service/UserService.java | 7 ++-- .../domain/user/service/UserServiceImpl.java | 38 +++++++++---------- 10 files changed, 41 insertions(+), 43 deletions(-) rename src/main/java/moodbuddy/moodbuddy/domain/{user/dto/request/UserReqProfileUpdateDto.java => profile/dto/request/ProfileReqUpdateDTO.java} (62%) rename src/main/java/moodbuddy/moodbuddy/domain/{user/dto/response/UserResProfileDTO.java => profile/dto/response/ProfileResDetailDTO.java} (73%) diff --git a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/DiaryMapperImpl.java b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/DiaryMapperImpl.java index e2a17742..e04ce225 100644 --- a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/DiaryMapperImpl.java +++ b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/DiaryMapperImpl.java @@ -7,7 +7,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-11-23T17:53:28+0900", + date = "2024-11-26T00:28:54+0900", comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)" ) @Component diff --git a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/image/DiaryImageMapperImpl.java b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/image/DiaryImageMapperImpl.java index 8f9b5eb8..6c06581d 100644 --- a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/image/DiaryImageMapperImpl.java +++ b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/image/DiaryImageMapperImpl.java @@ -6,7 +6,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-11-23T17:53:28+0900", + date = "2024-11-26T00:28:54+0900", comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)" ) @Component diff --git a/src/main/generated/moodbuddy/moodbuddy/domain/quddyTI/mapper/QuddyTIMapperImpl.java b/src/main/generated/moodbuddy/moodbuddy/domain/quddyTI/mapper/QuddyTIMapperImpl.java index ac646777..68420dcb 100644 --- a/src/main/generated/moodbuddy/moodbuddy/domain/quddyTI/mapper/QuddyTIMapperImpl.java +++ b/src/main/generated/moodbuddy/moodbuddy/domain/quddyTI/mapper/QuddyTIMapperImpl.java @@ -8,7 +8,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-11-23T17:53:28+0900", + date = "2024-11-26T00:28:54+0900", comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)" ) @Component diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/dto/request/UserReqProfileUpdateDto.java b/src/main/java/moodbuddy/moodbuddy/domain/profile/dto/request/ProfileReqUpdateDTO.java similarity index 62% rename from src/main/java/moodbuddy/moodbuddy/domain/user/dto/request/UserReqProfileUpdateDto.java rename to src/main/java/moodbuddy/moodbuddy/domain/profile/dto/request/ProfileReqUpdateDTO.java index 0089ecfb..a221b1f5 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/dto/request/UserReqProfileUpdateDto.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/profile/dto/request/ProfileReqUpdateDTO.java @@ -1,8 +1,7 @@ -package moodbuddy.moodbuddy.domain.user.dto.request; +package moodbuddy.moodbuddy.domain.profile.dto.request; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; -import org.springframework.web.multipart.MultipartFile; @AllArgsConstructor @@ -10,15 +9,15 @@ @Builder @Getter @Setter -public class UserReqProfileUpdateDto { +public class ProfileReqUpdateDTO { String profileComment; Boolean alarm; @Schema(description = "알림, HH:mm 형식") String alarmTime; @Schema(description = "사용자 전화번호, -을 제외한 01012345678 형식") String phoneNumber; - @Schema(description = "수정할 프로필 이미지", example = "[\"image1.png\", \"image2.png\"]") - MultipartFile newProfileImg; + @Schema(description = "업로드 할 이미지 url", example = "이미지 url") + String profileImageUrl; String nickname; Boolean gender; @Schema(description = "생일, YYYY-mm-dd 형식") diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/dto/response/UserResProfileDTO.java b/src/main/java/moodbuddy/moodbuddy/domain/profile/dto/response/ProfileResDetailDTO.java similarity index 73% rename from src/main/java/moodbuddy/moodbuddy/domain/user/dto/response/UserResProfileDTO.java rename to src/main/java/moodbuddy/moodbuddy/domain/profile/dto/response/ProfileResDetailDTO.java index 60dd297f..61832976 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/dto/response/UserResProfileDTO.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/profile/dto/response/ProfileResDetailDTO.java @@ -1,4 +1,4 @@ -package moodbuddy.moodbuddy.domain.user.dto.response; +package moodbuddy.moodbuddy.domain.profile.dto.response; import lombok.*; @@ -7,7 +7,7 @@ @Builder @Getter @Setter -public class UserResProfileDTO { +public class ProfileResDetailDTO { String url; String profileComment; String nickname; diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/controller/UserApiController.java b/src/main/java/moodbuddy/moodbuddy/domain/user/controller/UserApiController.java index e9de56a9..132c9890 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/controller/UserApiController.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/controller/UserApiController.java @@ -5,18 +5,15 @@ import io.swagger.v3.oas.annotations.Parameters; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import moodbuddy.moodbuddy.domain.profile.dto.request.ProfileReqUpdateDTO; import moodbuddy.moodbuddy.domain.user.dto.request.*; -import moodbuddy.moodbuddy.domain.user.dto.response.*; -import moodbuddy.moodbuddy.domain.user.facade.UserFacade; import moodbuddy.moodbuddy.domain.user.service.UserService; import moodbuddy.moodbuddy.global.common.util.JwtUtil; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.io.IOException; import java.time.LocalDate; -import java.util.List; @RestController @RequiredArgsConstructor @@ -104,12 +101,11 @@ public ResponseEntity getProfile() { return ResponseEntity.ok(userService.getUserProfile()); } - //프로필 수정 @PostMapping ("/main/profile-edit") @Operation(summary = "프로필 수정", description = "alarmTime(str) -> HH:mm 형식,birthday(str) -> YYYY-mm-dd 형식 ") public ResponseEntity updateProfile( - @ModelAttribute UserReqProfileUpdateDto updateDto) throws IOException { + @ModelAttribute ProfileReqUpdateDTO updateDto) { Long kakaoId = JwtUtil.getUserId(); userService.scheduleUserMessage(kakaoId); return ResponseEntity.ok(userService.updateProfile(updateDto)); diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/facade/UserFacade.java b/src/main/java/moodbuddy/moodbuddy/domain/user/facade/UserFacade.java index 65464d3a..da443a7d 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/facade/UserFacade.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/facade/UserFacade.java @@ -1,5 +1,7 @@ package moodbuddy.moodbuddy.domain.user.facade; +import moodbuddy.moodbuddy.domain.profile.dto.request.ProfileReqUpdateDTO; +import moodbuddy.moodbuddy.domain.profile.dto.response.ProfileResDetailDTO; import moodbuddy.moodbuddy.domain.user.dto.request.*; import moodbuddy.moodbuddy.domain.user.dto.response.*; @@ -15,9 +17,9 @@ public interface UserFacade { UserResMonthCommentUpdateDTO monthCommentUpdate(UserReqMonthCommentUpdateDTO userReqMonthCommentUpdateDTO); List getDiaryNums(LocalDate year); List getEmotionNums(LocalDate month); - UserResProfileDTO getUserProfile(); + ProfileResDetailDTO getUserProfile(); void scheduleUserMessage(Long kakaoId); - UserResProfileDTO updateProfile(UserReqProfileUpdateDto updateDto); + ProfileResDetailDTO updateProfile(ProfileReqUpdateDTO updateDto); UserResLoginDTO login(UserReqLoginDTO userReqLoginDTO); UserResCheckTodayDiaryDTO checkTodayDiary(); } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/facade/UserFacadeImpl.java b/src/main/java/moodbuddy/moodbuddy/domain/user/facade/UserFacadeImpl.java index 8a979c27..84238453 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/facade/UserFacadeImpl.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/facade/UserFacadeImpl.java @@ -1,6 +1,8 @@ package moodbuddy.moodbuddy.domain.user.facade; import lombok.RequiredArgsConstructor; +import moodbuddy.moodbuddy.domain.profile.dto.request.ProfileReqUpdateDTO; +import moodbuddy.moodbuddy.domain.profile.dto.response.ProfileResDetailDTO; import moodbuddy.moodbuddy.domain.user.dto.request.*; import moodbuddy.moodbuddy.domain.user.dto.response.*; import org.springframework.stereotype.Component; @@ -53,7 +55,7 @@ public List getEmotionNums(LocalDate month) { } @Override - public UserResProfileDTO getUserProfile() { + public ProfileResDetailDTO getUserProfile() { return null; } @@ -63,7 +65,7 @@ public void scheduleUserMessage(Long kakaoId) { } @Override - public UserResProfileDTO updateProfile(UserReqProfileUpdateDto updateDto) { + public ProfileResDetailDTO updateProfile(ProfileReqUpdateDTO updateDto) { return null; } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserService.java b/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserService.java index 03de7bfa..44d907ee 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserService.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserService.java @@ -1,5 +1,7 @@ package moodbuddy.moodbuddy.domain.user.service; +import moodbuddy.moodbuddy.domain.profile.dto.request.ProfileReqUpdateDTO; +import moodbuddy.moodbuddy.domain.profile.dto.response.ProfileResDetailDTO; import moodbuddy.moodbuddy.domain.user.dto.request.*; import moodbuddy.moodbuddy.domain.user.dto.response.UserResCalendarMonthListDTO; import moodbuddy.moodbuddy.domain.user.dto.response.UserResCalendarSummaryDTO; @@ -7,7 +9,6 @@ import moodbuddy.moodbuddy.domain.user.dto.response.*; import moodbuddy.moodbuddy.domain.user.domain.User; -import java.io.IOException; import java.time.LocalDate; import java.util.List; @@ -31,10 +32,10 @@ public interface UserService { List getEmotionNums(LocalDate month); //프로필 조회 - UserResProfileDTO getUserProfile(); + ProfileResDetailDTO getUserProfile(); //프로필 수정 - UserResProfileDTO updateProfile(UserReqProfileUpdateDto dto) throws IOException; + ProfileResDetailDTO updateProfile(ProfileReqUpdateDTO requestDTO) ; // 사용자가 설정한 알림 시간에 문자 보내기 void scheduleUserMessage(Long userId); diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserServiceImpl.java b/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserServiceImpl.java index c557bec9..64ffd960 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserServiceImpl.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserServiceImpl.java @@ -5,10 +5,11 @@ import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryEmotion; import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryStatus; import moodbuddy.moodbuddy.domain.diary.repository.DiaryRepository; -import moodbuddy.moodbuddy.domain.diary.service.image.DiaryImageService; import moodbuddy.moodbuddy.domain.monthcomment.domain.MonthComment; import moodbuddy.moodbuddy.domain.monthcomment.repository.MonthCommentRepository; import moodbuddy.moodbuddy.domain.profile.domain.Profile; +import moodbuddy.moodbuddy.domain.profile.dto.request.ProfileReqUpdateDTO; +import moodbuddy.moodbuddy.domain.profile.dto.response.ProfileResDetailDTO; import moodbuddy.moodbuddy.domain.profile.repository.ProfileRepository; import moodbuddy.moodbuddy.domain.profile.domain.ProfileImage; import moodbuddy.moodbuddy.domain.profile.repository.ProfileImageRepository; @@ -31,7 +32,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.IOException; + import java.time.*; import java.time.format.DateTimeFormatter; import java.util.*; @@ -44,13 +45,12 @@ @RequiredArgsConstructor @EnableScheduling @Slf4j -public class UserServiceImpl implements UserService{ +public class UserServiceImpl implements UserService { private final UserRepository userRepository; private final ProfileRepository profileRepository; private final ProfileImageRepository profileImageRepository; private final DiaryRepository diaryRepository; private final MonthCommentRepository monthCommentRepository; - private final DiaryImageService diaryImageService; private final ScheduledExecutorService scheduledExecutorService; private final SmsService smsService; @@ -408,7 +408,7 @@ public List getEmotionNums(LocalDate month) { //프로필 이미지 s3에 저장 -> url setter로 변경 @Override @Transactional - public UserResProfileDTO updateProfile(UserReqProfileUpdateDto dto) throws IOException { + public ProfileResDetailDTO updateProfile(ProfileReqUpdateDTO requestDTO) { Long userId = JwtUtil.getUserId(); User user = userRepository.findByUserId(userId).orElseThrow( @@ -421,29 +421,27 @@ public UserResProfileDTO updateProfile(UserReqProfileUpdateDto dto) throws IOExc () -> new ProfileImageNotFoundByUserIdException(ErrorCode.NOT_FOUND_PROFILE_IMAGE) ); - profile.setProfileComment(dto.getProfileComment()); + profile.setProfileComment(requestDTO.getProfileComment()); profileRepository.save(profile); - user.setAlarm(dto.getAlarm()); - user.setAlarmTime(dto.getAlarmTime()); - user.setPhoneNumber(dto.getPhoneNumber()); - user.setNickname(dto.getNickname()); - user.setGender(dto.getGender()); - user.setBirthday(dto.getBirthday()); + user.setAlarm(requestDTO.getAlarm()); + user.setAlarmTime(requestDTO.getAlarmTime()); + user.setPhoneNumber(requestDTO.getPhoneNumber()); + user.setNickname(requestDTO.getNickname()); + user.setGender(requestDTO.getGender()); + user.setBirthday(requestDTO.getBirthday()); userRepository.save(user); - if (dto.getNewProfileImg() != null) { - String url = diaryImageService.saveProfileImages(dto.getNewProfileImg()); - profileImage.setProfileImgURL(url); - profileImageRepository.save(profileImage); + String profileImageUrl = requestDTO.getProfileImageUrl(); + if (profileImageUrl != null) { + profileImage.setProfileImgURL(profileImageUrl); } - // 업데이트된 정보를 기반으로 UserResProfileDTO 객체를 생성하여 반환 return createUserResProfileDTO(user, profile, profileImage); } - private UserResProfileDTO createUserResProfileDTO(User user, Profile profile, ProfileImage profileImage) { - return UserResProfileDTO.builder() + private ProfileResDetailDTO createUserResProfileDTO(User user, Profile profile, ProfileImage profileImage) { + return ProfileResDetailDTO.builder() .url(profileImage.getProfileImgURL()) .profileComment(profile.getProfileComment()) .nickname(user.getNickname()) @@ -457,7 +455,7 @@ private UserResProfileDTO createUserResProfileDTO(User user, Profile profile, Pr @Override @Transactional(readOnly = true) - public UserResProfileDTO getUserProfile() { + public ProfileResDetailDTO getUserProfile() { Long userId = JwtUtil.getUserId(); User user = userRepository.findByUserId(userId).orElseThrow(