Skip to content

Commit

Permalink
Merge pull request #82 from mju-likelion/feature/refactor-user-respon…
Browse files Browse the repository at this point in the history
…se-dto-#81

Feature/#81 유저 정보 반환 ResponseDto 리팩토링
  • Loading branch information
rnqhstmd authored Aug 6, 2024
2 parents f42e193 + e359140 commit d08a0b4
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.example.mutsideout_mju.dto.request.survey.SurveyResultListDto;
import com.example.mutsideout_mju.dto.response.ResponseDto;
import com.example.mutsideout_mju.dto.response.survey.SurveyQuestionListResponseDto;
import com.example.mutsideout_mju.dto.response.user.UserGradeResponseDto;
import com.example.mutsideout_mju.dto.response.user.UserInfoResponseDto;
import com.example.mutsideout_mju.entity.User;
import com.example.mutsideout_mju.service.SurveyService;
import com.example.mutsideout_mju.service.UserService;
Expand All @@ -24,11 +24,11 @@ public class SurveyController {

// 설문조사 응답
@PostMapping
public ResponseEntity<ResponseDto<UserGradeResponseDto>> saveSurveyResults(@AuthenticatedUser User user,
@RequestBody @Valid SurveyResultListDto surveyResultListDto) {
public ResponseEntity<ResponseDto<UserInfoResponseDto>> saveSurveyResults(@AuthenticatedUser User user,
@RequestBody @Valid SurveyResultListDto surveyResultListDto) {
surveyService.saveSurveyResults(user, surveyResultListDto);
UserGradeResponseDto userGradeResponseDto = userService.calculateUserGrade(user);
return new ResponseEntity<>(ResponseDto.res(HttpStatus.OK, "설문조사 저장 및 유저 등급 반환 완료", userGradeResponseDto), HttpStatus.OK);
UserInfoResponseDto userInfoResponseDto = userService.calculateUserGrade(user);
return new ResponseEntity<>(ResponseDto.res(HttpStatus.OK, "설문조사 저장 및 유저 등급 반환 완료", userInfoResponseDto), HttpStatus.OK);
}

// 설문조사 질문 전체 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.example.mutsideout_mju.dto.request.user.DeleteUserDto;
import com.example.mutsideout_mju.dto.request.user.UpdateUserDto;
import com.example.mutsideout_mju.dto.response.ResponseDto;
import com.example.mutsideout_mju.dto.response.user.ProfileResponseData;
import com.example.mutsideout_mju.dto.response.user.UserGradeResponseDto;
import com.example.mutsideout_mju.dto.response.user.UserInfoResponseDto;
import com.example.mutsideout_mju.entity.User;
import com.example.mutsideout_mju.service.UserService;
import jakarta.validation.Valid;
Expand All @@ -22,31 +21,31 @@ public class UserController {

// 유저 등급 조회
@GetMapping("/grade")
public ResponseEntity<ResponseDto<UserGradeResponseDto>> getUserGrade(@AuthenticatedUser User user) {
UserGradeResponseDto userGradeResponseDto = userService.getUserGrade(user);
return new ResponseEntity<>(ResponseDto.res(HttpStatus.OK, "유저 등급 조회 완료", userGradeResponseDto), HttpStatus.OK);
public ResponseEntity<ResponseDto<UserInfoResponseDto>> getUserGrade(@AuthenticatedUser User user) {
UserInfoResponseDto userInfoResponseDto = userService.getUserGrade(user);
return new ResponseEntity<>(ResponseDto.res(HttpStatus.OK, "유저 등급 조회 완료", userInfoResponseDto), HttpStatus.OK);
}

// 유저 정보 수정
@PatchMapping
public ResponseEntity<ResponseDto<Void>> updateUser(@AuthenticatedUser User user,
@RequestBody @Valid UpdateUserDto updateUserDto) {
@RequestBody @Valid UpdateUserDto updateUserDto) {
userService.updateUser(user, updateUserDto);
return new ResponseEntity<>(ResponseDto.res(HttpStatus.OK, "유저 정보 수정 완료"), HttpStatus.OK);
}

// 유저 탈퇴
@DeleteMapping
public ResponseEntity<ResponseDto<Void>> deleteUser(@AuthenticatedUser User user,
@RequestBody @Valid DeleteUserDto deleteUserDto) {
@RequestBody @Valid DeleteUserDto deleteUserDto) {
userService.deleteUser(user, deleteUserDto);
return new ResponseEntity<>(ResponseDto.res(HttpStatus.OK, "회원 탈퇴 성공"), HttpStatus.OK);
}

// 유저 전체 정보(이메일, 이름, 등급) 조회
@GetMapping("/mypage")
public ResponseEntity<ResponseDto<ProfileResponseData>> getMyPage(@AuthenticatedUser User user) {
ProfileResponseData profileResponseData = userService.getMyPage(user);
return new ResponseEntity<>(ResponseDto.res(HttpStatus.OK, "회원 정보 조회 완료", profileResponseData), HttpStatus.OK);
public ResponseEntity<ResponseDto<UserInfoResponseDto>> getMyPage(@AuthenticatedUser User user) {
UserInfoResponseDto userInfoResponseDto = userService.getMyPage(user);
return new ResponseEntity<>(ResponseDto.res(HttpStatus.OK, "회원 정보 조회 완료", userInfoResponseDto), HttpStatus.OK);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.mutsideout_mju.dto.response.user;

import com.example.mutsideout_mju.entity.User;
import com.example.mutsideout_mju.entity.UserGrade;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class UserInfoResponseDto {
private String email;
private String name;
private UserGrade userGrade;

public static UserInfoResponseDto of(String email, String name, UserGrade userGrade) {
return builder()
.email(email)
.userGrade(userGrade)
.name(name)
.build();
}

public static UserInfoResponseDto of(String name, UserGrade userGrade) {
return builder()
.name(name)
.userGrade(userGrade)
.build();
}

public static UserInfoResponseDto from(UserGrade userGrade) {
return builder()
.userGrade(userGrade)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.UUID;

public interface UserSurveyRepository extends JpaRepository<UserSurvey, UUID>, CustomUserSurveyRepository {
List<UserSurvey> findByUserId(UUID userId);
boolean existsByUserId(UUID userId);
List<UserSurvey> findByUserIdAndSurveyIdIn(UUID userId, List<UUID> surveyIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public DailyPlannerCompletionDataList getMonthlyPlannerStats(User user, String m
*/
public void deletePlanner(User user, UUID plannerId) {
Planner planner = findPlanner(user.getId(), plannerId);
if(planner.isCompleted()){
if (planner.isCompleted()) {
throw new ForbiddenException(ErrorCode.INVALID_PLANNER_ACCESS, "완료된 플랜은 삭제할 수 없습니다.");
}
plannerRepository.delete(planner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.example.mutsideout_mju.authentication.PasswordHashEncryption;
import com.example.mutsideout_mju.dto.request.user.DeleteUserDto;
import com.example.mutsideout_mju.dto.request.user.UpdateUserDto;
import com.example.mutsideout_mju.dto.response.user.ProfileResponseData;
import com.example.mutsideout_mju.dto.response.user.UserGradeResponseDto;
import com.example.mutsideout_mju.dto.response.user.UserInfoResponseDto;
import com.example.mutsideout_mju.entity.UserGrade;
import com.example.mutsideout_mju.entity.User;
import com.example.mutsideout_mju.exception.ConflictException;
Expand All @@ -27,21 +26,21 @@ public class UserService {
* 설문조사 유효 응답갯수로 유저 등급 계산
*/
@Transactional
public UserGradeResponseDto calculateUserGrade(User user) {
public UserInfoResponseDto calculateUserGrade(User user) {
long count = userSurveyRepository.countValidSurveyResponse(user.getId());
UserGrade userGrade = user.determineGrade(count);

user.setUserGrade(userGrade);
userRepository.save(user);

return UserGradeResponseDto.of(user.getName(), userGrade);
return UserInfoResponseDto.of(user.getName(), userGrade);
}

/**
* 유저 등급 반환
*/
public UserGradeResponseDto getUserGrade(User user) {
return UserGradeResponseDto.from(user.getUserGrade());
public UserInfoResponseDto getUserGrade(User user) {
return UserInfoResponseDto.from(user.getUserGrade());
}

/**
Expand Down Expand Up @@ -74,9 +73,9 @@ public void updateUser(User user, UpdateUserDto updateUserDto) {
/**
* 유저 전체 정보(이메일, 이름, 등급) 조회
*/
public ProfileResponseData getMyPage(User user){
ProfileResponseData profileResponseData = ProfileResponseData.of(user.getEmail(), user.getName(), user.getUserGrade());
return profileResponseData;
public UserInfoResponseDto getMyPage(User user) {
UserInfoResponseDto userInfoResponseDto = UserInfoResponseDto.of(user.getEmail(), user.getName(), user.getUserGrade());
return userInfoResponseDto;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private String getImagePath(String link) {
public List<String> uploadImage(List<MultipartFile> files) throws IOException {
List<String> imageUrls = new ArrayList<>();

for(MultipartFile file : files){
for (MultipartFile file : files) {
String dateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
String extension = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));

Expand Down

0 comments on commit d08a0b4

Please sign in to comment.