From eaccd31bdbcb637510bf10cc0350743355d479db Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 13 Sep 2023 01:02:16 +0900 Subject: [PATCH 1/7] [feat] #17 security witheList --- .../hdmedi_server/global/config/auth/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/kusithm/hdmedi_server/global/config/auth/SecurityConfig.java b/src/main/java/com/kusithm/hdmedi_server/global/config/auth/SecurityConfig.java index f711258..c7b27a4 100644 --- a/src/main/java/com/kusithm/hdmedi_server/global/config/auth/SecurityConfig.java +++ b/src/main/java/com/kusithm/hdmedi_server/global/config/auth/SecurityConfig.java @@ -20,7 +20,7 @@ public class SecurityConfig { private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; private final JwtProvider jwtProvider; // TODO api 추가될 때 white list url 확인해서 추가하기. - private static final String[] whiteList = {"/api/user/signin", "/api/user/signup", "/api/user/reissue", "/"}; + private static final String[] whiteList = {"/api/user/signIn", "/api/user/signUp", "/api/user/reissue", "/"}; @Bean public WebSecurityCustomizer webSecurityCustomizer() { From 5d6281894c366d38695ad564f77d45b119dbd21b Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 13 Sep 2023 01:26:44 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[feat]=20#17=20=EC=A4=91=EB=B3=B5=EB=90=9C?= =?UTF-8?q?=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kusithm/hdmedi_server/global/error/exception/ErrorCode.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/kusithm/hdmedi_server/global/error/exception/ErrorCode.java b/src/main/java/com/kusithm/hdmedi_server/global/error/exception/ErrorCode.java index 86df1ef..e1178a9 100644 --- a/src/main/java/com/kusithm/hdmedi_server/global/error/exception/ErrorCode.java +++ b/src/main/java/com/kusithm/hdmedi_server/global/error/exception/ErrorCode.java @@ -48,6 +48,7 @@ public enum ErrorCode { * 409 Conflict */ CONFLICT(HttpStatus.CONFLICT, "이미 존재하는 리소스입니다."), + DUPLICATE_USER(HttpStatus.CONFLICT, "이미 존재하는 회원입니다."), /** * 500 Internal Server Error From 0a482e3da410055f1ca93d8ca90f8bba99feaaa3 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 13 Sep 2023 01:28:36 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[feat]=20#17=20user=EC=9D=98=20=EC=84=B1?= =?UTF-8?q?=EB=B3=84=20column=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kusithm/hdmedi_server/domain/user/domain/Gender.java | 6 ++++++ .../com/kusithm/hdmedi_server/domain/user/domain/User.java | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/user/domain/Gender.java diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/Gender.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/Gender.java new file mode 100644 index 0000000..3b77229 --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/Gender.java @@ -0,0 +1,6 @@ +package com.kusithm.hdmedi_server.domain.user.domain; + +public enum Gender { + NAN, + WOMAN; +} diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/User.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/User.java index b528b97..0f0d967 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/User.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/User.java @@ -18,6 +18,8 @@ public class User { private Platform platform; private String platformId; private String userName; + @Enumerated(value = EnumType.STRING) + private Gender gender; public static User createUser(Platform platform, String platformId, String userName){ return User.builder() From 73a87a8e0b3abf41d1dfe4852109f6a8bd926b52 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 13 Sep 2023 01:28:52 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[feat]=20#17=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20controller=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/controller/AuthController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/controller/AuthController.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/controller/AuthController.java index 1b42d0c..434a4a3 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/user/controller/AuthController.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/controller/AuthController.java @@ -1,6 +1,7 @@ package com.kusithm.hdmedi_server.domain.user.controller; import com.kusithm.hdmedi_server.domain.user.dto.request.UserAuthRequestDto; +import com.kusithm.hdmedi_server.domain.user.dto.request.UserSignUpRequestDto; import com.kusithm.hdmedi_server.domain.user.dto.response.UserAuthResponseDto; import com.kusithm.hdmedi_server.domain.user.service.AuthService; import com.kusithm.hdmedi_server.global.common.BaseResponse; @@ -27,4 +28,12 @@ public ResponseEntity> signIn(@RequestHeader("Authorization") fi return ResponseEntity.status(HttpStatus.OK) .body(BaseResponse.of(SuccessCode.OK, responseDto)); } + + @PostMapping("/signUp") + public ResponseEntity> signUp(@RequestHeader("Authorization") final String token, + @RequestBody final UserSignUpRequestDto userSignUpRequestDto){ + final UserAuthResponseDto responseDto = authService.signUp(token, userSignUpRequestDto); + return ResponseEntity.status(HttpStatus.OK) + .body(BaseResponse.of(SuccessCode.OK, responseDto)); + } } From 0661053a4d157c23ecbdf19e7f24e6d8c0b0c1d1 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 13 Sep 2023 01:29:05 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[feat]=20#17=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20service=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/AuthService.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/service/AuthService.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/service/AuthService.java index 58b6f31..55a669c 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/user/service/AuthService.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/service/AuthService.java @@ -4,19 +4,20 @@ import com.kusithm.hdmedi_server.domain.user.domain.Platform; import com.kusithm.hdmedi_server.domain.user.domain.User; import com.kusithm.hdmedi_server.domain.user.dto.request.UserAuthRequestDto; +import com.kusithm.hdmedi_server.domain.user.dto.request.UserSignUpRequestDto; import com.kusithm.hdmedi_server.domain.user.dto.response.UserAuthResponseDto; import com.kusithm.hdmedi_server.domain.user.repository.RefreshTokenRepository; import com.kusithm.hdmedi_server.domain.user.repository.UserRepository; import com.kusithm.hdmedi_server.global.config.jwt.JwtProvider; import com.kusithm.hdmedi_server.global.config.jwt.Token; +import com.kusithm.hdmedi_server.global.error.exception.ConflictException; import com.kusithm.hdmedi_server.global.error.exception.EntityNotFoundException; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.Optional; - import static com.kusithm.hdmedi_server.domain.user.domain.RefreshToken.createRefreshToken; +import static com.kusithm.hdmedi_server.global.error.exception.ErrorCode.DUPLICATE_USER; import static com.kusithm.hdmedi_server.global.error.exception.ErrorCode.USER_NOT_FOUND; @RequiredArgsConstructor @@ -37,6 +38,16 @@ public UserAuthResponseDto signIn(String token, UserAuthRequestDto requestDto) { return UserAuthResponseDto.of(issuedToken, findUser); } + public UserAuthResponseDto signUp(String token, UserSignUpRequestDto requestDto){ + Platform platform = Platform.getEnumPlatformFrom(requestDto.getPlatform()); + String platformId = getPlatformId(token); + validateDuplicateUser(platform, platformId); + User saveUser = saveUser(platform, platformId, requestDto.getUserName()); + Token issuedToken = issueAccessTokenAndRefreshToken(saveUser); + updateRefreshToken(issuedToken.getRefreshToken(), saveUser); + return UserAuthResponseDto.of(issuedToken, saveUser); + } + private User getUser(Platform platform, String platformId) { return userRepository.findUserByPlatformAndPlatformId(platform, platformId) .orElseThrow(() -> new EntityNotFoundException(USER_NOT_FOUND)); @@ -59,4 +70,9 @@ private Token issueAccessTokenAndRefreshToken(User user) { private void updateRefreshToken(String refreshToken, User user) { refreshTokenRepository.save(createRefreshToken(user.getId(), refreshToken)); } + + private void validateDuplicateUser(Platform platform, String platformId) { + if (userRepository.existsUserByPlatformAndPlatformId(platform, platformId)) + throw new ConflictException(DUPLICATE_USER); + } } From a5cbfb6a1795eadc8d54bcafa9415f20e7f54da4 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 13 Sep 2023 01:29:26 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[feat]=20#17=20=ED=9A=8C=EC=9B=90=EC=9D=98?= =?UTF-8?q?=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=20method=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hdmedi_server/domain/user/repository/UserRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/repository/UserRepository.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/repository/UserRepository.java index 80b7e69..6c4a828 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/user/repository/UserRepository.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/repository/UserRepository.java @@ -8,4 +8,5 @@ public interface UserRepository extends JpaRepository { Optional findUserByPlatformAndPlatformId(Platform platform, String platformId); + boolean existsUserByPlatformAndPlatformId(Platform platform, String platformId); } From 9d546b06248f916a6186aa54d18e01ac23dc0d08 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 13 Sep 2023 01:29:38 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[feat]=20#17=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20request=20dto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/dto/request/UserSignUpRequestDto.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/user/dto/request/UserSignUpRequestDto.java diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/dto/request/UserSignUpRequestDto.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/dto/request/UserSignUpRequestDto.java new file mode 100644 index 0000000..8e05293 --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/dto/request/UserSignUpRequestDto.java @@ -0,0 +1,18 @@ +package com.kusithm.hdmedi_server.domain.user.dto.request; + +import com.kusithm.hdmedi_server.domain.user.domain.Gender; +import com.kusithm.hdmedi_server.domain.user.domain.Platform; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class UserSignUpRequestDto { + private String userName; + private LocalDateTime birthday; + private String gender; + private String platform; +}