From f35d2f50e6ca55ade87594581bf49bd5816824e8 Mon Sep 17 00:00:00 2001 From: shinhn Date: Fri, 28 Oct 2022 23:14:26 +0900 Subject: [PATCH] =?UTF-8?q?#8=20fix:=20=ED=95=84=EC=88=98=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A0=80=EC=9E=A5=20=EB=B0=8F=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20API=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/inspectionProfiles/Project_Default.xml | 10 ++ .../user/controller/UserController.java | 18 +-- .../request/EditUserEssentialProfileReq.java | 18 +-- .../dto/response/UserEssentialProfileRes.java | 13 +-- .../server/user/service/UserService.java | 7 +- .../server/user/service/UserServiceImpl.java | 103 ++++-------------- 6 files changed, 42 insertions(+), 127 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..875ffa2 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/server/src/main/java/com/yogit/server/user/controller/UserController.java b/server/src/main/java/com/yogit/server/user/controller/UserController.java index 116219f..b5056a2 100644 --- a/server/src/main/java/com/yogit/server/user/controller/UserController.java +++ b/server/src/main/java/com/yogit/server/user/controller/UserController.java @@ -1,10 +1,7 @@ package com.yogit.server.user.controller; import com.yogit.server.global.dto.ApplicationResponse; -import com.yogit.server.user.dto.request.AddUserAdditionalProfileReq; -import com.yogit.server.user.dto.request.CreateUserEssentialProfileReq; -import com.yogit.server.user.dto.request.CreateUserImageReq; -import com.yogit.server.user.dto.request.CreateUserReq; +import com.yogit.server.user.dto.request.*; import com.yogit.server.user.dto.response.UserAdditionalProfileRes; import com.yogit.server.user.dto.response.UserEssentialProfileRes; import com.yogit.server.user.dto.response.UserImagesRes; @@ -30,7 +27,7 @@ public class UserController { * 유저 필수 정보 입력 * @author 강신현 */ - @ApiOperation(value = "유저 필수 정보 입력", notes = "languageName1 부터, languageLevel1 부터 차례로 입력해주세요 (swagger에서 enum 열거형을 지원하지 않으므로)") + @ApiOperation(value = "유저 필수 정보 입력 및 수정") @ApiImplicitParams({ @ApiImplicitParam(name = "userName", required = true, dataTypeClass = String.class), @ApiImplicitParam(name = "userAge", required = true, dataTypeClass = int.class, example = "0"), @@ -43,17 +40,6 @@ public ApplicationResponse enterEssentialProfile(@Model return userService.enterEssentialProfile(createUserEssentialProfileReq); } - /** - * 유저 필수 정보 수정 - * @author 강신현 - */ -// @ApiOperation(value = "유저 필수 정보 수정", notes = "수정할 정보들만 입력해주세요, Language 중에 하나라도 변경사항이 있다면 유저의 모든 Language 를 입력하여 요청해주세요") -// @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0") -// @PatchMapping("/edit-essential-profile") -// public ApplicationResponse editEssentialProfile(@ModelAttribute EditUserEssentialProfileReq editUserEssentialProfileReq){ -// return userService.editEssentialProfile(editUserEssentialProfileReq); -// } - /** * 유저 Profile 조회 * @author 강신현 diff --git a/server/src/main/java/com/yogit/server/user/dto/request/EditUserEssentialProfileReq.java b/server/src/main/java/com/yogit/server/user/dto/request/EditUserEssentialProfileReq.java index f2d3de9..bd5f9c6 100644 --- a/server/src/main/java/com/yogit/server/user/dto/request/EditUserEssentialProfileReq.java +++ b/server/src/main/java/com/yogit/server/user/dto/request/EditUserEssentialProfileReq.java @@ -5,6 +5,8 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; + @NoArgsConstructor @AllArgsConstructor @Data @@ -17,18 +19,6 @@ public class EditUserEssentialProfileReq { Gender gender; Nationality nationality; -// LanguageName languageName1; -// LanguageLevel languageLevel1; -// -// LanguageName languageName2; -// LanguageLevel languageLevel2; -// -// LanguageName languageName3; -// LanguageLevel languageLevel3; -// -// LanguageName languageName4; -// LanguageLevel languageLevel4; -// -// LanguageName languageName5; -// LanguageLevel languageLevel5; + List languageNames; + List languageLevels; } diff --git a/server/src/main/java/com/yogit/server/user/dto/response/UserEssentialProfileRes.java b/server/src/main/java/com/yogit/server/user/dto/response/UserEssentialProfileRes.java index 80434d1..23aa26b 100644 --- a/server/src/main/java/com/yogit/server/user/dto/response/UserEssentialProfileRes.java +++ b/server/src/main/java/com/yogit/server/user/dto/response/UserEssentialProfileRes.java @@ -1,6 +1,5 @@ package com.yogit.server.user.dto.response; -import com.yogit.server.user.dto.request.CreateUserEssentialProfileReq; import com.yogit.server.user.entity.Gender; import com.yogit.server.user.entity.Nationality; import lombok.AllArgsConstructor; @@ -25,14 +24,14 @@ public class UserEssentialProfileRes { List languageNames = new ArrayList<>(); List languageLevels = new ArrayList<>(); - public static UserEssentialProfileRes create(CreateUserEssentialProfileReq createUserEssentialProfileReq){ + public static UserEssentialProfileRes create(Long userId, String userName, Integer userAge, Gender gender, Nationality nationality){ UserEssentialProfileRes userEssentialProfileRes = new UserEssentialProfileRes(); - userEssentialProfileRes.userId = createUserEssentialProfileReq.getUserId(); - userEssentialProfileRes.userName = createUserEssentialProfileReq.getUserName(); - userEssentialProfileRes.userAge = createUserEssentialProfileReq.getUserAge(); - userEssentialProfileRes.gender = createUserEssentialProfileReq.getGender(); - userEssentialProfileRes.nationality = createUserEssentialProfileReq.getNationality(); + userEssentialProfileRes.userId = userId; + userEssentialProfileRes.userName = userName; + userEssentialProfileRes.userAge = userAge; + userEssentialProfileRes.gender = gender; + userEssentialProfileRes.nationality = nationality; return userEssentialProfileRes; } diff --git a/server/src/main/java/com/yogit/server/user/service/UserService.java b/server/src/main/java/com/yogit/server/user/service/UserService.java index 35229b2..8bfdc01 100644 --- a/server/src/main/java/com/yogit/server/user/service/UserService.java +++ b/server/src/main/java/com/yogit/server/user/service/UserService.java @@ -1,10 +1,7 @@ package com.yogit.server.user.service; import com.yogit.server.global.dto.ApplicationResponse; -import com.yogit.server.user.dto.request.AddUserAdditionalProfileReq; -import com.yogit.server.user.dto.request.CreateUserEssentialProfileReq; -import com.yogit.server.user.dto.request.CreateUserImageReq; -import com.yogit.server.user.dto.request.CreateUserReq; +import com.yogit.server.user.dto.request.*; import com.yogit.server.user.dto.response.UserAdditionalProfileRes; import com.yogit.server.user.dto.response.UserEssentialProfileRes; import com.yogit.server.user.dto.response.UserImagesRes; @@ -12,8 +9,6 @@ public interface UserService { ApplicationResponse enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq); - //ApplicationResponse editEssentialProfile(EditUserEssentialProfileReq editUserEssentialProfileReq); - //ApplicationResponse getProfile(Long userId); ApplicationResponse delProfile(Long userId); diff --git a/server/src/main/java/com/yogit/server/user/service/UserServiceImpl.java b/server/src/main/java/com/yogit/server/user/service/UserServiceImpl.java index a6657f0..192aa5d 100644 --- a/server/src/main/java/com/yogit/server/user/service/UserServiceImpl.java +++ b/server/src/main/java/com/yogit/server/user/service/UserServiceImpl.java @@ -2,10 +2,7 @@ import com.yogit.server.global.dto.ApplicationResponse; import com.yogit.server.s3.AwsS3Service; -import com.yogit.server.user.dto.request.AddUserAdditionalProfileReq; -import com.yogit.server.user.dto.request.CreateUserEssentialProfileReq; -import com.yogit.server.user.dto.request.CreateUserImageReq; -import com.yogit.server.user.dto.request.CreateUserReq; +import com.yogit.server.user.dto.request.*; import com.yogit.server.user.dto.response.UserAdditionalProfileRes; import com.yogit.server.user.dto.response.UserEssentialProfileRes; import com.yogit.server.user.dto.response.UserImagesRes; @@ -36,92 +33,30 @@ public class UserServiceImpl implements UserService { @Override public ApplicationResponse enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq){ - User user = userRepository.findById(createUserEssentialProfileReq.getUserId()).orElseThrow(); + User user = userRepository.findById(createUserEssentialProfileReq.getUserId()).orElseThrow(NotFoundUserException::new); user.changeUserInfo(createUserEssentialProfileReq.getUserName(), createUserEssentialProfileReq.getUserAge(), createUserEssentialProfileReq.getGender(), createUserEssentialProfileReq.getNationality()); - UserEssentialProfileRes userEssentialProfileRes = UserEssentialProfileRes.create(createUserEssentialProfileReq); - - for(int i=0;i < createUserEssentialProfileReq.getLanguageNames().size(); i++){ - Language language = Language.builder() - .user(user) - .name(createUserEssentialProfileReq.getLanguageNames().get(i)) - .level(createUserEssentialProfileReq.getLanguageLevels().get(i)) - .build(); - languageRepository.save(language); - - userEssentialProfileRes.addLanguage(createUserEssentialProfileReq.getLanguageNames().get(i), createUserEssentialProfileReq.getLanguageLevels().get(i)); + UserEssentialProfileRes userEssentialProfileRes = UserEssentialProfileRes.create(createUserEssentialProfileReq.getUserId(), createUserEssentialProfileReq.getUserName(), createUserEssentialProfileReq.getUserAge(), createUserEssentialProfileReq.getGender(), createUserEssentialProfileReq.getNationality()); + + if(!createUserEssentialProfileReq.getLanguageNames().isEmpty()) { + // 기존 languages 삭제 + languageRepository.deleteAllByUserId(createUserEssentialProfileReq.getUserId()); + // 새로운 languages 추가 + for(int i=0;i < createUserEssentialProfileReq.getLanguageNames().size(); i++){ + Language language = Language.builder() + .user(user) + .name(createUserEssentialProfileReq.getLanguageNames().get(i)) + .level(createUserEssentialProfileReq.getLanguageLevels().get(i)) + .build(); + languageRepository.save(language); + + userEssentialProfileRes.addLanguage(createUserEssentialProfileReq.getLanguageNames().get(i), createUserEssentialProfileReq.getLanguageLevels().get(i)); + } } - return ApplicationResponse.create("created", userEssentialProfileRes); + return ApplicationResponse.ok(userEssentialProfileRes); } -// @Transactional -// @Override -// public ApplicationResponse editEssentialProfile(EditUserEssentialProfileReq editUserEssentialProfileReq){ -// -// User user = userRepository.findById(editUserEssentialProfileReq.getUserId()).orElseThrow(NotFoundUserException::new); -// user.changeUserInfo(editUserEssentialProfileReq); -// -// UserProfileRes userProfileRes = UserProfileRes.create(user); -// -// if(editUserEssentialProfileReq.getLanguageName1() != null){ -// // 기존 language 들 삭제 -// languageRepository.deleteAllByUserId(user.getId()); -// -// // language 추가 -// if(editUserEssentialProfileReq.getLanguageName1() != null && editUserEssentialProfileReq.getLanguageLevel1() != null){ -// Language language = Language.builder() -// .user(user) -// .name(editUserEssentialProfileReq.getLanguageName1()) -// .level(editUserEssentialProfileReq.getLanguageLevel1()) -// .build(); -// languageRepository.save(language); -// userProfileRes.addLanguage(language); -// } -// -// if(editUserEssentialProfileReq.getLanguageName2() != null && editUserEssentialProfileReq.getLanguageLevel2() != null){ -// Language language = Language.builder() -// .user(user) -// .name(editUserEssentialProfileReq.getLanguageName2()) -// .level(editUserEssentialProfileReq.getLanguageLevel2()) -// .build(); -// languageRepository.save(language); -// userProfileRes.addLanguage(language); -// } -// -// if(editUserEssentialProfileReq.getLanguageName3() != null && editUserEssentialProfileReq.getLanguageLevel3() != null){ -// Language language = Language.builder() -// .user(user) -// .name(editUserEssentialProfileReq.getLanguageName3()) -// .level(editUserEssentialProfileReq.getLanguageLevel3()) -// .build(); -// languageRepository.save(language); -// userProfileRes.addLanguage(language); -// } -// -// if(editUserEssentialProfileReq.getLanguageName4() != null && editUserEssentialProfileReq.getLanguageLevel4() != null){ -// Language language = Language.builder() -// .user(user) -// .name(editUserEssentialProfileReq.getLanguageName4()) -// .level(editUserEssentialProfileReq.getLanguageLevel4()) -// .build(); -// languageRepository.save(language); -// userProfileRes.addLanguage(language); -// } -// -// if(editUserEssentialProfileReq.getLanguageName5() != null && editUserEssentialProfileReq.getLanguageLevel5() != null){ -// Language language = Language.builder() -// .user(user) -// .name(editUserEssentialProfileReq.getLanguageName5()) -// .level(editUserEssentialProfileReq.getLanguageLevel5()) -// .build(); -// languageRepository.save(language); -// userProfileRes.addLanguage(language); -// } -// } -// -// return ApplicationResponse.ok(userProfileRes); -// } // @Override // public ApplicationResponse getProfile(Long userId){