Skip to content

Commit

Permalink
[�Merge] 프로필 이미지 업로드 로직 구현
Browse files Browse the repository at this point in the history
[Feature] 프로필 이미지 업로드 로직 구현
  • Loading branch information
M-ung authored Nov 25, 2024
2 parents 09a54e1 + 842ef6e commit 9282741
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
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
@NoArgsConstructor
@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 형식")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package moodbuddy.moodbuddy.domain.user.dto.response;
package moodbuddy.moodbuddy.domain.profile.dto.response;

import lombok.*;

Expand All @@ -7,7 +7,7 @@
@Builder
@Getter
@Setter
public class UserResProfileDTO {
public class ProfileResDetailDTO {
String url;
String profileComment;
String nickname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;

Expand All @@ -15,9 +17,9 @@ public interface UserFacade {
UserResMonthCommentUpdateDTO monthCommentUpdate(UserReqMonthCommentUpdateDTO userReqMonthCommentUpdateDTO);
List<UserDiaryNumsDTO> getDiaryNums(LocalDate year);
List<UserEmotionStaticDTO> 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();
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -53,7 +55,7 @@ public List<UserEmotionStaticDTO> getEmotionNums(LocalDate month) {
}

@Override
public UserResProfileDTO getUserProfile() {
public ProfileResDetailDTO getUserProfile() {
return null;
}

Expand All @@ -63,7 +65,7 @@ public void scheduleUserMessage(Long kakaoId) {
}

@Override
public UserResProfileDTO updateProfile(UserReqProfileUpdateDto updateDto) {
public ProfileResDetailDTO updateProfile(ProfileReqUpdateDTO updateDto) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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;
import moodbuddy.moodbuddy.domain.user.dto.response.UserResMainPageDTO;
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;

Expand All @@ -31,10 +32,10 @@ public interface UserService {
List<UserEmotionStaticDTO> getEmotionNums(LocalDate month);

//프로필 조회
UserResProfileDTO getUserProfile();
ProfileResDetailDTO getUserProfile();

//프로필 수정
UserResProfileDTO updateProfile(UserReqProfileUpdateDto dto) throws IOException;
ProfileResDetailDTO updateProfile(ProfileReqUpdateDTO requestDTO) ;

// 사용자가 설정한 알림 시간에 문자 보내기
void scheduleUserMessage(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand All @@ -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;

Expand Down Expand Up @@ -408,7 +408,7 @@ public List<UserEmotionStaticDTO> 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(
Expand All @@ -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())
Expand All @@ -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(
Expand Down

0 comments on commit 9282741

Please sign in to comment.