From 9f8e4518de12d05b3c6f11215a0d8bef614d67b9 Mon Sep 17 00:00:00 2001 From: WaGaNaWa Date: Fri, 1 Sep 2023 11:22:03 +0900 Subject: [PATCH] =?UTF-8?q?[UPDATE]=20=ED=94=84=EB=A1=A0=ED=8A=B8=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EC=9D=BC=EB=B6=80=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=8C=80?= =?UTF-8?q?=EC=9D=91=ED=95=98=EB=8A=94=20Dto=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EC=86=8C=EC=85=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A9=94=EC=9D=BC=EC=9D=B4=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=EC=97=90=20=EB=8B=A4=EB=A5=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=EC=84=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/service/ttucktak/base/BaseErrorCode.java | 1 + .../ttucktak/controller/AuthController.java | 4 ++++ .../ttucktak/controller/MemberController.java | 2 +- .../service/ttucktak/dto/auth/PostLogoutRes.java | 3 +-- .../ttucktak/dto/auth/PostSignUpReqDto.java | 2 +- .../ttucktak/dto/member/PatchUserDataResDto.java | 5 ++++- .../ttucktak/dto/member/PatchUserPasswordDto.java | 14 ++++++++++++++ .../java/com/service/ttucktak/entity/Member.java | 12 ++++++++++++ .../com/service/ttucktak/service/AuthService.java | 8 +++++++- .../service/ttucktak/service/MemberService.java | 6 +++--- 10 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/service/ttucktak/dto/member/PatchUserPasswordDto.java diff --git a/src/main/java/com/service/ttucktak/base/BaseErrorCode.java b/src/main/java/com/service/ttucktak/base/BaseErrorCode.java index bcfc619..c105253 100644 --- a/src/main/java/com/service/ttucktak/base/BaseErrorCode.java +++ b/src/main/java/com/service/ttucktak/base/BaseErrorCode.java @@ -50,6 +50,7 @@ public enum BaseErrorCode { ALREADY_EXIST_ID(HttpStatus.CONFLICT.value(), "이미 존재하는 아이디입니다."), ALREADY_EXIST_NICKNAME(HttpStatus.CONFLICT.value(), "이미 존재하는 닉네임입니다."), ALREADY_EXIST_EMAIL(HttpStatus.CONFLICT.value(), "이미 존재하는 이메일입니다."), + ALREADY_USED_EMAIL(HttpStatus.CONFLICT.value(), "이미 사용중인 이메일입니다. 이전에 사용하시던 계정으로 사용해 주세요."), /** * 500 : INTERNAL SERVER ERROR diff --git a/src/main/java/com/service/ttucktak/controller/AuthController.java b/src/main/java/com/service/ttucktak/controller/AuthController.java index 45d9c3f..9f67339 100644 --- a/src/main/java/com/service/ttucktak/controller/AuthController.java +++ b/src/main/java/com/service/ttucktak/controller/AuthController.java @@ -166,6 +166,8 @@ public BaseResponse emailConfirm(@Email @RequestParam St @ApiResponses(value = { @ApiResponse(responseCode = "404", description = "카카오 이메일 동의가 필요합니다.", content = @Content(schema = @Schema(implementation = BaseResponse.class))), + @ApiResponse(responseCode = "409", description = "이미 사용중인 이메일입니다. 이전에 사용하시던 계정으로 사용해 주세요.", + content = @Content(schema = @Schema(implementation = BaseResponse.class))), @ApiResponse(responseCode = "500", description = "Database Error | 예상치 못한 에러가 발생하였습니다. | 카카오 로그인 중 오류발생 서버에 문의", content = @Content(schema = @Schema(implementation = BaseResponse.class))), }) @@ -187,6 +189,8 @@ public BaseResponse kakaoOauth2(@RequestParam("code") String authC @ApiResponses(value = { @ApiResponse(responseCode = "401", description = "구글 로그인 중 ID 토큰 검증 실패. 오류 발생.", content = @Content(schema = @Schema(implementation = BaseResponse.class))), + @ApiResponse(responseCode = "409", description = "이미 사용중인 이메일입니다. 이전에 사용하시던 계정으로 사용해 주세요.", + content = @Content(schema = @Schema(implementation = BaseResponse.class))), @ApiResponse(responseCode = "500", description = "Database Error | 예상치 못한 에러가 발생하였습니다. | 구글 로그인 중 GoogleIDToken Payload 과정에서 오류 발생. 서버에 문의. | 구글 JWT 토큰 인증 중 구글 시큐리티 문제 발생. | 구글 JWT 토큰 인증 중 IO 문제 발생.", content = @Content(schema = @Schema(implementation = BaseResponse.class))) }) diff --git a/src/main/java/com/service/ttucktak/controller/MemberController.java b/src/main/java/com/service/ttucktak/controller/MemberController.java index abf7e84..38aa4f1 100644 --- a/src/main/java/com/service/ttucktak/controller/MemberController.java +++ b/src/main/java/com/service/ttucktak/controller/MemberController.java @@ -195,7 +195,7 @@ public BaseResponse patchNightNotice(@RequestBody PatchNotice content = @Content(schema = @Schema(implementation = BaseResponse.class))), }) @PatchMapping("/password") - public BaseResponse updateUserdata(@RequestBody PutPasswordUpdateDto reqDto, @RequestHeader(CustomHttpHeaders.AUTHORIZATION) String jwt) throws BaseException{ + public BaseResponse updateUserdata(@RequestBody PutPasswordUpdateDto reqDto, @RequestHeader(CustomHttpHeaders.AUTHORIZATION) String jwt) throws BaseException{ UUID userIdx; try{ diff --git a/src/main/java/com/service/ttucktak/dto/auth/PostLogoutRes.java b/src/main/java/com/service/ttucktak/dto/auth/PostLogoutRes.java index fcd7bd8..583ac21 100644 --- a/src/main/java/com/service/ttucktak/dto/auth/PostLogoutRes.java +++ b/src/main/java/com/service/ttucktak/dto/auth/PostLogoutRes.java @@ -10,7 +10,6 @@ @AllArgsConstructor @NoArgsConstructor public class PostLogoutRes { - @Schema(name = "isSuccess", example = "true", description = "회원가입 성공 여부") - @JsonProperty("isSuccess") + @Schema(name = "isSuccess", example = "true", description = "로그아웃 성공") boolean isSuccess; } diff --git a/src/main/java/com/service/ttucktak/dto/auth/PostSignUpReqDto.java b/src/main/java/com/service/ttucktak/dto/auth/PostSignUpReqDto.java index 611af6a..1cd3350 100644 --- a/src/main/java/com/service/ttucktak/dto/auth/PostSignUpReqDto.java +++ b/src/main/java/com/service/ttucktak/dto/auth/PostSignUpReqDto.java @@ -33,7 +33,7 @@ public Member toMember() { .nickname(nickname) .accountType(AccountType.DEFAULT) .adProvision(adProvision) - .profileImgUrl("default url") // Todo: default image url 설정 필요 + .profileImgUrl("https://ttuckttak.s3.ap-northeast-2.amazonaws.com/profile/%E2%80%94Pngtree%E2%80%94vector+edit+profile+icon_4101351.png") // Todo: default image url 설정 필요 .pushApprove(true) .refreshToken(null) .nightApprove(true) diff --git a/src/main/java/com/service/ttucktak/dto/member/PatchUserDataResDto.java b/src/main/java/com/service/ttucktak/dto/member/PatchUserDataResDto.java index 19ee57b..7f5dd1c 100644 --- a/src/main/java/com/service/ttucktak/dto/member/PatchUserDataResDto.java +++ b/src/main/java/com/service/ttucktak/dto/member/PatchUserDataResDto.java @@ -9,8 +9,11 @@ @AllArgsConstructor public class PatchUserDataResDto { - @Schema(name = "isSuccess", example = "true", description = "회원가입 성공 여부") + @Schema(name = "isSuccess", example = "true", description = "") @JsonProperty("isSuccess") boolean isSuccess; + @Schema(name = "userData",description = "updated user data (nullable)") + UserDataDto userData; + } diff --git a/src/main/java/com/service/ttucktak/dto/member/PatchUserPasswordDto.java b/src/main/java/com/service/ttucktak/dto/member/PatchUserPasswordDto.java new file mode 100644 index 0000000..0a7f5d4 --- /dev/null +++ b/src/main/java/com/service/ttucktak/dto/member/PatchUserPasswordDto.java @@ -0,0 +1,14 @@ +package com.service.ttucktak.dto.member; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class PatchUserPasswordDto { + + @Schema(name = "isSuccess", example = "true", description = "") + boolean isSuccess; + +} diff --git a/src/main/java/com/service/ttucktak/entity/Member.java b/src/main/java/com/service/ttucktak/entity/Member.java index d2d7ba2..d89364d 100644 --- a/src/main/java/com/service/ttucktak/entity/Member.java +++ b/src/main/java/com/service/ttucktak/entity/Member.java @@ -3,6 +3,7 @@ import com.service.ttucktak.base.AccountType; import com.service.ttucktak.base.BaseEntity; import com.service.ttucktak.dto.member.PatchUserDataReqDto; +import com.service.ttucktak.dto.member.UserDataDto; import com.service.ttucktak.dto.member.UserDataUpdateDto; import jakarta.persistence.*; import lombok.*; @@ -10,6 +11,7 @@ import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.GenericGenerator; import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import java.text.ParseException; @@ -91,6 +93,16 @@ public void updateUserProfile(UserDataUpdateDto dto) { } } + public UserDataDto asUserDataDto(){ + return UserDataDto.builder() + .userName(nickname) + .email(userId) + .profileImgUrl(profileImgUrl) + .nightPushStatus(nightApprove) + .pushStatus(pushApprove) + .accountType(accountType).build(); + } + public void updateProfileImageUrl(String uploadedUrl) { this.profileImgUrl = uploadedUrl; } diff --git a/src/main/java/com/service/ttucktak/service/AuthService.java b/src/main/java/com/service/ttucktak/service/AuthService.java index f0f8fd3..2714691 100644 --- a/src/main/java/com/service/ttucktak/service/AuthService.java +++ b/src/main/java/com/service/ttucktak/service/AuthService.java @@ -226,6 +226,10 @@ public PostLoginRes loginWithSocialAccount(SocialAccountUserInfo data, AccountTy return memberRepository.save(newMember); }); + if (!member.getAccountType().equals(type)) { + throw new BaseException(BaseErrorCode.ALREADY_USED_EMAIL); + } + // --- 로그인 처리 --- // 토큰을 발급받고, refresh token을 DB에 저장한다. TokensDto token = generateToken(member.getUserId(), member.getUserId(), member.getMemberIdx(), data.getUserEmail()); @@ -235,7 +239,9 @@ public PostLoginRes loginWithSocialAccount(SocialAccountUserInfo data, AccountTy return new PostLoginRes(member.getMemberIdx().toString(), token); - } catch (Exception e) { + }catch (BaseException e){ + throw e; + }catch (Exception e) { log.error(e.getMessage()); throw new BaseException(BaseErrorCode.DATABASE_ERROR); } diff --git a/src/main/java/com/service/ttucktak/service/MemberService.java b/src/main/java/com/service/ttucktak/service/MemberService.java index a0754ff..3a66fec 100644 --- a/src/main/java/com/service/ttucktak/service/MemberService.java +++ b/src/main/java/com/service/ttucktak/service/MemberService.java @@ -165,11 +165,11 @@ public PatchUserDataResDto updateUserByUUID(UUID memberIdx, UserDataUpdateDto dt throw new BaseException(BaseErrorCode.MEMBER_ERROR); } - return new PatchUserDataResDto(true); + return new PatchUserDataResDto(true,currentUser.asUserDataDto()); } - public PatchUserDataResDto updateUserPasswordByUUID(UUID memberIdx, PutPasswordUpdateDto dto) throws BaseException { + public PatchUserPasswordDto updateUserPasswordByUUID(UUID memberIdx, PutPasswordUpdateDto dto) throws BaseException { Optional res = memberRepository.findByMemberIdx(memberIdx); @@ -182,7 +182,7 @@ public PatchUserDataResDto updateUserPasswordByUUID(UUID memberIdx, PutPasswordU throw new BaseException(BaseErrorCode.PWUPDATE_ERROR); } - return new PatchUserDataResDto(true); + return new PatchUserPasswordDto(true); }