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 3673e72..3e4daa3 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 @@ -30,10 +30,10 @@ public class UserController { private final UserService userService; /** - * 유저 필수 정보 입력 및 수정 + * 유저 프로필 정보 입력 및 수정 * @author 강신현 */ - @ApiOperation(value = "유저 필수 정보 입력 및 수정") + @ApiOperation(value = "유저 프로필 정보 입력 및 수정") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "1"), @ApiImplicitParam(name = "userName", dataTypeClass = String.class, example = "강신현"), @@ -42,18 +42,23 @@ public class UserController { @ApiImplicitParam(name = "nationality", dataTypeClass = String.class, example = "Korea"), @ApiImplicitParam(name = "languageNames", dataType = "list", value = "언어 이름을 순서대로 넣어주세요"), @ApiImplicitParam(name = "languageLevels", dataType = "list", value = "언어 레벨을 순서대로 넣어주세요"), + @ApiImplicitParam(name = "latitude", dataTypeClass = Float.class, example = "10.23"), + @ApiImplicitParam(name = "longitude", dataTypeClass = Float.class, example = "10.23"), + @ApiImplicitParam(name = "aboutMe", dataTypeClass = String.class, example = "캠핑 모임에 관심이 많습니다."), + @ApiImplicitParam(name = "job", dataTypeClass = String.class, example = "학생"), + @ApiImplicitParam(name = "cityName", dataTypeClass = String.class, example = "SEOUL"), @ApiImplicitParam(name = "refreshToken", required = true, dataTypeClass = String.class, example = "reb5085c395164587b84ac583d023011f.0.sryrq.IDLsECw-rsTozfsX0Yz-CA") }) - @PatchMapping("/essential-profile") - public ApplicationResponse enterEssentialProfile(@ModelAttribute CreateUserEssentialProfileReq createUserEssentialProfileReq){ - return userService.enterEssentialProfile(createUserEssentialProfileReq); + @PatchMapping("/profile") + public ApplicationResponse enterProfile(@ModelAttribute CreateUserProfileReq createUserProfileReq){ + return userService.enterProfile(createUserProfileReq); } /** - * 유저 Profile 조회 + * 유저 프로필 조회 * @author 강신현 */ - @ApiOperation(value = "유저 Profile 조회") + @ApiOperation(value = "유저 프로필 조회") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "1"), @ApiImplicitParam(name = "refreshTokenUserId", required = true, dataTypeClass = Long.class, example = "21"), @@ -65,10 +70,10 @@ public ApplicationResponse getProfile(@ModelAttribute GetUserPro } /** - * 유저 Profile 삭제 + * 유저 프로필 삭제 * @author 강신현 */ - @ApiOperation(value = "유저 Profile 삭제") + @ApiOperation(value = "유저 프로필 삭제") @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0") @PatchMapping("/{userId}") public ApplicationResponse delProfile(@PathVariable Long userId){ @@ -106,25 +111,6 @@ public ApplicationResponse AddAndDeleteUserImage(@ModelAttribute return userService.AddAndDeleteUserImage(addAndDeleteUserImageReq); } - /** - * 유저 추가 정보 입력 및 수정 - * @author 강신현 - */ - @ApiOperation(value = "유저 추가 정보 입력 및 수정") - @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "1"), - @ApiImplicitParam(name = "latitude", dataTypeClass = Float.class, example = "10.23"), - @ApiImplicitParam(name = "longitude", dataTypeClass = Float.class, example = "10.23"), - @ApiImplicitParam(name = "aboutMe", dataTypeClass = String.class, example = "캠핑 모임에 관심이 많습니다."), - @ApiImplicitParam(name = "job", dataTypeClass = String.class, example = "학생"), - @ApiImplicitParam(name = "cityName", dataTypeClass = String.class, example = "SEOUL"), - @ApiImplicitParam(name = "refreshToken", required = true, dataTypeClass = String.class, example = "reb5085c395164587b84ac583d023011f.0.sryrq.IDLsECw-rsTozfsX0Yz-CA") - }) - @PatchMapping("/additional-profile") - public ApplicationResponse enterAdditionalProfile(@ModelAttribute AddUserAdditionalProfileReq addUserAdditionalProfileReq){ - return userService.enterAdditionalProfile(addUserAdditionalProfileReq); - } - /** * 유저 회원가입 (일반) * @author 강신현 diff --git a/server/src/main/java/com/yogit/server/user/dto/request/CreateUserProfileReq.java b/server/src/main/java/com/yogit/server/user/dto/request/CreateUserProfileReq.java new file mode 100644 index 0000000..e167c16 --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/dto/request/CreateUserProfileReq.java @@ -0,0 +1,32 @@ +package com.yogit.server.user.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class CreateUserProfileReq { + Long userId; + + String userName; + int userAge; + String gender; + String nationality; + + List languageNames; + List languageLevels; + + float latitude; + float longitude; + String aboutMe; + String job; + + String cityName; + List interests; + + String refreshToken; +} diff --git a/server/src/main/java/com/yogit/server/user/dto/response/UserProfileRes.java b/server/src/main/java/com/yogit/server/user/dto/response/UserProfileRes.java index e518c3e..9fd2dc0 100644 --- a/server/src/main/java/com/yogit/server/user/dto/response/UserProfileRes.java +++ b/server/src/main/java/com/yogit/server/user/dto/response/UserProfileRes.java @@ -31,16 +31,16 @@ public class UserProfileRes { String aboutMe; UserStatus userStatus; String phone; + String job; List languageNames = new ArrayList<>(); List languageLevels = new ArrayList<>(); // 유저 추가 정보 - String administrativeArea; float longtitude; float latitude; - CityName city; + String city; List interests = new ArrayList<>(); @@ -57,6 +57,7 @@ public static UserProfileRes create(User user){ userProfileRes.aboutMe = user.getAboutMe(); userProfileRes.userStatus = user.getUserStatus(); userProfileRes.phone = user.getPhoneNum(); + userProfileRes.job = user.getJob(); // 유저 추가 정보 if(user.getLongtitude() != null)userProfileRes.longtitude = user.getLongtitude(); @@ -65,10 +66,6 @@ public static UserProfileRes create(User user){ return userProfileRes; } - public void addCity(CityName city){ - this.city = city; - } - public void addLanguage(String languageName, String languageLevel){ this.languageNames.add(languageName); this.languageLevels.add(languageLevel); 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 c72ee63..22aa7de 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 @@ -8,7 +8,7 @@ public interface UserService { Void validateRefreshToken(Long userId, String refreshToken); - ApplicationResponse enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq); + ApplicationResponse enterProfile(CreateUserProfileReq createUserProfileReq); ApplicationResponse getProfile(GetUserProfileReq getUserProfileReq); @@ -18,8 +18,6 @@ public interface UserService { ApplicationResponse AddAndDeleteUserImage(AddAndDeleteUserImageReq addAndDeleteUserImageReq); - ApplicationResponse enterAdditionalProfile(AddUserAdditionalProfileReq addUserAdditionalProfileReq); - ApplicationResponse createUser(CreateUserReq createUserReq); User createUserApple(CreateUserAppleReq createUserAppleReq); 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 e523631..76b4dff 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 @@ -6,9 +6,15 @@ import com.yogit.server.global.dto.ApplicationResponse; import com.yogit.server.s3.AwsS3Service; import com.yogit.server.user.dto.request.*; -import com.yogit.server.user.dto.response.*; +import com.yogit.server.user.dto.response.LogoutRes; +import com.yogit.server.user.dto.response.UserDeviceTokenRes; +import com.yogit.server.user.dto.response.UserImagesRes; +import com.yogit.server.user.dto.response.UserProfileRes; import com.yogit.server.user.entity.*; -import com.yogit.server.user.exception.*; +import com.yogit.server.user.exception.NotFoundUserException; +import com.yogit.server.user.exception.NotFoundUserImageException; +import com.yogit.server.user.exception.UserDuplicationLoginId; +import com.yogit.server.user.exception.UserGenderException; import com.yogit.server.user.repository.*; import lombok.RequiredArgsConstructor; import net.minidev.json.JSONArray; @@ -56,36 +62,99 @@ public Void validateRefreshToken(Long userId, String refreshToken){ return null; } + // 국가 정보 조회 Open Api + JSONObject getNation(String nationality) { + + JSONObject nation = null; + try { + URL url = new URL("http://apis.data.go.kr/1262000/CountryFlagService2/getCountryFlagList2?ServiceKey=Os%2B%2Fa%2BWGJPptb5Rf1U850JQo11XO0fCA5cL3YND%2BxoxUm8B38IDZjHKlrpV0gj496%2Br53Rg61EdzI9KDuILDrg%3D%3D" + "&cond[country_iso_alp2::EQ]=" + nationality); + + BufferedReader bf; + bf = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")); + String result = bf.readLine(); + + JSONParser jsonParser = new JSONParser(); + JSONObject jsonObject = (JSONObject) jsonParser.parse(result); + JSONArray data = (JSONArray) jsonObject.get("data"); + nation = (JSONObject) data.get(0); + } catch (Exception e) { + e.printStackTrace(); + } + + return nation; + } + @Transactional @Override - public ApplicationResponse enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq){ + public ApplicationResponse enterProfile(CreateUserProfileReq createUserProfileReq){ - validateRefreshToken(createUserEssentialProfileReq.getUserId(), createUserEssentialProfileReq.getRefreshToken()); + validateRefreshToken(createUserProfileReq.getUserId(), createUserProfileReq.getRefreshToken()); - if(!createUserEssentialProfileReq.getGender().equals("Prefer not to say") && !createUserEssentialProfileReq.getGender().equals("Male") && !createUserEssentialProfileReq.getGender().equals("Female")) throw new UserGenderException(); + if(!createUserProfileReq.getGender().equals("Prefer not to say") && !createUserProfileReq.getGender().equals("Male") && !createUserProfileReq.getGender().equals("Female")) throw new UserGenderException(); - User user = userRepository.findByUserId(createUserEssentialProfileReq.getUserId()).orElseThrow(NotFoundUserException::new); - user.changeUserInfo(createUserEssentialProfileReq.getUserName(), createUserEssentialProfileReq.getUserAge(), createUserEssentialProfileReq.getGender(), createUserEssentialProfileReq.getNationality()); + User user = userRepository.findByUserId(createUserProfileReq.getUserId()).orElseThrow(NotFoundUserException::new); + user.changeUserInfo(createUserProfileReq.getUserName(), createUserProfileReq.getUserAge(), createUserProfileReq.getGender(), createUserProfileReq.getNationality()); - UserEssentialProfileRes userEssentialProfileRes = UserEssentialProfileRes.create(createUserEssentialProfileReq.getUserId(), createUserEssentialProfileReq.getUserName(), createUserEssentialProfileReq.getUserAge(), createUserEssentialProfileReq.getGender(), createUserEssentialProfileReq.getNationality()); + UserProfileRes userProfileRes = UserProfileRes.create(user); - if(createUserEssentialProfileReq.getLanguageNames() != null) { + if(createUserProfileReq.getLanguageNames() != null) { // 기존 languages 삭제 - languageRepository.deleteAllByUserId(createUserEssentialProfileReq.getUserId()); + languageRepository.deleteAllByUserId(createUserProfileReq.getUserId()); // 새로운 languages 추가 - for(int i=0;i < createUserEssentialProfileReq.getLanguageNames().size(); i++){ + for(int i=0;i < createUserProfileReq.getLanguageNames().size(); i++){ Language language = Language.builder() .user(user) - .name(createUserEssentialProfileReq.getLanguageNames().get(i)) - .level(createUserEssentialProfileReq.getLanguageLevels().get(i)) + .name(createUserProfileReq.getLanguageNames().get(i)) + .level(createUserProfileReq.getLanguageLevels().get(i)) .build(); languageRepository.save(language); - userEssentialProfileRes.addLanguage(createUserEssentialProfileReq.getLanguageNames().get(i), createUserEssentialProfileReq.getLanguageLevels().get(i)); + userProfileRes.addLanguage(createUserProfileReq.getLanguageNames().get(i), createUserProfileReq.getLanguageLevels().get(i)); } } - return ApplicationResponse.ok(userEssentialProfileRes); + user.addAdditionalProfile(createUserProfileReq.getLatitude(), createUserProfileReq.getLongitude(), createUserProfileReq.getAboutMe(), createUserProfileReq.getJob()); + + // 기존에 존재하는 city인 경우 + if(cityRepository.existsByCityName(createUserProfileReq.getCityName())){ + City city = cityRepository.findByCityName(createUserProfileReq.getCityName()); + city.addUser(user); + } + else{ // 기존에 존재하지 않는 city인 경우 + City city = City.builder() + .user(user) + .cityName(createUserProfileReq.getCityName()) + .build(); + cityRepository.save(city); + city.addUser(user); + } + + userProfileRes.setCity(createUserProfileReq.getCityName()); + + for(String interestName : createUserProfileReq.getInterests()){ + Interest interest = Interest.builder() + .name(interestName) + .build(); + interestRepository.save(interest); + + UserInterest userInterest = UserInterest.builder() + .user(user) + .interest(interest) + .build(); + userInterestRepository.save(userInterest); + + userProfileRes.getInterests().add(interestName); + } + + // 국가 이름 및 국기 이미지 조회 + JSONObject nation = getNation(user.getNationality()); + String country_eng_nm = nation.get("country_eng_nm").toString(); + String download_url = nation.get("download_url").toString(); + + userProfileRes.setCountry_eng_nm(country_eng_nm); + userProfileRes.setDownload_url(download_url); + + return ApplicationResponse.ok(userProfileRes); } @Override @@ -121,33 +190,12 @@ public ApplicationResponse getProfile(GetUserProfileReq getUserP userProfileRes.addImage(awsS3Service.makeUrlOfFilename(userImage.getImgUUid())); } - try { - - URL url = new URL("http://apis.data.go.kr/1262000/CountryFlagService2/getCountryFlagList2?ServiceKey=Os%2B%2Fa%2BWGJPptb5Rf1U850JQo11XO0fCA5cL3YND%2BxoxUm8B38IDZjHKlrpV0gj496%2Br53Rg61EdzI9KDuILDrg%3D%3D" + "&cond[country_iso_alp2::EQ]=" + user.getNationality()); + JSONObject nation = getNation(user.getNationality()); + String country_eng_nm = nation.get("country_eng_nm").toString(); + String download_url = nation.get("download_url").toString(); - BufferedReader bf; - - bf = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")); - - String result = bf.readLine(); - - JSONParser jsonParser = new JSONParser(); - JSONObject jsonObject = (JSONObject) jsonParser.parse(result); - - JSONArray data = (JSONArray) jsonObject.get("data"); - - - JSONObject nation = (JSONObject) data.get(0); - - String country_eng_nm = nation.get("country_eng_nm").toString(); - String download_url = nation.get("download_url").toString(); - - userProfileRes.setCountry_eng_nm(country_eng_nm); - userProfileRes.setDownload_url(download_url); - - } catch (Exception e) { - e.printStackTrace(); - } + userProfileRes.setCountry_eng_nm(country_eng_nm); + userProfileRes.setDownload_url(download_url); return ApplicationResponse.ok(userProfileRes); } @@ -249,53 +297,6 @@ public Void deleteUserImage(List deleteUserImageIds){ return null; } - - @Override - @Transactional - public ApplicationResponse enterAdditionalProfile(AddUserAdditionalProfileReq addUserAdditionalProfileReq){ - - validateRefreshToken(addUserAdditionalProfileReq.getUserId(), addUserAdditionalProfileReq.getRefreshToken()); - - User user = userRepository.findByUserId(addUserAdditionalProfileReq.getUserId()).orElseThrow(NotFoundUserException::new); - - user.addAdditionalProfile(addUserAdditionalProfileReq.getLatitude(), addUserAdditionalProfileReq.getLongitude(), addUserAdditionalProfileReq.getAboutMe(), addUserAdditionalProfileReq.getJob()); - - UserAdditionalProfileRes userAdditionalProfileRes = UserAdditionalProfileRes.create(user); - - // 기존에 존재하는 city인 경우 - if(cityRepository.existsByCityName(addUserAdditionalProfileReq.getCityName())){ - City city = cityRepository.findByCityName(addUserAdditionalProfileReq.getCityName()); - city.addUser(user); - } - else{ // 기존에 존재하지 않는 city인 경우 - City city = City.builder() - .user(user) - .cityName(addUserAdditionalProfileReq.getCityName()) - .build(); - cityRepository.save(city); - city.addUser(user); - } - - userAdditionalProfileRes.setCityName(addUserAdditionalProfileReq.getCityName()); - - for(String interestName : addUserAdditionalProfileReq.getInterests()){ - Interest interest = Interest.builder() - .name(interestName) - .build(); - interestRepository.save(interest); - - UserInterest userInterest = UserInterest.builder() - .user(user) - .interest(interest) - .build(); - userInterestRepository.save(userInterest); - - userAdditionalProfileRes.getInterests().add(interestName); - } - - return ApplicationResponse.ok(userAdditionalProfileRes); - } - @Override @Transactional public ApplicationResponse createUser(CreateUserReq createUserReq){