Skip to content

Commit

Permalink
#8 fix: 필수정보 저장 및 수정 API 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
shinhn committed Oct 28, 2022
1 parent e466d1c commit f35d2f5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 127 deletions.
10 changes: 10 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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"),
Expand All @@ -43,17 +40,6 @@ public ApplicationResponse<UserEssentialProfileRes> 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<UserProfileRes> editEssentialProfile(@ModelAttribute EditUserEssentialProfileReq editUserEssentialProfileReq){
// return userService.editEssentialProfile(editUserEssentialProfileReq);
// }

/**
* 유저 Profile 조회
* @author 강신현
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
@Data
Expand All @@ -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<String> languageNames;
List<String> languageLevels;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,14 +24,14 @@ public class UserEssentialProfileRes {
List<String> languageNames = new ArrayList<>();
List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
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;

public interface UserService {
ApplicationResponse<UserEssentialProfileRes> enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq);

//ApplicationResponse<UserProfileRes> editEssentialProfile(EditUserEssentialProfileReq editUserEssentialProfileReq);

//ApplicationResponse<UserProfileRes> getProfile(Long userId);

ApplicationResponse<Void> delProfile(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,92 +33,30 @@ public class UserServiceImpl implements UserService {
@Override
public ApplicationResponse<UserEssentialProfileRes> 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<UserProfileRes> 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<UserProfileRes> getProfile(Long userId){
Expand Down

0 comments on commit f35d2f5

Please sign in to comment.