diff --git a/server/build.gradle b/server/build.gradle index 3bd2fb2..915df2e 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -35,6 +35,8 @@ dependencies { // S3 implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + // JWT + implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' } tasks.named('test') { diff --git a/server/src/main/java/com/yogit/server/config/SwaggerConfig.java b/server/src/main/java/com/yogit/server/config/SwaggerConfig.java index 23ca3c2..9e7538b 100644 --- a/server/src/main/java/com/yogit/server/config/SwaggerConfig.java +++ b/server/src/main/java/com/yogit/server/config/SwaggerConfig.java @@ -1,20 +1,13 @@ package com.yogit.server.config; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; -import java.util.Arrays; -import java.util.List; - @Configuration @EnableSwagger2// 기능을 활성화하는 어노테이션입니다. SwaggerConfig.java 가 아니라 어플리케이션에 추가해도 동작합니다. public class SwaggerConfig { diff --git a/server/src/main/java/com/yogit/server/sms/service/SmsService.java b/server/src/main/java/com/yogit/server/sms/service/SmsService.java index c105b0a..9ed4928 100644 --- a/server/src/main/java/com/yogit/server/sms/service/SmsService.java +++ b/server/src/main/java/com/yogit/server/sms/service/SmsService.java @@ -40,7 +40,7 @@ public class SmsService { private String secretKey; @Value("01046270562") - private String phoneNum; + private String phoneNum; // TODO 위 3가지 변수와 다르게 @Value(application.yml)값이 다른 값으로 불러와지는 문제가 있음, 일단 값을 yml에서 가져오지 않고 바로 넣어주는 식으로 임시 해결 public String send(SmsSendReq smsSendReq) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException, JsonProcessingException, URISyntaxException { // if(smsSendReq.getPhoneNum().contains("-")) return "-을 제거해주세요."; @@ -48,11 +48,11 @@ public String send(SmsSendReq smsSendReq) throws UnsupportedEncodingException, N System.out.println(serviceId); System.out.println(accessKey); System.out.println(secretKey); - System.out.println(phoneNum); // TODO 위 3가지 변수와 다르게 @Value(application.yml)값이 다른 값으로 불러와지는 문제가 있음, 일단 값을 yml에서 가져오지 않고 바로 넣어주는 식으로 임시 해결 + System.out.println(phoneNum); String certification = Integer.toString((int)(Math.random() * (99999 - 10000 + 1)) + 10000); - Long time = System.currentTimeMillis(); + Long time = System.currentTimeMillis(); List messages = new ArrayList<>(); messages.add(new MessageDTO(smsSendReq.getPhoneNum(), "Yogit \n 인증번호: "+certification)); 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 645a165..116219f 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 @@ -4,11 +4,12 @@ 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.EditUserEssentialProfileReq; +import com.yogit.server.user.dto.request.CreateUserReq; import com.yogit.server.user.dto.response.UserAdditionalProfileRes; +import com.yogit.server.user.dto.response.UserEssentialProfileRes; 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.entity.Gender; +import com.yogit.server.user.entity.Nationality; import com.yogit.server.user.service.UserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -33,13 +34,12 @@ public class UserController { @ApiImplicitParams({ @ApiImplicitParam(name = "userName", required = true, dataTypeClass = String.class), @ApiImplicitParam(name = "userAge", required = true, dataTypeClass = int.class, example = "0"), + @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0"), @ApiImplicitParam(name = "gender", required = true, dataTypeClass = Gender.class), - @ApiImplicitParam(name = "nationality", required = true, dataTypeClass = Nationality.class), - @ApiImplicitParam(name = "languageName1", required = true, dataTypeClass = LanguageName.class), - @ApiImplicitParam(name = "languageLevel1", required = true, dataTypeClass = LanguageLevel.class) + @ApiImplicitParam(name = "nationality", required = true, dataTypeClass = Nationality.class) }) - @PostMapping("/essential-profile") - public ApplicationResponse enterEssentialProfile(@ModelAttribute CreateUserEssentialProfileReq createUserEssentialProfileReq){ + @PatchMapping("/essential-profile") + public ApplicationResponse enterEssentialProfile(@ModelAttribute CreateUserEssentialProfileReq createUserEssentialProfileReq){ return userService.enterEssentialProfile(createUserEssentialProfileReq); } @@ -47,23 +47,23 @@ public ApplicationResponse enterEssentialProfile(@ModelAttribute * 유저 필수 정보 수정 * @author 강신현 */ - @ApiOperation(value = "유저 필수 정보 수정", notes = "수정할 정보들만 입력해주세요, Language 중에 하나라도 변경사항이 있다면 유저의 모든 Language 를 입력하여 요청해주세요") - @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0") - @PatchMapping("/essential-profile") - public ApplicationResponse editEssentialProfile(@ModelAttribute EditUserEssentialProfileReq editUserEssentialProfileReq){ - return userService.editEssentialProfile(editUserEssentialProfileReq); - } +// @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 강신현 */ - @ApiOperation(value = "유저 Profile 조회") - @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0") - @GetMapping("/prifile/{userId}") - public ApplicationResponse getProfile(@PathVariable Long userId){ - return userService.getProfile(userId); - } +// @ApiOperation(value = "유저 Profile 조회") +// @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0") +// @GetMapping("/prifile/{userId}") +// public ApplicationResponse getProfile(@PathVariable Long userId){ +// return userService.getProfile(userId); +// } /** * 유저 Profile 삭제 @@ -97,4 +97,19 @@ public ApplicationResponse enterUserImage(@ModelAttribute CreateU public ApplicationResponse enterAdditionalProfile(@ModelAttribute AddUserAdditionalProfileReq addUserAdditionalProfileReq){ return userService.enterAdditionalProfile(addUserAdditionalProfileReq); } + + /** + * 유저 회원가입 (일반) + */ + @ApiOperation(value = "유저 회원가입", notes = "sms 인증이 완료되어야 회원가입이 가능합니다.") + @ApiImplicitParam(name = "loginId", required = true, dataTypeClass = String.class) + @PostMapping("/join") + public ApplicationResponse createUser(@ModelAttribute CreateUserReq createUserReq){ + return userService.createUser(createUserReq); + } + + + /** + * 유저 로그인 + */ } diff --git a/server/src/main/java/com/yogit/server/user/dto/request/CreateUserEssentialProfileReq.java b/server/src/main/java/com/yogit/server/user/dto/request/CreateUserEssentialProfileReq.java index bb9f990..6a7319e 100644 --- a/server/src/main/java/com/yogit/server/user/dto/request/CreateUserEssentialProfileReq.java +++ b/server/src/main/java/com/yogit/server/user/dto/request/CreateUserEssentialProfileReq.java @@ -1,41 +1,25 @@ package com.yogit.server.user.dto.request; -import com.yogit.server.user.entity.*; +import com.yogit.server.user.entity.Gender; +import com.yogit.server.user.entity.Nationality; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; + @NoArgsConstructor @AllArgsConstructor @Data public class CreateUserEssentialProfileReq { + Long userId; + String userName; int userAge; Gender gender; Nationality nationality; - LanguageName languageName1; - LanguageLevel languageLevel1; - - LanguageName languageName2; - LanguageLevel languageLevel2; - - LanguageName languageName3; - LanguageLevel languageLevel3; - - LanguageName languageName4; - LanguageLevel languageLevel4; - - LanguageName languageName5; - LanguageLevel languageLevel5; - - public static User toEntityUser(CreateUserEssentialProfileReq createUserEssentialProfileReq){ - return User.builder() - .name(createUserEssentialProfileReq.getUserName()) - .age(createUserEssentialProfileReq.getUserAge()) - .gender(createUserEssentialProfileReq.getGender()) - .nationality(createUserEssentialProfileReq.getNationality()) - .build(); - } + List languageNames; + List languageLevels; } diff --git a/server/src/main/java/com/yogit/server/user/dto/request/CreateUserReq.java b/server/src/main/java/com/yogit/server/user/dto/request/CreateUserReq.java new file mode 100644 index 0000000..853c756 --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/dto/request/CreateUserReq.java @@ -0,0 +1,20 @@ +package com.yogit.server.user.dto.request; + +import com.yogit.server.user.entity.User; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class CreateUserReq { + + String loginId; + + public static User toEntityUser(CreateUserReq createUserReq){ + return User.builder() + .loginId(createUserReq.getLoginId()) + .build(); + } +} 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 23762a9..f2d3de9 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 @@ -17,18 +17,18 @@ 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; +// LanguageName languageName1; +// LanguageLevel languageLevel1; +// +// LanguageName languageName2; +// LanguageLevel languageLevel2; +// +// LanguageName languageName3; +// LanguageLevel languageLevel3; +// +// LanguageName languageName4; +// LanguageLevel languageLevel4; +// +// LanguageName languageName5; +// LanguageLevel languageLevel5; } 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 new file mode 100644 index 0000000..80434d1 --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/dto/response/UserEssentialProfileRes.java @@ -0,0 +1,44 @@ +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; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class UserEssentialProfileRes { + + Long userId; + + String userName; + Integer userAge; + Gender gender; + Nationality nationality; + + List languageNames = new ArrayList<>(); + List languageLevels = new ArrayList<>(); + + public static UserEssentialProfileRes create(CreateUserEssentialProfileReq createUserEssentialProfileReq){ + UserEssentialProfileRes userEssentialProfileRes = new UserEssentialProfileRes(); + + userEssentialProfileRes.userId = createUserEssentialProfileReq.getUserId(); + userEssentialProfileRes.userName = createUserEssentialProfileReq.getUserName(); + userEssentialProfileRes.userAge = createUserEssentialProfileReq.getUserAge(); + userEssentialProfileRes.gender = createUserEssentialProfileReq.getGender(); + userEssentialProfileRes.nationality = createUserEssentialProfileReq.getNationality(); + + return userEssentialProfileRes; + } + + 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/dto/response/UserProfileRes.java b/server/src/main/java/com/yogit/server/user/dto/response/UserProfileRes.java index 0932caa..6fa7c58 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 @@ -1,6 +1,8 @@ package com.yogit.server.user.dto.response; -import com.yogit.server.user.entity.*; +import com.yogit.server.user.entity.Gender; +import com.yogit.server.user.entity.Nationality; +import com.yogit.server.user.entity.User; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -23,21 +25,6 @@ public class UserProfileRes { // String login_id; //TODO // String pass_word; //TODO - LanguageName languageName1; - LanguageLevel languageLevel1; - - LanguageName languageName2; - LanguageLevel languageLevel2; - - LanguageName languageName3; - LanguageLevel languageLevel3; - - LanguageName languageName4; - LanguageLevel languageLevel4; - - LanguageName languageName5; - LanguageLevel languageLevel5; - public static UserProfileRes create(User user){ UserProfileRes userProfileRes = new UserProfileRes(); @@ -52,27 +39,4 @@ public static UserProfileRes create(User user){ return userProfileRes; } - - public void addLanguage(Language language){ - if(this.languageName1 == null){ - this.languageName1 = language.getName(); - this.languageLevel1 = language.getLevel(); - } - else if(this.languageName2 == null){ - this.languageName2 = language.getName(); - this.languageLevel2 = language.getLevel(); - } - else if(this.languageName3 == null){ - this.languageName3 = language.getName(); - this.languageLevel3 = language.getLevel(); - } - else if(this.languageName4 == null){ - this.languageName4 = language.getName(); - this.languageLevel4 = language.getLevel(); - } - else{ - this.languageName5 = language.getName(); - this.languageLevel5 = language.getLevel(); - } - } } diff --git a/server/src/main/java/com/yogit/server/user/entity/City.java b/server/src/main/java/com/yogit/server/user/entity/City.java index 8c4bf20..ad5bcc7 100644 --- a/server/src/main/java/com/yogit/server/user/entity/City.java +++ b/server/src/main/java/com/yogit/server/user/entity/City.java @@ -17,7 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class City extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "city_id") private Long id; diff --git a/server/src/main/java/com/yogit/server/user/entity/CountryCode.java b/server/src/main/java/com/yogit/server/user/entity/CountryCode.java index 18dbe9d..9111601 100644 --- a/server/src/main/java/com/yogit/server/user/entity/CountryCode.java +++ b/server/src/main/java/com/yogit/server/user/entity/CountryCode.java @@ -12,7 +12,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class CountryCode extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "country_code_id") private Long id; diff --git a/server/src/main/java/com/yogit/server/user/entity/Interest.java b/server/src/main/java/com/yogit/server/user/entity/Interest.java index 4ddb9a2..2ec88c6 100644 --- a/server/src/main/java/com/yogit/server/user/entity/Interest.java +++ b/server/src/main/java/com/yogit/server/user/entity/Interest.java @@ -15,7 +15,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Interest extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "interest_id") private Long id; diff --git a/server/src/main/java/com/yogit/server/user/entity/Language.java b/server/src/main/java/com/yogit/server/user/entity/Language.java index 3f9fec0..96fa2cf 100644 --- a/server/src/main/java/com/yogit/server/user/entity/Language.java +++ b/server/src/main/java/com/yogit/server/user/entity/Language.java @@ -10,21 +10,19 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Language extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "language_id") private Long id; @ManyToOne(fetch = FetchType.LAZY) private User user; - @Enumerated(EnumType.STRING) - private LanguageName name; + private String name; - @Enumerated(EnumType.STRING) - private LanguageLevel level; + private String level; @Builder - public Language (User user, LanguageName name, LanguageLevel level){ + public Language (User user, String name, String level){ this.name = name; this.level = level; diff --git a/server/src/main/java/com/yogit/server/user/entity/LanguageLevel.java b/server/src/main/java/com/yogit/server/user/entity/LanguageLevel.java deleted file mode 100644 index 92d3559..0000000 --- a/server/src/main/java/com/yogit/server/user/entity/LanguageLevel.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.yogit.server.user.entity; - -public enum LanguageLevel { - Beginner, - Elementary, - Intermediate, - Fluent, - Native, -} diff --git a/server/src/main/java/com/yogit/server/user/entity/LanguageName.java b/server/src/main/java/com/yogit/server/user/entity/LanguageName.java deleted file mode 100644 index 3bd8d1d..0000000 --- a/server/src/main/java/com/yogit/server/user/entity/LanguageName.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.yogit.server.user.entity; - -import io.swagger.annotations.ApiModel; - -public enum LanguageName { - Korean, - English, - Japanese, - Chinese -} diff --git a/server/src/main/java/com/yogit/server/user/entity/User.java b/server/src/main/java/com/yogit/server/user/entity/User.java index 932e1b8..75a9f05 100644 --- a/server/src/main/java/com/yogit/server/user/entity/User.java +++ b/server/src/main/java/com/yogit/server/user/entity/User.java @@ -1,12 +1,16 @@ package com.yogit.server.user.entity; -import com.yogit.server.board.entity.*; +import com.yogit.server.board.entity.BoardUser; +import com.yogit.server.board.entity.BookMark; +import com.yogit.server.board.entity.ClipBoard; +import com.yogit.server.board.entity.Comment; import com.yogit.server.config.domain.BaseEntity; -import com.yogit.server.user.dto.request.EditUserEssentialProfileReq; -import lombok.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.persistence.*; - import java.util.ArrayList; import java.util.List; @@ -16,7 +20,7 @@ public class User extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "user_id") private Long id; @@ -33,10 +37,9 @@ public class User extends BaseEntity { @OneToMany(mappedBy = "user") private List languages = new ArrayList<>(); - private String loginId; // TODO 애플 로그인 성공시, 구현 - private String passWord; // TODO 애플 로그인 성공시, 구현 + private String loginId; private String name; - private String profileImg; // 프로필 대표 이미지 TODO image 연동 되면, 구현 + private String profileImg; private String aboutMe; // 300자 이내 @@ -71,24 +74,19 @@ public class User extends BaseEntity { private List userImages = new ArrayList<>(); @Builder - public User (String name, int age, Gender gender, Nationality nationality){ - this.name = name; - this.age = age; - this.memberTemp = 0; - this.gender = gender; - this.nationality = nationality; - this.userStatus = UserStatus.ACTIVE; + public User (String loginId){ + this.loginId = loginId; } public void addLanguage(Language language){ this.languages.add(language); } - public void changeUserInfo(EditUserEssentialProfileReq editUserEssentialProfileReq){ - if(editUserEssentialProfileReq.getUserName() != null) this.name = editUserEssentialProfileReq.getUserName(); - if(editUserEssentialProfileReq.getUserAge() != null) this.age = editUserEssentialProfileReq.getUserAge(); - if(editUserEssentialProfileReq.getGender() != null) this.gender = editUserEssentialProfileReq.getGender(); - if(editUserEssentialProfileReq.getNationality() != null) this.nationality = editUserEssentialProfileReq.getNationality(); + public void changeUserInfo(String userName, Integer userAge, Gender gender, Nationality nationality){ + if(userName != null) this.name = userName; + if(userAge != 0) this.age = userAge; + if(gender != null) this.gender = gender; + if(nationality != null) this.nationality = nationality; } public void delUser(){ diff --git a/server/src/main/java/com/yogit/server/user/entity/UserImage.java b/server/src/main/java/com/yogit/server/user/entity/UserImage.java index bd15702..2b94e62 100644 --- a/server/src/main/java/com/yogit/server/user/entity/UserImage.java +++ b/server/src/main/java/com/yogit/server/user/entity/UserImage.java @@ -13,7 +13,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class UserImage extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "user_image_id") private Long id; diff --git a/server/src/main/java/com/yogit/server/user/entity/UserInterest.java b/server/src/main/java/com/yogit/server/user/entity/UserInterest.java index 28061a2..2392aa6 100644 --- a/server/src/main/java/com/yogit/server/user/entity/UserInterest.java +++ b/server/src/main/java/com/yogit/server/user/entity/UserInterest.java @@ -13,7 +13,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class UserInterest extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "user_interest_id") private Long id; diff --git a/server/src/main/java/com/yogit/server/user/exception/UserDuplicationLoginId.java b/server/src/main/java/com/yogit/server/user/exception/UserDuplicationLoginId.java new file mode 100644 index 0000000..a7f2efe --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/exception/UserDuplicationLoginId.java @@ -0,0 +1,9 @@ +package com.yogit.server.user.exception; + +import static com.yogit.server.user.exception.UserExceptionList.DUPLICATE_LOGIN_ID; + +public class UserDuplicationLoginId extends UserException { + public UserDuplicationLoginId() { + super(DUPLICATE_LOGIN_ID.getCODE(), DUPLICATE_LOGIN_ID.getHTTPSTATUS(), DUPLICATE_LOGIN_ID.getMESSAGE()); + } +} diff --git a/server/src/main/java/com/yogit/server/user/exception/UserExceptionList.java b/server/src/main/java/com/yogit/server/user/exception/UserExceptionList.java index c2acfb0..f17b24f 100644 --- a/server/src/main/java/com/yogit/server/user/exception/UserExceptionList.java +++ b/server/src/main/java/com/yogit/server/user/exception/UserExceptionList.java @@ -11,7 +11,8 @@ @RequiredArgsConstructor public enum UserExceptionList { - NOT_FOUND_ID("U0001", NOT_FOUND,"존재하지 않는 아이디입니다."); + NOT_FOUND_ID("U0001", NOT_FOUND,"존재하지 않는 아이디입니다."), + DUPLICATE_LOGIN_ID("U0002", CONFLICT,"이미 존재하는 아이디입니다."); private final String CODE; private final HttpStatus HTTPSTATUS; diff --git a/server/src/main/java/com/yogit/server/user/repository/UserRepository.java b/server/src/main/java/com/yogit/server/user/repository/UserRepository.java index da70705..f0bcd93 100644 --- a/server/src/main/java/com/yogit/server/user/repository/UserRepository.java +++ b/server/src/main/java/com/yogit/server/user/repository/UserRepository.java @@ -4,4 +4,5 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface UserRepository extends JpaRepository { + boolean existsByLoginId(String loginId); } 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 d5f3cc6..35229b2 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 @@ -4,21 +4,23 @@ 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.EditUserEssentialProfileReq; +import com.yogit.server.user.dto.request.CreateUserReq; import com.yogit.server.user.dto.response.UserAdditionalProfileRes; +import com.yogit.server.user.dto.response.UserEssentialProfileRes; import com.yogit.server.user.dto.response.UserImagesRes; -import com.yogit.server.user.dto.response.UserProfileRes; public interface UserService { - ApplicationResponse enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq); + ApplicationResponse enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq); - ApplicationResponse editEssentialProfile(EditUserEssentialProfileReq editUserEssentialProfileReq); + //ApplicationResponse editEssentialProfile(EditUserEssentialProfileReq editUserEssentialProfileReq); - ApplicationResponse getProfile(Long userId); + //ApplicationResponse getProfile(Long userId); ApplicationResponse delProfile(Long userId); ApplicationResponse enterUserImage(CreateUserImageReq createUserImageReq); ApplicationResponse enterAdditionalProfile(AddUserAdditionalProfileReq addUserAdditionalProfileReq); + + ApplicationResponse createUser(CreateUserReq createUserReq); } 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 91d8dbd..a6657f0 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 @@ -5,12 +5,13 @@ 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.EditUserEssentialProfileReq; +import com.yogit.server.user.dto.request.CreateUserReq; import com.yogit.server.user.dto.response.UserAdditionalProfileRes; +import com.yogit.server.user.dto.response.UserEssentialProfileRes; 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.NotFoundUserException; +import com.yogit.server.user.exception.UserDuplicationLoginId; import com.yogit.server.user.repository.*; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -33,149 +34,110 @@ public class UserServiceImpl implements UserService { @Transactional @Override - public ApplicationResponse enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq){ + public ApplicationResponse enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq){ - User user = userRepository.save(createUserEssentialProfileReq.toEntityUser(createUserEssentialProfileReq)); + User user = userRepository.findById(createUserEssentialProfileReq.getUserId()).orElseThrow(); + user.changeUserInfo(createUserEssentialProfileReq.getUserName(), createUserEssentialProfileReq.getUserAge(), createUserEssentialProfileReq.getGender(), createUserEssentialProfileReq.getNationality()); - UserProfileRes userProfileRes = UserProfileRes.create(user); + UserEssentialProfileRes userEssentialProfileRes = UserEssentialProfileRes.create(createUserEssentialProfileReq); - // language 추가 - if(createUserEssentialProfileReq.getLanguageName1() != null && createUserEssentialProfileReq.getLanguageLevel1() != null){ + for(int i=0;i < createUserEssentialProfileReq.getLanguageNames().size(); i++){ Language language = Language.builder() .user(user) - .name(createUserEssentialProfileReq.getLanguageName1()) - .level(createUserEssentialProfileReq.getLanguageLevel1()) + .name(createUserEssentialProfileReq.getLanguageNames().get(i)) + .level(createUserEssentialProfileReq.getLanguageLevels().get(i)) .build(); languageRepository.save(language); - userProfileRes.addLanguage(language); - } - - if(createUserEssentialProfileReq.getLanguageName2() != null && createUserEssentialProfileReq.getLanguageLevel2() != null){ - Language language = Language.builder() - .user(user) - .name(createUserEssentialProfileReq.getLanguageName2()) - .level(createUserEssentialProfileReq.getLanguageLevel2()) - .build(); - languageRepository.save(language); - userProfileRes.addLanguage(language); - } - - if(createUserEssentialProfileReq.getLanguageName3() != null && createUserEssentialProfileReq.getLanguageLevel3() != null){ - Language language = Language.builder() - .user(user) - .name(createUserEssentialProfileReq.getLanguageName3()) - .level(createUserEssentialProfileReq.getLanguageLevel3()) - .build(); - languageRepository.save(language); - userProfileRes.addLanguage(language); - } - if(createUserEssentialProfileReq.getLanguageName4() != null && createUserEssentialProfileReq.getLanguageLevel4() != null){ - Language language = Language.builder() - .user(user) - .name(createUserEssentialProfileReq.getLanguageName4()) - .level(createUserEssentialProfileReq.getLanguageLevel4()) - .build(); - languageRepository.save(language); - userProfileRes.addLanguage(language); + userEssentialProfileRes.addLanguage(createUserEssentialProfileReq.getLanguageNames().get(i), createUserEssentialProfileReq.getLanguageLevels().get(i)); } - if(createUserEssentialProfileReq.getLanguageName5() != null && createUserEssentialProfileReq.getLanguageLevel5() != null){ - Language language = Language.builder() - .user(user) - .name(createUserEssentialProfileReq.getLanguageName5()) - .level(createUserEssentialProfileReq.getLanguageLevel5()) - .build(); - languageRepository.save(language); - userProfileRes.addLanguage(language); - } - - return ApplicationResponse.create("created", userProfileRes); + return ApplicationResponse.create("created", 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){ - User user = userRepository.findById(userId).orElseThrow(NotFoundUserException::new); - - UserProfileRes userProfileRes = UserProfileRes.create(user); - - List languages = languageRepository.findAllByUserId(userId); - if(!languages.isEmpty()){ - for(Language l : languages){ - userProfileRes.addLanguage(l); - } - } - - return ApplicationResponse.ok(userProfileRes); - } +// @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){ +// User user = userRepository.findById(userId).orElseThrow(NotFoundUserException::new); +// +// UserProfileRes userProfileRes = UserProfileRes.create(user); +// +// List languages = languageRepository.findAllByUserId(userId); +// if(!languages.isEmpty()){ +// for(Language l : languages){ +// userProfileRes.addLanguage(l); +// } +// } +// +// return ApplicationResponse.ok(userProfileRes); +// } @Override @Transactional @@ -248,9 +210,17 @@ public ApplicationResponse enterAdditionalProfile(AddU userAdditionalProfileRes.getInterests().add(interestName); } + return ApplicationResponse.ok(userAdditionalProfileRes); + } + + @Override + @Transactional + public ApplicationResponse createUser(CreateUserReq createUserReq){ + if(userRepository.existsByLoginId(createUserReq.getLoginId())) throw new UserDuplicationLoginId(); + userRepository.save(CreateUserReq.toEntityUser(createUserReq)); - return ApplicationResponse.ok(userAdditionalProfileRes); + return ApplicationResponse.ok(); } }