From 56902e306f08b5b4b3c22fefbb4e382ad266fd15 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 16:48:36 +0900 Subject: [PATCH] =?UTF-8?q?[Weekly/11/Refactor/all]=20=EC=86=8C=EC=85=9C?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#148)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: gender enum으로 수정 * hotfix: 소셜로그인 오류 수정 --- .../application/oauth/GoogleRequestService.java | 7 ++++--- .../application/oauth/KakaoRequestService.java | 8 +++++--- .../application/oauth/OauthRequestService.java | 15 +-------------- .../auth/application/oauth/dto/OauthRequest.java | 2 +- .../ktc2/cokaen/wouldyouin/like/persist/Like.java | 3 +++ .../wouldyouin/member/api/dto/MemberResponse.java | 3 ++- .../ReservationMemberResponse.java | 3 ++- .../dto/request/MemberAdditionalInfoRequest.java | 3 ++- .../dto/request/create/MemberCreateRequest.java | 3 ++- .../cokaen/wouldyouin/member/persist/Curator.java | 2 +- .../cokaen/wouldyouin/member/persist/Gender.java | 8 ++++++++ .../cokaen/wouldyouin/member/persist/Host.java | 2 +- .../cokaen/wouldyouin/member/persist/Member.java | 7 ++++--- .../wouldyouin/_global/testdata/MemberData.java | 7 ++++--- 14 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Gender.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java index da691399..bade50ee 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java @@ -72,13 +72,14 @@ protected AccountType getAccountType() { } @Override - protected OauthRequest getOauthRequestBase() { - return OauthRequest.builder() + public OauthResourcesResponse getOauthMemberResources(String code) { + return requestLoginAndAccessResources(OauthRequest.builder() .grantType("authorization_code") .clientId(clientId) .clientSecret(clientSecret) .redirectUri(redirectUri) - .build(); + .code(code) + .build()); } @Override diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java index 3b443200..f92a690d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java @@ -81,15 +81,17 @@ protected HttpHeaders getAccessRequestHeaders(AccessTokenResponse authentication } @Override - protected OauthRequest getOauthRequestBase() { - return OauthRequest.builder() + public OauthResourcesResponse getOauthMemberResources(String code) { + return requestLoginAndAccessResources(OauthRequest.builder() .grantType("authorization_code") .clientId(clientId) .clientSecret(clientSecret) .redirectUri(redirectUri) - .build(); + .code(code) + .build()); } + @Override protected OauthResourcesResponse requestLoginAndAccessResources(OauthRequest request) { AccessTokenResponse authenticationResponse = client.post( diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/OauthRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/OauthRequestService.java index 6e96036d..7b40e42a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/OauthRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/OauthRequestService.java @@ -9,22 +9,9 @@ @Service public abstract class OauthRequestService { - private OauthRequest oauthRequestBase; - protected abstract AccountType getAccountType(); - protected abstract OauthRequest getOauthRequestBase(); - protected abstract OauthResourcesResponse requestLoginAndAccessResources(OauthRequest oauthRequest); - @PostConstruct - private void init() { - oauthRequestBase = getOauthRequestBase(); - } - - final public OauthResourcesResponse getOauthMemberResources(String code) { - return requestLoginAndAccessResources(oauthRequestBase.toBuilder() - .code(code) - .build()); - } + public abstract OauthResourcesResponse getOauthMemberResources(String code); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthRequest.java index ffcc3405..52cd236d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthRequest.java @@ -9,7 +9,7 @@ @Getter @RequiredArgsConstructor(access = AccessLevel.PROTECTED) -@Builder(toBuilder = true) +@Builder @JsonNaming(SnakeCaseStrategy.class) public class OauthRequest { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java index 48840190..9e1afcb4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java @@ -1,6 +1,8 @@ package org.ktc2.cokaen.wouldyouin.like.persist; import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -39,6 +41,7 @@ public abstract class Like { @NotNull @Column + @Enumerated(EnumType.STRING) private MemberType likeableMemberType; @NotNull diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java index 3d350d8f..e64715b4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java @@ -8,6 +8,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -26,7 +27,7 @@ public class MemberResponse { private MemberType memberType; private Area area; - private String gender; + private Gender gender; private String intro; private Integer likes; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java index eec96917..5e495ba4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java @@ -4,6 +4,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; import org.ktc2.cokaen.wouldyouin.member.persist.Member; @Getter @@ -16,7 +17,7 @@ public class ReservationMemberResponse { private String email; private String nickname; private String phone; - private String gender; + private Gender gender; public static ReservationMemberResponse from(Member member) { return ReservationMemberResponse.builder() diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java index b1eda017..ec1c4b17 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java @@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor; import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; @Getter @EqualsAndHashCode @@ -14,5 +15,5 @@ public class MemberAdditionalInfoRequest { private String phone; private Area area; - private String gender; + private Gender gender; } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java index 0d3661a3..2d3c6a71 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java @@ -8,6 +8,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; import org.ktc2.cokaen.wouldyouin.member.persist.Member; @Getter @@ -36,7 +37,7 @@ public Member toEntity(MemberImage profileImage, String thumbnailImageUrl) { .accountType(this.accountType) .socialId(this.socialId) .area(Area.서울) - .gender("") + .gender(Gender.MAN) .profileImage(profileImage) .profileImageThumbnailUrl(thumbnailImageUrl) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java index cae6326a..3db77301 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java @@ -45,7 +45,7 @@ public class Curator extends Member implements LikeableMember { private List curations = new ArrayList<>(); @Builder(builderMethodName = "curatorBuilder") - public Curator(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, String gender, + public Curator(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, Gender gender, String socialId) { super(accountType, MemberType.curator, email, nickname, phone, profileImage, profileImageThumbnailUrl, area, gender, socialId); this.intro = ""; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Gender.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Gender.java new file mode 100644 index 00000000..311b1652 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Gender.java @@ -0,0 +1,8 @@ +package org.ktc2.cokaen.wouldyouin.member.persist; + +import lombok.Getter; + +@Getter +public enum Gender { + MAN, WOMAN +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index fcabec34..4ff93ba2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -24,7 +24,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @DiscriminatorValue("Host") @EqualsAndHashCode(callSuper = true) -@ToString() +@ToString @Entity public class Host extends BaseMember implements LikeableMember { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index 560ae232..1c4f8345 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -38,7 +38,8 @@ public class Member extends BaseMember { private Area area; @Column(nullable = false, name = "gender") - private String gender; + @Enumerated(EnumType.STRING) + private Gender gender; @Column(name = "social_id") private String socialId; //소셜 타입 식별자 값 @@ -60,7 +61,7 @@ public class Member extends BaseMember { private List reviews = new ArrayList<>(); // for Curator - protected Member(AccountType accountType, MemberType memberType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbNailUrl, Area area, String gender, String socialId) { + protected Member(AccountType accountType, MemberType memberType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbNailUrl, Area area, Gender gender, String socialId) { super(accountType, memberType, email, nickname, phone, profileImage, profileImageThumbNailUrl); this.area = area; this.gender = gender; @@ -69,7 +70,7 @@ protected Member(AccountType accountType, MemberType memberType, String email, S @Builder // for public builder - protected Member(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, String gender, String socialId) { + protected Member(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, Gender gender, String socialId) { this(accountType, MemberType.welcome, email, nickname, phone, profileImage, profileImageThumbnailUrl, area, gender, socialId); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index 9c95335a..e9418187 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -14,6 +14,7 @@ import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -56,7 +57,7 @@ public static List reviews() { public static final String profileImageUrl = ImageData.R.member.normal.url; public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.광주; - public static final String gender = "Men"; + public static final Gender gender = Gender.MAN; public static final String socialId = "100100100100100"; public static final MemberType memberType = MemberType.normal; } @@ -81,7 +82,7 @@ public static List curations() { public static final String profileImageUrl = ImageData.R.member.curator.url; public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.광주; - public static final String gender = "Women"; + public static final Gender gender = Gender.WOMAN; public static final String socialId = "200200200200200"; public static final String intro = "큐레이터 자기소개입니다."; public static final List hashtags = List.of("#큐레이터", "#해시태그", "#입니다"); @@ -122,7 +123,7 @@ public static class welcome1 { public static final String profileImageUrl = ImageData.R.member.welcome.url; public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.서울; - public static final String gender = "Men"; + public static final Gender gender = Gender.MAN; public static final String socialId = "456456456456"; }