From 2cb395951b174c37490bdb09e68c8b8b99cf1c28 Mon Sep 17 00:00:00 2001 From: parksey Date: Sun, 29 Oct 2023 13:42:37 +0900 Subject: [PATCH 01/27] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/moabam/api/domain/member/Member.java | 82 +++++++++++++++++++ .../com/moabam/api/domain/member/Role.java | 7 ++ .../global/common/util/BaseImageUrl.java | 14 ++++ .../moabam/api/domain/member/MemberTest.java | 62 ++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 src/main/java/com/moabam/api/domain/member/Member.java create mode 100644 src/main/java/com/moabam/api/domain/member/Role.java create mode 100644 src/main/java/com/moabam/global/common/util/BaseImageUrl.java create mode 100644 src/test/java/com/moabam/api/domain/member/MemberTest.java diff --git a/src/main/java/com/moabam/api/domain/member/Member.java b/src/main/java/com/moabam/api/domain/member/Member.java new file mode 100644 index 00000000..3964b546 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/member/Member.java @@ -0,0 +1,82 @@ +package com.moabam.api.domain.member; + +import com.moabam.global.common.entity.BaseTimeEntity; +import com.moabam.global.common.util.BaseImageUrl; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.ColumnDefault; + +import java.time.LocalDateTime; + +import static java.util.Objects.requireNonNull; +import static java.util.Objects.requireNonNullElse; + +@Getter +@Entity +@Table(name = "members") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Member extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_id") + private Long id; + + @Column(name = "social_id", nullable = false, unique = true) + private String socialId; + + @Column(name = "nickname", nullable = false, unique = true) + private String nickname; + + @Column(name = "intro") + private String intro; + + @Column(name = "profile_image", nullable = false) + private String profileImage; + + @Column(name = "total_certify_count", nullable = false) + @ColumnDefault("0") + private long totalCertifyCount; + + @Column(name = "report_count", nullable = false) + @ColumnDefault("0") + private int reportCount; + + @Column(name = "current_night_count", nullable = false) + @ColumnDefault("0") + private int currentNightCount; + + @Column(name = "current_morning_count", nullable = false) + @ColumnDefault("0") + private int currentMorningCount; + + @Column(name = "morning_bug", nullable = false) + @ColumnDefault("0") + private int morningBug; + + @Column(name = "night_bug", nullable = false) + @ColumnDefault("0") + private int nightBug; + + @Column(name = "golden_bug", nullable = false) + @ColumnDefault("0") + private int goldenBug; + + @Enumerated(EnumType.STRING) + @Column(name = "role", nullable = false) + private Role role; + + @Column(name = "deleted_at") + private LocalDateTime deletedAt; + + @Builder + private Member(String socialId, String nickname, String profileImage) { + this.socialId = requireNonNull(socialId); + this.nickname = requireNonNull(nickname); + this.profileImage = requireNonNullElse(profileImage, BaseImageUrl.PROFILE_URL.getUrl()); + this.role = Role.USER; + } +} diff --git a/src/main/java/com/moabam/api/domain/member/Role.java b/src/main/java/com/moabam/api/domain/member/Role.java new file mode 100644 index 00000000..3e8c0c95 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/member/Role.java @@ -0,0 +1,7 @@ +package com.moabam.api.domain.member; + +public enum Role { + USER, + BLACK, + ADMIN +} diff --git a/src/main/java/com/moabam/global/common/util/BaseImageUrl.java b/src/main/java/com/moabam/global/common/util/BaseImageUrl.java new file mode 100644 index 00000000..81196bc1 --- /dev/null +++ b/src/main/java/com/moabam/global/common/util/BaseImageUrl.java @@ -0,0 +1,14 @@ +package com.moabam.global.common.util; + +import lombok.Getter; + +@Getter +public enum BaseImageUrl { + PROFILE_URL("/profile/baseUrl"); + + private String url; + + BaseImageUrl(String url) { + this.url = url; + } +} diff --git a/src/test/java/com/moabam/api/domain/member/MemberTest.java b/src/test/java/com/moabam/api/domain/member/MemberTest.java new file mode 100644 index 00000000..2ef8936c --- /dev/null +++ b/src/test/java/com/moabam/api/domain/member/MemberTest.java @@ -0,0 +1,62 @@ +package com.moabam.api.domain.member; + +import com.moabam.global.common.util.BaseImageUrl; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertAll; + +class MemberTest { + + String socialId = "1"; + String nickname = "밥세공기"; + String profileImage = "kakao/profile/url"; + + @DisplayName("회원 생성 성공") + @Test + void create_member_success() { + // When + Then + assertThatNoException().isThrownBy(() -> Member.builder() + .socialId(socialId) + .nickname(nickname) + .profileImage(profileImage) + .build()); + } + + @DisplayName("프로필 이미지 없이 회원 생성 성공") + @Test + void create_member_noImage_success() { + // When + Then + assertThatNoException().isThrownBy(() -> { + Member member = Member.builder() + .socialId(socialId) + .nickname(nickname) + .profileImage(null) + .build(); + + assertAll( + () -> assertThat(member.getProfileImage()).isEqualTo(BaseImageUrl.PROFILE_URL.getUrl()), + () -> assertThat(member.getRole()).isEqualTo(Role.USER) + ); + }); + } + + @DisplayName("소셜ID에 따른 회원 생성 실패") + @Test + void creat_member_failBy_socialId() { + // When + Then + assertThatThrownBy(Member.builder() + .nickname(nickname)::build) + .isInstanceOf(NullPointerException.class); + } + + @DisplayName("닉네임에 따른 회원 생성 실패") + @Test + void create_member_failBy_nickname() { + // When + Then + assertThatThrownBy(Member.builder() + .socialId(socialId)::build) + .isInstanceOf(NullPointerException.class); + } +} From 3c119f8509d0844f277358741ac3189bb9cdb4d0 Mon Sep 17 00:00:00 2001 From: parksey Date: Sun, 29 Oct 2023 17:28:19 +0900 Subject: [PATCH 02/27] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20OAu?= =?UTF-8?q?th=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B0=94=EC=9D=B8?= =?UTF-8?q?=EB=94=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++ .../com/moabam/MoabamServerApplication.java | 8 +++++- .../com/moabam/global/config/OAuthConfig.java | 28 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/moabam/global/config/OAuthConfig.java diff --git a/build.gradle b/build.gradle index 1fc75afe..0bb89395 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,9 @@ dependencies { // H2 implementation 'com.h2database:h2' + + // Configuration Binding + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" } tasks.named('test') { diff --git a/src/main/java/com/moabam/MoabamServerApplication.java b/src/main/java/com/moabam/MoabamServerApplication.java index 5390acc3..95ca95aa 100644 --- a/src/main/java/com/moabam/MoabamServerApplication.java +++ b/src/main/java/com/moabam/MoabamServerApplication.java @@ -1,13 +1,19 @@ package com.moabam; +import com.moabam.global.config.OAuthConfig; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +@ConfigurationPropertiesScan @SpringBootApplication public class MoabamServerApplication { + @Autowired + OAuthConfig oAuthConfig; + public static void main(String[] args) { SpringApplication.run(MoabamServerApplication.class, args); } - } diff --git a/src/main/java/com/moabam/global/config/OAuthConfig.java b/src/main/java/com/moabam/global/config/OAuthConfig.java new file mode 100644 index 00000000..603df341 --- /dev/null +++ b/src/main/java/com/moabam/global/config/OAuthConfig.java @@ -0,0 +1,28 @@ +package com.moabam.global.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.List; + +@ConfigurationProperties(prefix = "oauth2") +public record OAuthConfig( + Provider provider, + Client client +) { + + public record Client( + String provider, + String clientId, + String authorizationGrantType, + List scope + ) { + + } + + public record Provider( + String authorizationUrl, + String redirectUrl + ) { + + } +} From 729d7d2e3cac5a13138e269425077c065b2b6c2e Mon Sep 17 00:00:00 2001 From: parksey Date: Sun, 29 Oct 2023 19:08:25 +0900 Subject: [PATCH 03/27] =?UTF-8?q?feat:=20authorization=20code=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=9B=EA=B8=B0=20=EC=9C=84=ED=95=9C=20queryString=20generat?= =?UTF-8?q?or=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/AuthenticationService.java | 33 ++++++++++++ .../global/common/util/GlobalConstant.java | 6 +++ .../global/common/util/UrlGenerator.java | 40 ++++++++++++++ .../global/common/util/UrlGeneratorTest.java | 54 +++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 src/main/java/com/moabam/api/application/auth/AuthenticationService.java create mode 100644 src/main/java/com/moabam/global/common/util/GlobalConstant.java create mode 100644 src/main/java/com/moabam/global/common/util/UrlGenerator.java create mode 100644 src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java diff --git a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java new file mode 100644 index 00000000..93fe070f --- /dev/null +++ b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java @@ -0,0 +1,33 @@ +package com.moabam.api.application.auth; + +import com.moabam.global.common.util.GlobalConstant; +import com.moabam.global.common.util.UrlGenerator; +import com.moabam.global.config.OAuthConfig; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class AuthenticationService { + + private static final String RESPONSE_TYPE = "response_type"; + private static final String CODE = "code"; + private static final String CLIENT_ID = "client_id"; + private static final String REDIRECT_URL = "redirect_url"; + private static final String SCOPE = "scope"; + + private final OAuthConfig oAuthConfig; + + public String authorizaionCodeUrl() { + String scopes = String.join(GlobalConstant.COMMA, oAuthConfig.client().scope()); + UrlGenerator url = UrlGenerator.builder() + .baseUrl(oAuthConfig.provider().authorizationUrl()) + .parameter(RESPONSE_TYPE, CODE) + .parameter(CLIENT_ID, oAuthConfig.client().clientId()) + .parameter(REDIRECT_URL, oAuthConfig.provider().redirectUrl()) + .parameter(SCOPE, scopes) + .build(); + + return url.generateUrl(); + } +} diff --git a/src/main/java/com/moabam/global/common/util/GlobalConstant.java b/src/main/java/com/moabam/global/common/util/GlobalConstant.java new file mode 100644 index 00000000..8fdb1a9c --- /dev/null +++ b/src/main/java/com/moabam/global/common/util/GlobalConstant.java @@ -0,0 +1,6 @@ +package com.moabam.global.common.util; + +public class GlobalConstant { + + public static final String COMMA = ","; +} diff --git a/src/main/java/com/moabam/global/common/util/UrlGenerator.java b/src/main/java/com/moabam/global/common/util/UrlGenerator.java new file mode 100644 index 00000000..3db1521d --- /dev/null +++ b/src/main/java/com/moabam/global/common/util/UrlGenerator.java @@ -0,0 +1,40 @@ +package com.moabam.global.common.util; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.NoArgsConstructor; +import lombok.Singular; + +import java.util.Map; + +import static java.util.Objects.requireNonNull; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UrlGenerator { + + private static final String QUERY_BEGIN = "?"; + private static final String QUERY_SEPERATE = "&"; + private static final String QUERY_MATCH = "="; + + private String baseUrl; + + private Map parameters; + + @Builder + private UrlGenerator(String baseUrl, @Singular("parameter") Map parameters) { + this.baseUrl = requireNonNull(baseUrl); + this.parameters = parameters; + } + + public String generateUrl() { + StringBuilder url = new StringBuilder(baseUrl); + + url.append(QUERY_BEGIN); + parameters.forEach((key, value) -> + url.append(key).append(QUERY_MATCH).append(value).append(QUERY_SEPERATE)); + url.deleteCharAt(url.length() - 1); + + return url.toString(); + } + +} diff --git a/src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java b/src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java new file mode 100644 index 00000000..3a8679c3 --- /dev/null +++ b/src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java @@ -0,0 +1,54 @@ +package com.moabam.global.common.util; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; + +class UrlGeneratorTest { + + private static final String BASE_URL = "http://localhost:8080/auth"; + private static final String RESPONSE_TYPE = "response-type"; + private static final String CODE = "code"; + + @DisplayName("베이스 URL이 없으면 생성 실패") + @Test + void create_url_failBy_no_base_url() { + // When + Then + assertThatThrownBy(UrlGenerator.builder()::build) + .isInstanceOf(NullPointerException.class); + } + + @DisplayName("URL 생성 성공") + @Test + void create_url_success() { + assertThatNoException().isThrownBy(() -> { + // Given + UrlGenerator urlGenerator = UrlGenerator.builder() + .baseUrl(BASE_URL).build(); + + // When + String url = urlGenerator.generateUrl(); + + // Then + assertThat(url).isEqualTo(BASE_URL); + }); + } + + @DisplayName("쿼리가 포함된 url 생성 성공") + @Test + void create_query_url_success() { + assertThatNoException().isThrownBy(() -> { + // Given + UrlGenerator urlGenerator = UrlGenerator.builder() + .baseUrl(BASE_URL) + .parameter(RESPONSE_TYPE, CODE).build(); + + // When + String url = urlGenerator.generateUrl(); + + // Then + assertThat(url).isEqualTo(BASE_URL + "?" + RESPONSE_TYPE + "=" + CODE); + }); + } +} From 9cbfc2ef5720cd37f654c81e70ed38d8a526a2e0 Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 12:05:04 +0900 Subject: [PATCH 04/27] =?UTF-8?q?feat:=20Authorization=20code=EC=9D=98=20p?= =?UTF-8?q?arameter=20=EB=A7=8C=EB=93=9C=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/AuthenticationService.java | 26 ++++------ .../api/dto/AuthorizationCodeRequest.java | 43 ++++++++++++++++ .../global/common/util/GlobalConstant.java | 1 + .../common/util/OAuthParameterNames.java | 14 ++++++ .../auth/AuthenticationServiceTest.java | 49 +++++++++++++++++++ 5 files changed, 116 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/moabam/api/dto/AuthorizationCodeRequest.java create mode 100644 src/main/java/com/moabam/global/common/util/OAuthParameterNames.java create mode 100644 src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java diff --git a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java index 93fe070f..7f71b115 100644 --- a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java +++ b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java @@ -1,7 +1,6 @@ package com.moabam.api.application.auth; -import com.moabam.global.common.util.GlobalConstant; -import com.moabam.global.common.util.UrlGenerator; +import com.moabam.api.dto.AuthorizationCodeRequest; import com.moabam.global.config.OAuthConfig; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -10,24 +9,17 @@ @RequiredArgsConstructor public class AuthenticationService { - private static final String RESPONSE_TYPE = "response_type"; - private static final String CODE = "code"; - private static final String CLIENT_ID = "client_id"; - private static final String REDIRECT_URL = "redirect_url"; - private static final String SCOPE = "scope"; - private final OAuthConfig oAuthConfig; - public String authorizaionCodeUrl() { - String scopes = String.join(GlobalConstant.COMMA, oAuthConfig.client().scope()); - UrlGenerator url = UrlGenerator.builder() - .baseUrl(oAuthConfig.provider().authorizationUrl()) - .parameter(RESPONSE_TYPE, CODE) - .parameter(CLIENT_ID, oAuthConfig.client().clientId()) - .parameter(REDIRECT_URL, oAuthConfig.provider().redirectUrl()) - .parameter(SCOPE, scopes) + public AuthorizationCodeRequest authorizaionCodeParams() { + return AuthorizationCodeRequest.builder() + .clientId(oAuthConfig.client().clientId()) + .redirectUri(oAuthConfig.provider().redirectUrl()) + .scope(oAuthConfig.client().scope()) .build(); + } - return url.generateUrl(); + public String getUrl() { + return oAuthConfig.provider().authorizationUrl(); } } diff --git a/src/main/java/com/moabam/api/dto/AuthorizationCodeRequest.java b/src/main/java/com/moabam/api/dto/AuthorizationCodeRequest.java new file mode 100644 index 00000000..5f3f51fb --- /dev/null +++ b/src/main/java/com/moabam/api/dto/AuthorizationCodeRequest.java @@ -0,0 +1,43 @@ +package com.moabam.api.dto; + +import com.moabam.global.common.util.GlobalConstant; +import lombok.Builder; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import java.util.List; + +import static com.moabam.global.common.util.OAuthParameterNames.*; + +public record AuthorizationCodeRequest( + String clientId, + String redirectUri, + String responseType, + List scope, + String state +) { + + @Builder + public AuthorizationCodeRequest(String clientId, String redirectUri, String responseType, List scope, + String state) { + this.clientId = clientId; + this.redirectUri = redirectUri; + this.responseType = responseType; + this.scope = scope; + this.state = state; + } + + public MultiValueMap generateQueryParams() { + MultiValueMap oauthParam = new LinkedMultiValueMap<>(); + oauthParam.add(RESPONSE_TYPE, CODE); + oauthParam.add(CLIENT_ID, clientId); + oauthParam.add(REDIRECT_URL, redirectUri); + + if (!scope.isEmpty()) { + String scopes = String.join(GlobalConstant.COMMA, scope); + oauthParam.add(SCOPE, scopes); + } + + return oauthParam; + } +} diff --git a/src/main/java/com/moabam/global/common/util/GlobalConstant.java b/src/main/java/com/moabam/global/common/util/GlobalConstant.java index 8fdb1a9c..419d2615 100644 --- a/src/main/java/com/moabam/global/common/util/GlobalConstant.java +++ b/src/main/java/com/moabam/global/common/util/GlobalConstant.java @@ -3,4 +3,5 @@ public class GlobalConstant { public static final String COMMA = ","; + public static final String SEMI_COLON = ";"; } diff --git a/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java b/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java new file mode 100644 index 00000000..d6ff30ad --- /dev/null +++ b/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java @@ -0,0 +1,14 @@ +package com.moabam.global.common.util; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class OAuthParameterNames { + + public static final String RESPONSE_TYPE = "response_type"; + public static final String CODE = "code"; + public static final String CLIENT_ID = "client_id"; + public static final String REDIRECT_URL = "redirect_url"; + public static final String SCOPE = "scope"; +} diff --git a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java b/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java new file mode 100644 index 00000000..06bcd4a4 --- /dev/null +++ b/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java @@ -0,0 +1,49 @@ +package com.moabam.api.application.auth; + +import com.moabam.api.dto.AuthorizationCodeRequest; +import com.moabam.global.config.OAuthConfig; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +@ExtendWith(MockitoExtension.class) +class AuthenticationServiceTest { + + @InjectMocks + AuthenticationService authenticationService; + + OAuthConfig oauthConfig; + + @BeforeEach + public void initParams() { + oauthConfig = new OAuthConfig( + new OAuthConfig.Provider("https://test.com/test/test", "http://test:8080/test"), + new OAuthConfig.Client("provider", "testtestetsttest", "authorization_code", + List.of("profile_nickname", "profile_image")) + ); + ReflectionTestUtils.setField(authenticationService, "oAuthConfig", oauthConfig); + } + + @DisplayName("") + @Test + void authenticationUrl() { + // Given + When + AuthorizationCodeRequest codeRequest = authenticationService.authorizaionCodeParams(); + + // Then + assertAll( + () -> assertThat(codeRequest.clientId()).isEqualTo(oauthConfig.client().clientId()), + () -> assertThat(codeRequest.scope()).isEqualTo(oauthConfig.client().scope()), + () -> assertThat(codeRequest.redirectUri()).isEqualTo(oauthConfig.provider().redirectUrl()) + ); + } +} From e05690566cfda199993b20a376168ec121a4ed15 Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 12:18:20 +0900 Subject: [PATCH 05/27] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EA=B0=80?= =?UTF-8?q?=EC=9E=85/=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=9A=94=EC=B2=AD=20ap?= =?UTF-8?q?i=20=EB=B0=8F=20=EC=86=8C=EC=85=9C=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/presentation/MemberController.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/moabam/api/presentation/MemberController.java diff --git a/src/main/java/com/moabam/api/presentation/MemberController.java b/src/main/java/com/moabam/api/presentation/MemberController.java new file mode 100644 index 00000000..2658b9bc --- /dev/null +++ b/src/main/java/com/moabam/api/presentation/MemberController.java @@ -0,0 +1,32 @@ +package com.moabam.api.presentation; + +import com.moabam.api.application.auth.AuthenticationService; +import com.moabam.api.dto.AuthorizationCodeRequest; +import com.moabam.global.common.util.GlobalConstant; +import lombok.RequiredArgsConstructor; +import org.springframework.http.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +import java.nio.charset.StandardCharsets; + +@RestController +@RequestMapping("/members") +@RequiredArgsConstructor +public class MemberController { + + private final AuthenticationService authenticationService; + + @GetMapping + public ResponseEntity socialLogin() { + AuthorizationCodeRequest authorizationCodeRequest = authenticationService.authorizaionCodeParams(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.SEMI_COLON + + StandardCharsets.UTF_8.name())); + HttpEntity httpEntity = new HttpEntity<>(authorizationCodeRequest.generateQueryParams(), headers); + + return new RestTemplate().exchange(authenticationService.getUrl(), HttpMethod.GET, httpEntity, String.class); + } +} From 0dc50e4b8ec3fbbd761739c468d8f5f7f4dd50b8 Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 12:59:36 +0900 Subject: [PATCH 06/27] =?UTF-8?q?refactor:=20member=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=84=A4=EC=9D=B4=EB=B0=8D?= =?UTF-8?q?=EA=B3=BC=20=ED=8F=B4=EB=8D=94=20=EC=9C=84=EC=B9=98=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/AuthenticationService.java | 6 +++--- .../AuthorizationCodeIssue.java} | 8 ++++---- .../{ => member}/MemberController.java | 19 ++++++++++++++++--- .../global/error/model/ErrorMessage.java | 3 ++- .../auth/AuthenticationServiceTest.java | 4 ++-- 5 files changed, 27 insertions(+), 13 deletions(-) rename src/main/java/com/moabam/api/dto/{AuthorizationCodeRequest.java => auth/AuthorizationCodeIssue.java} (82%) rename src/main/java/com/moabam/api/presentation/{ => member}/MemberController.java (61%) diff --git a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java index 7f71b115..5e92aad0 100644 --- a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java +++ b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java @@ -1,6 +1,6 @@ package com.moabam.api.application.auth; -import com.moabam.api.dto.AuthorizationCodeRequest; +import com.moabam.api.dto.auth.AuthorizationCodeIssue; import com.moabam.global.config.OAuthConfig; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -11,8 +11,8 @@ public class AuthenticationService { private final OAuthConfig oAuthConfig; - public AuthorizationCodeRequest authorizaionCodeParams() { - return AuthorizationCodeRequest.builder() + public AuthorizationCodeIssue authorizaionCodeParams() { + return AuthorizationCodeIssue.builder() .clientId(oAuthConfig.client().clientId()) .redirectUri(oAuthConfig.provider().redirectUrl()) .scope(oAuthConfig.client().scope()) diff --git a/src/main/java/com/moabam/api/dto/AuthorizationCodeRequest.java b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java similarity index 82% rename from src/main/java/com/moabam/api/dto/AuthorizationCodeRequest.java rename to src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java index 5f3f51fb..75ed1f9d 100644 --- a/src/main/java/com/moabam/api/dto/AuthorizationCodeRequest.java +++ b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java @@ -1,4 +1,4 @@ -package com.moabam.api.dto; +package com.moabam.api.dto.auth; import com.moabam.global.common.util.GlobalConstant; import lombok.Builder; @@ -9,7 +9,7 @@ import static com.moabam.global.common.util.OAuthParameterNames.*; -public record AuthorizationCodeRequest( +public record AuthorizationCodeIssue( String clientId, String redirectUri, String responseType, @@ -18,8 +18,8 @@ public record AuthorizationCodeRequest( ) { @Builder - public AuthorizationCodeRequest(String clientId, String redirectUri, String responseType, List scope, - String state) { + public AuthorizationCodeIssue(String clientId, String redirectUri, String responseType, List scope, + String state) { this.clientId = clientId; this.redirectUri = redirectUri; this.responseType = responseType; diff --git a/src/main/java/com/moabam/api/presentation/MemberController.java b/src/main/java/com/moabam/api/presentation/member/MemberController.java similarity index 61% rename from src/main/java/com/moabam/api/presentation/MemberController.java rename to src/main/java/com/moabam/api/presentation/member/MemberController.java index 2658b9bc..990d2fec 100644 --- a/src/main/java/com/moabam/api/presentation/MemberController.java +++ b/src/main/java/com/moabam/api/presentation/member/MemberController.java @@ -1,11 +1,15 @@ -package com.moabam.api.presentation; +package com.moabam.api.presentation.member; import com.moabam.api.application.auth.AuthenticationService; -import com.moabam.api.dto.AuthorizationCodeRequest; +import com.moabam.api.dto.auth.AuthorizationCodeIssue; +import com.moabam.api.dto.auth.AuthorizationCodeResponse; import com.moabam.global.common.util.GlobalConstant; +import com.moabam.global.error.exception.NotFoundException; +import com.moabam.global.error.model.ErrorMessage; import lombok.RequiredArgsConstructor; import org.springframework.http.*; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @@ -21,7 +25,7 @@ public class MemberController { @GetMapping public ResponseEntity socialLogin() { - AuthorizationCodeRequest authorizationCodeRequest = authenticationService.authorizaionCodeParams(); + AuthorizationCodeIssue authorizationCodeRequest = authenticationService.authorizaionCodeParams(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.SEMI_COLON + StandardCharsets.UTF_8.name())); @@ -29,4 +33,13 @@ public ResponseEntity socialLogin() { return new RestTemplate().exchange(authenticationService.getUrl(), HttpMethod.GET, httpEntity, String.class); } + + @GetMapping("/login") + public void authorizationServerCodeResponse(@ModelAttribute AuthorizationCodeResponse authorizationCodeResponse) { + if (authorizationCodeResponse.code().isEmpty()) { + throw new NotFoundException(ErrorMessage.LOGIN_FAILED); + } + + + } } diff --git a/src/main/java/com/moabam/global/error/model/ErrorMessage.java b/src/main/java/com/moabam/global/error/model/ErrorMessage.java index 662874f6..0ad98085 100644 --- a/src/main/java/com/moabam/global/error/model/ErrorMessage.java +++ b/src/main/java/com/moabam/global/error/model/ErrorMessage.java @@ -7,7 +7,8 @@ @RequiredArgsConstructor public enum ErrorMessage { - INVALID_REQUEST_FIELD("올바른 요청 정보가 아닙니다."); + INVALID_REQUEST_FIELD("올바른 요청 정보가 아닙니다."), + LOGIN_FAILED("로그인에 실패했습니다."); private final String message; } diff --git a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java b/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java index 06bcd4a4..c72c05b8 100644 --- a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java +++ b/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java @@ -1,6 +1,6 @@ package com.moabam.api.application.auth; -import com.moabam.api.dto.AuthorizationCodeRequest; +import com.moabam.api.dto.auth.AuthorizationCodeIssue; import com.moabam.global.config.OAuthConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -37,7 +37,7 @@ public void initParams() { @Test void authenticationUrl() { // Given + When - AuthorizationCodeRequest codeRequest = authenticationService.authorizaionCodeParams(); + AuthorizationCodeIssue codeRequest = authenticationService.authorizaionCodeParams(); // Then assertAll( From 233661af330686381faa7dce0378d33d4bfe9bee Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 15:07:48 +0900 Subject: [PATCH 07/27] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=9A=94=EC=B2=AD=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20Resttemplate=20->=20response=20(redirect)=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/AuthenticationService.java | 11 ++++----- .../api/dto/auth/AuthorizationCodeIssue.java | 18 +++++++-------- .../presentation/member/MemberController.java | 23 ++++++++----------- .../common/util/OAuthParameterNames.java | 2 +- .../com/moabam/global/config/OAuthConfig.java | 4 ++-- .../auth/AuthenticationServiceTest.java | 10 ++------ 6 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java index 5e92aad0..11095b38 100644 --- a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java +++ b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java @@ -11,15 +11,12 @@ public class AuthenticationService { private final OAuthConfig oAuthConfig; - public AuthorizationCodeIssue authorizaionCodeParams() { + public String getAuthorizaionCodeUri() { return AuthorizationCodeIssue.builder() .clientId(oAuthConfig.client().clientId()) - .redirectUri(oAuthConfig.provider().redirectUrl()) + .redirectUri(oAuthConfig.provider().redirectUri()) .scope(oAuthConfig.client().scope()) - .build(); - } - - public String getUrl() { - return oAuthConfig.provider().authorizationUrl(); + .build() + .generateQueryParamsWith(oAuthConfig.provider().authorizationUri()); } } diff --git a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java index 75ed1f9d..17ce3d63 100644 --- a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java +++ b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java @@ -2,8 +2,7 @@ import com.moabam.global.common.util.GlobalConstant; import lombok.Builder; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; +import org.springframework.web.util.UriComponentsBuilder; import java.util.List; @@ -27,17 +26,18 @@ public AuthorizationCodeIssue(String clientId, String redirectUri, String respon this.state = state; } - public MultiValueMap generateQueryParams() { - MultiValueMap oauthParam = new LinkedMultiValueMap<>(); - oauthParam.add(RESPONSE_TYPE, CODE); - oauthParam.add(CLIENT_ID, clientId); - oauthParam.add(REDIRECT_URL, redirectUri); + public String generateQueryParamsWith(String baseUrl) { + UriComponentsBuilder authorizationCodeUri = UriComponentsBuilder + .fromPath(baseUrl) + .queryParam(RESPONSE_TYPE, CODE) + .queryParam(CLIENT_ID, clientId) + .queryParam(REDIRECT_URI, redirectUri); if (!scope.isEmpty()) { String scopes = String.join(GlobalConstant.COMMA, scope); - oauthParam.add(SCOPE, scopes); + authorizationCodeUri.queryParam(SCOPE, scopes); } - return oauthParam; + return authorizationCodeUri.toUriString(); } } diff --git a/src/main/java/com/moabam/api/presentation/member/MemberController.java b/src/main/java/com/moabam/api/presentation/member/MemberController.java index 990d2fec..39b73a4d 100644 --- a/src/main/java/com/moabam/api/presentation/member/MemberController.java +++ b/src/main/java/com/moabam/api/presentation/member/MemberController.java @@ -1,19 +1,19 @@ package com.moabam.api.presentation.member; import com.moabam.api.application.auth.AuthenticationService; -import com.moabam.api.dto.auth.AuthorizationCodeIssue; import com.moabam.api.dto.auth.AuthorizationCodeResponse; import com.moabam.global.common.util.GlobalConstant; import com.moabam.global.error.exception.NotFoundException; import com.moabam.global.error.model.ErrorMessage; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; -import org.springframework.http.*; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; +import java.io.IOException; import java.nio.charset.StandardCharsets; @RestController @@ -24,22 +24,17 @@ public class MemberController { private final AuthenticationService authenticationService; @GetMapping - public ResponseEntity socialLogin() { - AuthorizationCodeIssue authorizationCodeRequest = authenticationService.authorizaionCodeParams(); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.SEMI_COLON - + StandardCharsets.UTF_8.name())); - HttpEntity httpEntity = new HttpEntity<>(authorizationCodeRequest.generateQueryParams(), headers); - - return new RestTemplate().exchange(authenticationService.getUrl(), HttpMethod.GET, httpEntity, String.class); + public void socialLogin(HttpServletResponse httpServletResponse) throws IOException { + String authorizationCodeUri = authenticationService.getAuthorizaionCodeUri(); + httpServletResponse.setContentType(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.SEMI_COLON + + StandardCharsets.UTF_8.name()); + httpServletResponse.sendRedirect(authorizationCodeUri); } - @GetMapping("/login") + @GetMapping("/login/kakao/oauth") public void authorizationServerCodeResponse(@ModelAttribute AuthorizationCodeResponse authorizationCodeResponse) { if (authorizationCodeResponse.code().isEmpty()) { throw new NotFoundException(ErrorMessage.LOGIN_FAILED); } - - } } diff --git a/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java b/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java index d6ff30ad..efc65e59 100644 --- a/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java +++ b/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java @@ -9,6 +9,6 @@ public class OAuthParameterNames { public static final String RESPONSE_TYPE = "response_type"; public static final String CODE = "code"; public static final String CLIENT_ID = "client_id"; - public static final String REDIRECT_URL = "redirect_url"; + public static final String REDIRECT_URI = "redirect_uri"; public static final String SCOPE = "scope"; } diff --git a/src/main/java/com/moabam/global/config/OAuthConfig.java b/src/main/java/com/moabam/global/config/OAuthConfig.java index 603df341..2aa40bf5 100644 --- a/src/main/java/com/moabam/global/config/OAuthConfig.java +++ b/src/main/java/com/moabam/global/config/OAuthConfig.java @@ -20,8 +20,8 @@ public record Client( } public record Provider( - String authorizationUrl, - String redirectUrl + String authorizationUri, + String redirectUri ) { } diff --git a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java b/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java index c72c05b8..a785e74b 100644 --- a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java +++ b/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java @@ -1,6 +1,5 @@ package com.moabam.api.application.auth; -import com.moabam.api.dto.auth.AuthorizationCodeIssue; import com.moabam.global.config.OAuthConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -13,7 +12,6 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; @ExtendWith(MockitoExtension.class) class AuthenticationServiceTest { @@ -37,13 +35,9 @@ public void initParams() { @Test void authenticationUrl() { // Given + When - AuthorizationCodeIssue codeRequest = authenticationService.authorizaionCodeParams(); + String authorizaionCodeUri = authenticationService.getAuthorizaionCodeUri(); // Then - assertAll( - () -> assertThat(codeRequest.clientId()).isEqualTo(oauthConfig.client().clientId()), - () -> assertThat(codeRequest.scope()).isEqualTo(oauthConfig.client().scope()), - () -> assertThat(codeRequest.redirectUri()).isEqualTo(oauthConfig.provider().redirectUrl()) - ); + assertThat(authorizaionCodeUri).contains(oauthConfig.client().clientId(), String.join(",", oauthConfig.client().scope()), oauthConfig.provider().redirectUri()); } } From 18f3496d9e184099db78fb075001dfd4e6ffc88b Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 15:17:39 +0900 Subject: [PATCH 08/27] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=ED=8F=AC?= =?UTF-8?q?=EB=A7=B7=20=EC=9E=AC=EC=A0=81=EC=9A=A9=20=EB=B0=8F=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 18 - config/naver-checkstyle-rules.xml | 433 ------------------ config/naver-intellij-formatter-custom.xml | 143 +++--- .../auth/AuthenticationService.java | 18 +- .../com/moabam/api/domain/member/Member.java | 90 ++-- .../com/moabam/api/domain/member/Role.java | 6 +- .../api/dto/auth/AuthorizationCodeIssue.java | 58 +-- .../presentation/member/MemberController.java | 28 +- .../global/common/entity/BaseTimeEntity.java | 23 +- .../global/common/util/DynamicQuery.java | 42 +- .../global/common/util/GlobalConstant.java | 4 +- .../common/util/OAuthParameterNames.java | 10 +- .../global/common/util/UrlGenerator.java | 40 -- .../global/common/util/UrlGeneratorTest.java | 54 --- 14 files changed, 210 insertions(+), 757 deletions(-) delete mode 100644 .editorconfig delete mode 100644 config/naver-checkstyle-rules.xml delete mode 100644 src/main/java/com/moabam/global/common/util/UrlGenerator.java delete mode 100644 src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 855c0c54..00000000 --- a/.editorconfig +++ /dev/null @@ -1,18 +0,0 @@ -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_size = 4 -indent_style = space -insert_final_newline = true -max_line_length = 120 -tab_width = 4 -trim_trailing_whitespace = true - -[*.bat] -end_of_line = crlf - -[*.java] -indent_style = tab -ij_java_blank_lines_after_class_header = 1 diff --git a/config/naver-checkstyle-rules.xml b/config/naver-checkstyle-rules.xml deleted file mode 100644 index dafbb4d1..00000000 --- a/config/naver-checkstyle-rules.xml +++ /dev/null @@ -1,433 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/naver-intellij-formatter-custom.xml b/config/naver-intellij-formatter-custom.xml index 26f28954..dc4c4a2e 100644 --- a/config/naver-intellij-formatter-custom.xml +++ b/config/naver-intellij-formatter-custom.xml @@ -1,74 +1,75 @@ - - - \ No newline at end of file diff --git a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java index 11095b38..bebf5bce 100644 --- a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java +++ b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java @@ -9,14 +9,14 @@ @RequiredArgsConstructor public class AuthenticationService { - private final OAuthConfig oAuthConfig; + private final OAuthConfig oAuthConfig; - public String getAuthorizaionCodeUri() { - return AuthorizationCodeIssue.builder() - .clientId(oAuthConfig.client().clientId()) - .redirectUri(oAuthConfig.provider().redirectUri()) - .scope(oAuthConfig.client().scope()) - .build() - .generateQueryParamsWith(oAuthConfig.provider().authorizationUri()); - } + public String getAuthorizaionCodeUri() { + return AuthorizationCodeIssue.builder() + .clientId(oAuthConfig.client().clientId()) + .redirectUri(oAuthConfig.provider().redirectUri()) + .scope(oAuthConfig.client().scope()) + .build() + .generateQueryParamsWith(oAuthConfig.provider().authorizationUri()); + } } diff --git a/src/main/java/com/moabam/api/domain/member/Member.java b/src/main/java/com/moabam/api/domain/member/Member.java index 3964b546..fab9bd28 100644 --- a/src/main/java/com/moabam/api/domain/member/Member.java +++ b/src/main/java/com/moabam/api/domain/member/Member.java @@ -20,63 +20,63 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Member extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "member_id") - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_id") + private Long id; - @Column(name = "social_id", nullable = false, unique = true) - private String socialId; + @Column(name = "social_id", nullable = false, unique = true) + private String socialId; - @Column(name = "nickname", nullable = false, unique = true) - private String nickname; + @Column(name = "nickname", nullable = false, unique = true) + private String nickname; - @Column(name = "intro") - private String intro; + @Column(name = "intro") + private String intro; - @Column(name = "profile_image", nullable = false) - private String profileImage; + @Column(name = "profile_image", nullable = false) + private String profileImage; - @Column(name = "total_certify_count", nullable = false) - @ColumnDefault("0") - private long totalCertifyCount; + @Column(name = "total_certify_count", nullable = false) + @ColumnDefault("0") + private long totalCertifyCount; - @Column(name = "report_count", nullable = false) - @ColumnDefault("0") - private int reportCount; + @Column(name = "report_count", nullable = false) + @ColumnDefault("0") + private int reportCount; - @Column(name = "current_night_count", nullable = false) - @ColumnDefault("0") - private int currentNightCount; + @Column(name = "current_night_count", nullable = false) + @ColumnDefault("0") + private int currentNightCount; - @Column(name = "current_morning_count", nullable = false) - @ColumnDefault("0") - private int currentMorningCount; + @Column(name = "current_morning_count", nullable = false) + @ColumnDefault("0") + private int currentMorningCount; - @Column(name = "morning_bug", nullable = false) - @ColumnDefault("0") - private int morningBug; + @Column(name = "morning_bug", nullable = false) + @ColumnDefault("0") + private int morningBug; - @Column(name = "night_bug", nullable = false) - @ColumnDefault("0") - private int nightBug; + @Column(name = "night_bug", nullable = false) + @ColumnDefault("0") + private int nightBug; - @Column(name = "golden_bug", nullable = false) - @ColumnDefault("0") - private int goldenBug; + @Column(name = "golden_bug", nullable = false) + @ColumnDefault("0") + private int goldenBug; - @Enumerated(EnumType.STRING) - @Column(name = "role", nullable = false) - private Role role; + @Enumerated(EnumType.STRING) + @Column(name = "role", nullable = false) + private Role role; - @Column(name = "deleted_at") - private LocalDateTime deletedAt; + @Column(name = "deleted_at") + private LocalDateTime deletedAt; - @Builder - private Member(String socialId, String nickname, String profileImage) { - this.socialId = requireNonNull(socialId); - this.nickname = requireNonNull(nickname); - this.profileImage = requireNonNullElse(profileImage, BaseImageUrl.PROFILE_URL.getUrl()); - this.role = Role.USER; - } + @Builder + private Member(String socialId, String nickname, String profileImage) { + this.socialId = requireNonNull(socialId); + this.nickname = requireNonNull(nickname); + this.profileImage = requireNonNullElse(profileImage, BaseImageUrl.PROFILE_URL.getUrl()); + this.role = Role.USER; + } } diff --git a/src/main/java/com/moabam/api/domain/member/Role.java b/src/main/java/com/moabam/api/domain/member/Role.java index 3e8c0c95..35d25351 100644 --- a/src/main/java/com/moabam/api/domain/member/Role.java +++ b/src/main/java/com/moabam/api/domain/member/Role.java @@ -1,7 +1,7 @@ package com.moabam.api.domain.member; public enum Role { - USER, - BLACK, - ADMIN + USER, + BLACK, + ADMIN } diff --git a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java index 17ce3d63..58ff0c15 100644 --- a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java +++ b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java @@ -9,35 +9,35 @@ import static com.moabam.global.common.util.OAuthParameterNames.*; public record AuthorizationCodeIssue( - String clientId, - String redirectUri, - String responseType, - List scope, - String state + String clientId, + String redirectUri, + String responseType, + List scope, + String state ) { - @Builder - public AuthorizationCodeIssue(String clientId, String redirectUri, String responseType, List scope, - String state) { - this.clientId = clientId; - this.redirectUri = redirectUri; - this.responseType = responseType; - this.scope = scope; - this.state = state; - } - - public String generateQueryParamsWith(String baseUrl) { - UriComponentsBuilder authorizationCodeUri = UriComponentsBuilder - .fromPath(baseUrl) - .queryParam(RESPONSE_TYPE, CODE) - .queryParam(CLIENT_ID, clientId) - .queryParam(REDIRECT_URI, redirectUri); - - if (!scope.isEmpty()) { - String scopes = String.join(GlobalConstant.COMMA, scope); - authorizationCodeUri.queryParam(SCOPE, scopes); - } - - return authorizationCodeUri.toUriString(); - } + @Builder + public AuthorizationCodeIssue(String clientId, String redirectUri, String responseType, List scope, + String state) { + this.clientId = clientId; + this.redirectUri = redirectUri; + this.responseType = responseType; + this.scope = scope; + this.state = state; + } + + public String generateQueryParamsWith(String baseUrl) { + UriComponentsBuilder authorizationCodeUri = UriComponentsBuilder + .fromPath(baseUrl) + .queryParam(RESPONSE_TYPE, CODE) + .queryParam(CLIENT_ID, clientId) + .queryParam(REDIRECT_URI, redirectUri); + + if (!scope.isEmpty()) { + String scopes = String.join(GlobalConstant.COMMA, scope); + authorizationCodeUri.queryParam(SCOPE, scopes); + } + + return authorizationCodeUri.toUriString(); + } } diff --git a/src/main/java/com/moabam/api/presentation/member/MemberController.java b/src/main/java/com/moabam/api/presentation/member/MemberController.java index 39b73a4d..283f5624 100644 --- a/src/main/java/com/moabam/api/presentation/member/MemberController.java +++ b/src/main/java/com/moabam/api/presentation/member/MemberController.java @@ -21,20 +21,20 @@ @RequiredArgsConstructor public class MemberController { - private final AuthenticationService authenticationService; + private final AuthenticationService authenticationService; - @GetMapping - public void socialLogin(HttpServletResponse httpServletResponse) throws IOException { - String authorizationCodeUri = authenticationService.getAuthorizaionCodeUri(); - httpServletResponse.setContentType(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.SEMI_COLON - + StandardCharsets.UTF_8.name()); - httpServletResponse.sendRedirect(authorizationCodeUri); - } + @GetMapping + public void socialLogin(HttpServletResponse httpServletResponse) throws IOException { + String authorizationCodeUri = authenticationService.getAuthorizaionCodeUri(); + httpServletResponse.setContentType(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.SEMI_COLON + + StandardCharsets.UTF_8.name()); + httpServletResponse.sendRedirect(authorizationCodeUri); + } - @GetMapping("/login/kakao/oauth") - public void authorizationServerCodeResponse(@ModelAttribute AuthorizationCodeResponse authorizationCodeResponse) { - if (authorizationCodeResponse.code().isEmpty()) { - throw new NotFoundException(ErrorMessage.LOGIN_FAILED); - } - } + @GetMapping("/login/kakao/oauth") + public void authorizationServerCodeResponse(@ModelAttribute AuthorizationCodeResponse authorizationCodeResponse) { + if (authorizationCodeResponse.code().isEmpty()) { + throw new NotFoundException(ErrorMessage.LOGIN_FAILED); + } + } } diff --git a/src/main/java/com/moabam/global/common/entity/BaseTimeEntity.java b/src/main/java/com/moabam/global/common/entity/BaseTimeEntity.java index 07b008fa..e6522ba7 100644 --- a/src/main/java/com/moabam/global/common/entity/BaseTimeEntity.java +++ b/src/main/java/com/moabam/global/common/entity/BaseTimeEntity.java @@ -1,17 +1,16 @@ package com.moabam.global.common.entity; -import java.time.LocalDateTime; - -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; @Getter @MappedSuperclass @@ -19,11 +18,11 @@ @EntityListeners(AuditingEntityListener.class) public abstract class BaseTimeEntity { - @CreatedDate - @Column(name = "created_at", updatable = false, nullable = false) - private LocalDateTime createdAt; + @CreatedDate + @Column(name = "created_at", updatable = false, nullable = false) + private LocalDateTime createdAt; - @LastModifiedDate - @Column(name = "updated_at") - private LocalDateTime updatedAt; + @LastModifiedDate + @Column(name = "updated_at") + private LocalDateTime updatedAt; } diff --git a/src/main/java/com/moabam/global/common/util/DynamicQuery.java b/src/main/java/com/moabam/global/common/util/DynamicQuery.java index 31fa8bb9..a6fef2af 100644 --- a/src/main/java/com/moabam/global/common/util/DynamicQuery.java +++ b/src/main/java/com/moabam/global/common/util/DynamicQuery.java @@ -1,37 +1,35 @@ package com.moabam.global.common.util; +import com.querydsl.core.types.dsl.BooleanExpression; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import org.springframework.util.CollectionUtils; + import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.function.Function; -import org.springframework.util.CollectionUtils; - -import com.querydsl.core.types.dsl.BooleanExpression; - -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public class DynamicQuery { - public static BooleanExpression generateEq(T value, Function function) { - if (Objects.isNull(value)) { - return null; - } + public static BooleanExpression generateEq(T value, Function function) { + if (Objects.isNull(value)) { + return null; + } - return function.apply(value); - } + return function.apply(value); + } - public static BooleanExpression filterCondition(T condition, Function function) { - T tempCondition = condition; + public static BooleanExpression filterCondition(T condition, Function function) { + T tempCondition = condition; - if (tempCondition instanceof List c && CollectionUtils.isEmpty(c)) { - tempCondition = null; - } + if (tempCondition instanceof List c && CollectionUtils.isEmpty(c)) { + tempCondition = null; + } - return Optional.ofNullable(tempCondition) - .map(function) - .orElse(null); - } + return Optional.ofNullable(tempCondition) + .map(function) + .orElse(null); + } } diff --git a/src/main/java/com/moabam/global/common/util/GlobalConstant.java b/src/main/java/com/moabam/global/common/util/GlobalConstant.java index 419d2615..bf55b0fe 100644 --- a/src/main/java/com/moabam/global/common/util/GlobalConstant.java +++ b/src/main/java/com/moabam/global/common/util/GlobalConstant.java @@ -2,6 +2,6 @@ public class GlobalConstant { - public static final String COMMA = ","; - public static final String SEMI_COLON = ";"; + public static final String COMMA = ","; + public static final String SEMI_COLON = ";"; } diff --git a/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java b/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java index efc65e59..d7899564 100644 --- a/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java +++ b/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java @@ -6,9 +6,9 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class OAuthParameterNames { - public static final String RESPONSE_TYPE = "response_type"; - public static final String CODE = "code"; - public static final String CLIENT_ID = "client_id"; - public static final String REDIRECT_URI = "redirect_uri"; - public static final String SCOPE = "scope"; + public static final String RESPONSE_TYPE = "response_type"; + public static final String CODE = "code"; + public static final String CLIENT_ID = "client_id"; + public static final String REDIRECT_URI = "redirect_uri"; + public static final String SCOPE = "scope"; } diff --git a/src/main/java/com/moabam/global/common/util/UrlGenerator.java b/src/main/java/com/moabam/global/common/util/UrlGenerator.java deleted file mode 100644 index 3db1521d..00000000 --- a/src/main/java/com/moabam/global/common/util/UrlGenerator.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.moabam.global.common.util; - -import lombok.AccessLevel; -import lombok.Builder; -import lombok.NoArgsConstructor; -import lombok.Singular; - -import java.util.Map; - -import static java.util.Objects.requireNonNull; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UrlGenerator { - - private static final String QUERY_BEGIN = "?"; - private static final String QUERY_SEPERATE = "&"; - private static final String QUERY_MATCH = "="; - - private String baseUrl; - - private Map parameters; - - @Builder - private UrlGenerator(String baseUrl, @Singular("parameter") Map parameters) { - this.baseUrl = requireNonNull(baseUrl); - this.parameters = parameters; - } - - public String generateUrl() { - StringBuilder url = new StringBuilder(baseUrl); - - url.append(QUERY_BEGIN); - parameters.forEach((key, value) -> - url.append(key).append(QUERY_MATCH).append(value).append(QUERY_SEPERATE)); - url.deleteCharAt(url.length() - 1); - - return url.toString(); - } - -} diff --git a/src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java b/src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java deleted file mode 100644 index 3a8679c3..00000000 --- a/src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.moabam.global.common.util; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.*; - -class UrlGeneratorTest { - - private static final String BASE_URL = "http://localhost:8080/auth"; - private static final String RESPONSE_TYPE = "response-type"; - private static final String CODE = "code"; - - @DisplayName("베이스 URL이 없으면 생성 실패") - @Test - void create_url_failBy_no_base_url() { - // When + Then - assertThatThrownBy(UrlGenerator.builder()::build) - .isInstanceOf(NullPointerException.class); - } - - @DisplayName("URL 생성 성공") - @Test - void create_url_success() { - assertThatNoException().isThrownBy(() -> { - // Given - UrlGenerator urlGenerator = UrlGenerator.builder() - .baseUrl(BASE_URL).build(); - - // When - String url = urlGenerator.generateUrl(); - - // Then - assertThat(url).isEqualTo(BASE_URL); - }); - } - - @DisplayName("쿼리가 포함된 url 생성 성공") - @Test - void create_query_url_success() { - assertThatNoException().isThrownBy(() -> { - // Given - UrlGenerator urlGenerator = UrlGenerator.builder() - .baseUrl(BASE_URL) - .parameter(RESPONSE_TYPE, CODE).build(); - - // When - String url = urlGenerator.generateUrl(); - - // Then - assertThat(url).isEqualTo(BASE_URL + "?" + RESPONSE_TYPE + "=" + CODE); - }); - } -} From a1e75337a96f066d3429b682573b7c5ec8f744cb Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 15:30:42 +0900 Subject: [PATCH 09/27] =?UTF-8?q?chore:=20config=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config b/src/main/resources/config index 8bc59e64..600a2467 160000 --- a/src/main/resources/config +++ b/src/main/resources/config @@ -1 +1 @@ -Subproject commit 8bc59e6455ce1220e00acf676849951cbd935373 +Subproject commit 600a2467b779690dd9c24f172425832b0d5eb87b From b5163eb2404926773b9a1604a495a5b73b8aef16 Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 17:34:59 +0900 Subject: [PATCH 10/27] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=20=EC=9E=AC=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/AuthenticationService.java | 22 ++-- .../com/moabam/api/domain/member/Member.java | 112 ++++++++++-------- .../com/moabam/api/domain/member/Role.java | 7 +- .../api/dto/auth/AuthorizationCodeIssue.java | 70 +++++------ .../presentation/member/MemberController.java | 39 +++--- .../global/common/util/DynamicQuery.java | 42 +++---- .../global/common/util/GlobalConstant.java | 8 +- .../common/util/OAuthParameterNames.java | 10 +- .../com/moabam/global/config/OAuthConfig.java | 4 +- .../auth/AuthenticationServiceTest.java | 14 ++- .../moabam/api/domain/member/MemberTest.java | 7 +- .../member/MemberControllerTest.java | 67 +++++++++++ 12 files changed, 241 insertions(+), 161 deletions(-) create mode 100644 src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java diff --git a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java index bebf5bce..3688b540 100644 --- a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java +++ b/src/main/java/com/moabam/api/application/auth/AuthenticationService.java @@ -1,22 +1,24 @@ package com.moabam.api.application.auth; +import org.springframework.stereotype.Service; + import com.moabam.api.dto.auth.AuthorizationCodeIssue; import com.moabam.global.config.OAuthConfig; + import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor public class AuthenticationService { - private final OAuthConfig oAuthConfig; + private final OAuthConfig oAuthConfig; - public String getAuthorizaionCodeUri() { - return AuthorizationCodeIssue.builder() - .clientId(oAuthConfig.client().clientId()) - .redirectUri(oAuthConfig.provider().redirectUri()) - .scope(oAuthConfig.client().scope()) - .build() - .generateQueryParamsWith(oAuthConfig.provider().authorizationUri()); - } + public String getAuthorizaionCodeUri() { + return AuthorizationCodeIssue.builder() + .clientId(oAuthConfig.client().clientId()) + .redirectUri(oAuthConfig.provider().redirectUri()) + .scope(oAuthConfig.client().scope()) + .build() + .generateQueryParamsWith(oAuthConfig.provider().authorizationUri()); + } } diff --git a/src/main/java/com/moabam/api/domain/member/Member.java b/src/main/java/com/moabam/api/domain/member/Member.java index fab9bd28..58440858 100644 --- a/src/main/java/com/moabam/api/domain/member/Member.java +++ b/src/main/java/com/moabam/api/domain/member/Member.java @@ -1,18 +1,26 @@ package com.moabam.api.domain.member; +import static java.util.Objects.*; + +import java.time.LocalDateTime; + +import org.hibernate.annotations.ColumnDefault; + import com.moabam.global.common.entity.BaseTimeEntity; import com.moabam.global.common.util.BaseImageUrl; -import jakarta.persistence.*; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.hibernate.annotations.ColumnDefault; - -import java.time.LocalDateTime; - -import static java.util.Objects.requireNonNull; -import static java.util.Objects.requireNonNullElse; @Getter @Entity @@ -20,63 +28,63 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Member extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "member_id") - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_id") + private Long id; - @Column(name = "social_id", nullable = false, unique = true) - private String socialId; + @Column(name = "social_id", nullable = false, unique = true) + private String socialId; - @Column(name = "nickname", nullable = false, unique = true) - private String nickname; + @Column(name = "nickname", nullable = false, unique = true) + private String nickname; - @Column(name = "intro") - private String intro; + @Column(name = "intro") + private String intro; - @Column(name = "profile_image", nullable = false) - private String profileImage; + @Column(name = "profile_image", nullable = false) + private String profileImage; - @Column(name = "total_certify_count", nullable = false) - @ColumnDefault("0") - private long totalCertifyCount; + @Column(name = "total_certify_count", nullable = false) + @ColumnDefault("0") + private long totalCertifyCount; - @Column(name = "report_count", nullable = false) - @ColumnDefault("0") - private int reportCount; + @Column(name = "report_count", nullable = false) + @ColumnDefault("0") + private int reportCount; - @Column(name = "current_night_count", nullable = false) - @ColumnDefault("0") - private int currentNightCount; + @Column(name = "current_night_count", nullable = false) + @ColumnDefault("0") + private int currentNightCount; - @Column(name = "current_morning_count", nullable = false) - @ColumnDefault("0") - private int currentMorningCount; + @Column(name = "current_morning_count", nullable = false) + @ColumnDefault("0") + private int currentMorningCount; - @Column(name = "morning_bug", nullable = false) - @ColumnDefault("0") - private int morningBug; + @Column(name = "morning_bug", nullable = false) + @ColumnDefault("0") + private int morningBug; - @Column(name = "night_bug", nullable = false) - @ColumnDefault("0") - private int nightBug; + @Column(name = "night_bug", nullable = false) + @ColumnDefault("0") + private int nightBug; - @Column(name = "golden_bug", nullable = false) - @ColumnDefault("0") - private int goldenBug; + @Column(name = "golden_bug", nullable = false) + @ColumnDefault("0") + private int goldenBug; - @Enumerated(EnumType.STRING) - @Column(name = "role", nullable = false) - private Role role; + @Enumerated(EnumType.STRING) + @Column(name = "role", nullable = false) + private Role role; - @Column(name = "deleted_at") - private LocalDateTime deletedAt; + @Column(name = "deleted_at") + private LocalDateTime deletedAt; - @Builder - private Member(String socialId, String nickname, String profileImage) { - this.socialId = requireNonNull(socialId); - this.nickname = requireNonNull(nickname); - this.profileImage = requireNonNullElse(profileImage, BaseImageUrl.PROFILE_URL.getUrl()); - this.role = Role.USER; - } + @Builder + private Member(String socialId, String nickname, String profileImage) { + this.socialId = requireNonNull(socialId); + this.nickname = requireNonNull(nickname); + this.profileImage = requireNonNullElse(profileImage, BaseImageUrl.PROFILE_URL.getUrl()); + this.role = Role.USER; + } } diff --git a/src/main/java/com/moabam/api/domain/member/Role.java b/src/main/java/com/moabam/api/domain/member/Role.java index 35d25351..b7e80810 100644 --- a/src/main/java/com/moabam/api/domain/member/Role.java +++ b/src/main/java/com/moabam/api/domain/member/Role.java @@ -1,7 +1,8 @@ package com.moabam.api.domain.member; public enum Role { - USER, - BLACK, - ADMIN + + USER, + BLACK, + ADMIN } diff --git a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java index 58ff0c15..375047e3 100644 --- a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java +++ b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java @@ -1,43 +1,47 @@ package com.moabam.api.dto.auth; -import com.moabam.global.common.util.GlobalConstant; -import lombok.Builder; -import org.springframework.web.util.UriComponentsBuilder; +import static com.moabam.global.common.util.OAuthParameterNames.*; +import java.time.LocalDateTime; import java.util.List; -import static com.moabam.global.common.util.OAuthParameterNames.*; +import org.springframework.web.util.UriComponentsBuilder; + +import com.moabam.global.common.util.GlobalConstant; + +import lombok.Builder; public record AuthorizationCodeIssue( - String clientId, - String redirectUri, - String responseType, - List scope, - String state + String clientId, + String redirectUri, + String responseType, + List scope, + String state ) { - @Builder - public AuthorizationCodeIssue(String clientId, String redirectUri, String responseType, List scope, - String state) { - this.clientId = clientId; - this.redirectUri = redirectUri; - this.responseType = responseType; - this.scope = scope; - this.state = state; - } - - public String generateQueryParamsWith(String baseUrl) { - UriComponentsBuilder authorizationCodeUri = UriComponentsBuilder - .fromPath(baseUrl) - .queryParam(RESPONSE_TYPE, CODE) - .queryParam(CLIENT_ID, clientId) - .queryParam(REDIRECT_URI, redirectUri); - - if (!scope.isEmpty()) { - String scopes = String.join(GlobalConstant.COMMA, scope); - authorizationCodeUri.queryParam(SCOPE, scopes); - } - - return authorizationCodeUri.toUriString(); - } + @Builder + public AuthorizationCodeIssue(String clientId, String redirectUri, String responseType, List scope, + String state) { + this.clientId = clientId; + this.redirectUri = redirectUri; + this.responseType = responseType; + this.scope = scope; + this.state = state; + } + + public String generateQueryParamsWith(String baseUrl) { + UriComponentsBuilder authorizationCodeUri = UriComponentsBuilder + .fromPath(baseUrl) + .queryParam(RESPONSE_TYPE, CODE) + .queryParam(CLIENT_ID, clientId) + .queryParam(REDIRECT_URI, redirectUri); + + if (!scope.isEmpty()) { + String scopes = String.join(GlobalConstant.COMMA, scope); + authorizationCodeUri.queryParam(SCOPE, scopes); + } + LocalDateTime dateTime; + dateTime.is + return authorizationCodeUri.toUriString(); + } } diff --git a/src/main/java/com/moabam/api/presentation/member/MemberController.java b/src/main/java/com/moabam/api/presentation/member/MemberController.java index 283f5624..703b415a 100644 --- a/src/main/java/com/moabam/api/presentation/member/MemberController.java +++ b/src/main/java/com/moabam/api/presentation/member/MemberController.java @@ -1,40 +1,29 @@ package com.moabam.api.presentation.member; -import com.moabam.api.application.auth.AuthenticationService; -import com.moabam.api.dto.auth.AuthorizationCodeResponse; -import com.moabam.global.common.util.GlobalConstant; -import com.moabam.global.error.exception.NotFoundException; -import com.moabam.global.error.model.ErrorMessage; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; +import java.io.IOException; + import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.io.IOException; -import java.nio.charset.StandardCharsets; +import com.moabam.api.application.auth.AuthenticationService; +import com.moabam.global.common.util.GlobalConstant; + +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; @RestController @RequestMapping("/members") @RequiredArgsConstructor public class MemberController { - private final AuthenticationService authenticationService; - - @GetMapping - public void socialLogin(HttpServletResponse httpServletResponse) throws IOException { - String authorizationCodeUri = authenticationService.getAuthorizaionCodeUri(); - httpServletResponse.setContentType(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.SEMI_COLON - + StandardCharsets.UTF_8.name()); - httpServletResponse.sendRedirect(authorizationCodeUri); - } + private final AuthenticationService authenticationService; - @GetMapping("/login/kakao/oauth") - public void authorizationServerCodeResponse(@ModelAttribute AuthorizationCodeResponse authorizationCodeResponse) { - if (authorizationCodeResponse.code().isEmpty()) { - throw new NotFoundException(ErrorMessage.LOGIN_FAILED); - } - } + @GetMapping + public void socialLogin(HttpServletResponse httpServletResponse) throws IOException { + String authorizationCodeUri = authenticationService.getAuthorizaionCodeUri(); + httpServletResponse.setContentType(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.CHARSET_UTF_8); + httpServletResponse.sendRedirect(authorizationCodeUri); + } } diff --git a/src/main/java/com/moabam/global/common/util/DynamicQuery.java b/src/main/java/com/moabam/global/common/util/DynamicQuery.java index a6fef2af..31fa8bb9 100644 --- a/src/main/java/com/moabam/global/common/util/DynamicQuery.java +++ b/src/main/java/com/moabam/global/common/util/DynamicQuery.java @@ -1,35 +1,37 @@ package com.moabam.global.common.util; -import com.querydsl.core.types.dsl.BooleanExpression; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import org.springframework.util.CollectionUtils; - import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.function.Function; +import org.springframework.util.CollectionUtils; + +import com.querydsl.core.types.dsl.BooleanExpression; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public class DynamicQuery { - public static BooleanExpression generateEq(T value, Function function) { - if (Objects.isNull(value)) { - return null; - } + public static BooleanExpression generateEq(T value, Function function) { + if (Objects.isNull(value)) { + return null; + } - return function.apply(value); - } + return function.apply(value); + } - public static BooleanExpression filterCondition(T condition, Function function) { - T tempCondition = condition; + public static BooleanExpression filterCondition(T condition, Function function) { + T tempCondition = condition; - if (tempCondition instanceof List c && CollectionUtils.isEmpty(c)) { - tempCondition = null; - } + if (tempCondition instanceof List c && CollectionUtils.isEmpty(c)) { + tempCondition = null; + } - return Optional.ofNullable(tempCondition) - .map(function) - .orElse(null); - } + return Optional.ofNullable(tempCondition) + .map(function) + .orElse(null); + } } diff --git a/src/main/java/com/moabam/global/common/util/GlobalConstant.java b/src/main/java/com/moabam/global/common/util/GlobalConstant.java index bf55b0fe..5b87cd58 100644 --- a/src/main/java/com/moabam/global/common/util/GlobalConstant.java +++ b/src/main/java/com/moabam/global/common/util/GlobalConstant.java @@ -1,7 +1,11 @@ package com.moabam.global.common.util; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class GlobalConstant { - public static final String COMMA = ","; - public static final String SEMI_COLON = ";"; + public static final String COMMA = ","; + public static final String CHARSET_UTF_8 = ";charset=UTF-8"; } diff --git a/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java b/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java index d7899564..efc65e59 100644 --- a/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java +++ b/src/main/java/com/moabam/global/common/util/OAuthParameterNames.java @@ -6,9 +6,9 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class OAuthParameterNames { - public static final String RESPONSE_TYPE = "response_type"; - public static final String CODE = "code"; - public static final String CLIENT_ID = "client_id"; - public static final String REDIRECT_URI = "redirect_uri"; - public static final String SCOPE = "scope"; + public static final String RESPONSE_TYPE = "response_type"; + public static final String CODE = "code"; + public static final String CLIENT_ID = "client_id"; + public static final String REDIRECT_URI = "redirect_uri"; + public static final String SCOPE = "scope"; } diff --git a/src/main/java/com/moabam/global/config/OAuthConfig.java b/src/main/java/com/moabam/global/config/OAuthConfig.java index 2aa40bf5..cff7f45b 100644 --- a/src/main/java/com/moabam/global/config/OAuthConfig.java +++ b/src/main/java/com/moabam/global/config/OAuthConfig.java @@ -1,9 +1,9 @@ package com.moabam.global.config; -import org.springframework.boot.context.properties.ConfigurationProperties; - import java.util.List; +import org.springframework.boot.context.properties.ConfigurationProperties; + @ConfigurationProperties(prefix = "oauth2") public record OAuthConfig( Provider provider, diff --git a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java b/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java index a785e74b..6f29348e 100644 --- a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java +++ b/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java @@ -1,6 +1,9 @@ package com.moabam.api.application.auth; -import com.moabam.global.config.OAuthConfig; +import static org.assertj.core.api.Assertions.*; + +import java.util.List; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -9,9 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.test.util.ReflectionTestUtils; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; +import com.moabam.global.config.OAuthConfig; @ExtendWith(MockitoExtension.class) class AuthenticationServiceTest { @@ -31,13 +32,14 @@ public void initParams() { ReflectionTestUtils.setField(authenticationService, "oAuthConfig", oauthConfig); } - @DisplayName("") + @DisplayName("authentication code Url 생성 성공") @Test void authenticationUrl() { // Given + When String authorizaionCodeUri = authenticationService.getAuthorizaionCodeUri(); // Then - assertThat(authorizaionCodeUri).contains(oauthConfig.client().clientId(), String.join(",", oauthConfig.client().scope()), oauthConfig.provider().redirectUri()); + assertThat(authorizaionCodeUri).contains(oauthConfig.client().clientId(), + String.join(",", oauthConfig.client().scope()), oauthConfig.provider().redirectUri()); } } diff --git a/src/test/java/com/moabam/api/domain/member/MemberTest.java b/src/test/java/com/moabam/api/domain/member/MemberTest.java index 2ef8936c..caa56681 100644 --- a/src/test/java/com/moabam/api/domain/member/MemberTest.java +++ b/src/test/java/com/moabam/api/domain/member/MemberTest.java @@ -1,11 +1,12 @@ package com.moabam.api.domain.member; -import com.moabam.global.common.util.BaseImageUrl; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertAll; +import com.moabam.global.common.util.BaseImageUrl; class MemberTest { diff --git a/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java b/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java new file mode 100644 index 00000000..1d7542c5 --- /dev/null +++ b/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java @@ -0,0 +1,67 @@ +package com.moabam.api.presentation.member; + +import static com.moabam.global.common.util.OAuthParameterNames.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.web.util.UriComponentsBuilder; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.moabam.api.application.auth.AuthenticationService; +import com.moabam.global.common.util.GlobalConstant; +import com.moabam.global.config.OAuthConfig; + +@SpringBootTest( + properties = { + "oauth2.provider.authorization-uri=https://kauth.kakao.com/oauth/authorize", + "oauth2.provider.redirect-uri=http://localhost:8080/members/login/kakao/oauth", + "oauth2.client.client-id=testtesttesttesttesttesttesttesttest", + "oauth2.client.authorization-grant-type=authorization_code", + "oauth2.client.scope=profile_nickname,profile_image" + } +) +@AutoConfigureMockMvc +class MemberControllerTest { + + @Autowired + MockMvc mockMvc; + + @Autowired + ObjectMapper objectMapper; + + @Autowired + AuthenticationService authenticationService; + + @Autowired + OAuthConfig oAuthConfig; + + @DisplayName("인가 코드 받기 위한 로그인 페이지 요청") + @Test + void authorization_code_request_success() throws Exception { + // given + String uri = UriComponentsBuilder + .fromPath(oAuthConfig.provider().authorizationUri()) + .queryParam(RESPONSE_TYPE, "code") + .queryParam(CLIENT_ID, oAuthConfig.client().clientId()) + .queryParam(REDIRECT_URI, oAuthConfig.provider().redirectUri()) + .queryParam(SCOPE, String.join(",", oAuthConfig.client().scope())) + .toUriString(); + + // when + ResultActions result = mockMvc.perform(get("/members")); + + // then + result.andExpect(status().is3xxRedirection()) + .andExpect(header().string("Content-type", + MediaType.APPLICATION_FORM_URLENCODED_VALUE + GlobalConstant.CHARSET_UTF_8)) + .andExpect(redirectedUrl(uri)); + } +} \ No newline at end of file From 9c10d45fe03a59c81eef3229ffa3bafa0a5c7004 Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 17:42:30 +0900 Subject: [PATCH 11/27] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/moabam/MoabamServerApplication.java | 5 ----- .../java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java | 4 +--- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/com/moabam/MoabamServerApplication.java b/src/main/java/com/moabam/MoabamServerApplication.java index 95ca95aa..e2dbce1d 100644 --- a/src/main/java/com/moabam/MoabamServerApplication.java +++ b/src/main/java/com/moabam/MoabamServerApplication.java @@ -1,7 +1,5 @@ package com.moabam; -import com.moabam.global.config.OAuthConfig; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; @@ -10,9 +8,6 @@ @SpringBootApplication public class MoabamServerApplication { - @Autowired - OAuthConfig oAuthConfig; - public static void main(String[] args) { SpringApplication.run(MoabamServerApplication.class, args); } diff --git a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java index 375047e3..80a7ec23 100644 --- a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java +++ b/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java @@ -2,7 +2,6 @@ import static com.moabam.global.common.util.OAuthParameterNames.*; -import java.time.LocalDateTime; import java.util.List; import org.springframework.web.util.UriComponentsBuilder; @@ -40,8 +39,7 @@ public String generateQueryParamsWith(String baseUrl) { String scopes = String.join(GlobalConstant.COMMA, scope); authorizationCodeUri.queryParam(SCOPE, scopes); } - LocalDateTime dateTime; - dateTime.is + return authorizationCodeUri.toUriString(); } } From 92cb5311792d18019d043d08bff0c086f91f073a Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 18:21:52 +0900 Subject: [PATCH 12/27] =?UTF-8?q?refactor:=20CRLF=20->=20LF=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/moabam/api/domain/member/Role.java | 2 +- .../global/common/entity/BaseTimeEntity.java | 23 ++++++++++--------- .../global/common/util/BaseImageUrl.java | 1 + .../member/MemberControllerTest.java | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/moabam/api/domain/member/Role.java b/src/main/java/com/moabam/api/domain/member/Role.java index b7e80810..b168314b 100644 --- a/src/main/java/com/moabam/api/domain/member/Role.java +++ b/src/main/java/com/moabam/api/domain/member/Role.java @@ -3,6 +3,6 @@ public enum Role { USER, - BLACK, + @SuppressWarnings("checkstyle:JavadocVariable") BLACK, ADMIN } diff --git a/src/main/java/com/moabam/global/common/entity/BaseTimeEntity.java b/src/main/java/com/moabam/global/common/entity/BaseTimeEntity.java index e6522ba7..07b008fa 100644 --- a/src/main/java/com/moabam/global/common/entity/BaseTimeEntity.java +++ b/src/main/java/com/moabam/global/common/entity/BaseTimeEntity.java @@ -1,16 +1,17 @@ package com.moabam.global.common.entity; +import java.time.LocalDateTime; + +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import java.time.LocalDateTime; @Getter @MappedSuperclass @@ -18,11 +19,11 @@ @EntityListeners(AuditingEntityListener.class) public abstract class BaseTimeEntity { - @CreatedDate - @Column(name = "created_at", updatable = false, nullable = false) - private LocalDateTime createdAt; + @CreatedDate + @Column(name = "created_at", updatable = false, nullable = false) + private LocalDateTime createdAt; - @LastModifiedDate - @Column(name = "updated_at") - private LocalDateTime updatedAt; + @LastModifiedDate + @Column(name = "updated_at") + private LocalDateTime updatedAt; } diff --git a/src/main/java/com/moabam/global/common/util/BaseImageUrl.java b/src/main/java/com/moabam/global/common/util/BaseImageUrl.java index 81196bc1..8a302328 100644 --- a/src/main/java/com/moabam/global/common/util/BaseImageUrl.java +++ b/src/main/java/com/moabam/global/common/util/BaseImageUrl.java @@ -4,6 +4,7 @@ @Getter public enum BaseImageUrl { + PROFILE_URL("/profile/baseUrl"); private String url; diff --git a/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java b/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java index 1d7542c5..bf09a503 100644 --- a/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java @@ -64,4 +64,4 @@ void authorization_code_request_success() throws Exception { MediaType.APPLICATION_FORM_URLENCODED_VALUE + GlobalConstant.CHARSET_UTF_8)) .andExpect(redirectedUrl(uri)); } -} \ No newline at end of file +} From a7291a8e32dc3557eaf51625590d39ca43631f5d Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 20:05:33 +0900 Subject: [PATCH 13/27] =?UTF-8?q?fix:=20config=20=EC=BB=A4=EB=B0=8B,=20con?= =?UTF-8?q?fig=20=EC=B5=9C=EA=B7=BC=20=EC=BB=A4=EB=B0=8B=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config b/src/main/resources/config index 600a2467..90404393 160000 --- a/src/main/resources/config +++ b/src/main/resources/config @@ -1 +1 @@ -Subproject commit 600a2467b779690dd9c24f172425832b0d5eb87b +Subproject commit 90404393aafb50e5650b81f6b67b69adc825e938 From 47ef3ea7a610344a223caed56e71d3ee59779401 Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 22:18:32 +0900 Subject: [PATCH 14/27] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/{auth => }/AuthenticationService.java | 4 ++-- .../com/moabam/api/domain/{member => }/Member.java | 2 +- src/main/java/com/moabam/api/domain/Role.java | 8 ++++++++ src/main/java/com/moabam/api/domain/member/Role.java | 8 -------- .../api/dto/{auth => }/AuthorizationCodeIssue.java | 2 +- .../presentation/{member => }/MemberController.java | 4 ++-- .../{auth => }/AuthenticationServiceTest.java | 2 +- .../moabam/api/domain/{member => }/MemberTest.java | 11 +++++++++-- .../{member => }/MemberControllerTest.java | 4 ++-- 9 files changed, 26 insertions(+), 19 deletions(-) rename src/main/java/com/moabam/api/application/{auth => }/AuthenticationService.java (85%) rename src/main/java/com/moabam/api/domain/{member => }/Member.java (98%) create mode 100644 src/main/java/com/moabam/api/domain/Role.java delete mode 100644 src/main/java/com/moabam/api/domain/member/Role.java rename src/main/java/com/moabam/api/dto/{auth => }/AuthorizationCodeIssue.java (97%) rename src/main/java/com/moabam/api/presentation/{member => }/MemberController.java (89%) rename src/test/java/com/moabam/api/application/{auth => }/AuthenticationServiceTest.java (97%) rename src/test/java/com/moabam/api/domain/{member => }/MemberTest.java (75%) rename src/test/java/com/moabam/api/presentation/{member => }/MemberControllerTest.java (95%) diff --git a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java b/src/main/java/com/moabam/api/application/AuthenticationService.java similarity index 85% rename from src/main/java/com/moabam/api/application/auth/AuthenticationService.java rename to src/main/java/com/moabam/api/application/AuthenticationService.java index 3688b540..75240f11 100644 --- a/src/main/java/com/moabam/api/application/auth/AuthenticationService.java +++ b/src/main/java/com/moabam/api/application/AuthenticationService.java @@ -1,8 +1,8 @@ -package com.moabam.api.application.auth; +package com.moabam.api.application; import org.springframework.stereotype.Service; -import com.moabam.api.dto.auth.AuthorizationCodeIssue; +import com.moabam.api.dto.AuthorizationCodeIssue; import com.moabam.global.config.OAuthConfig; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/moabam/api/domain/member/Member.java b/src/main/java/com/moabam/api/domain/Member.java similarity index 98% rename from src/main/java/com/moabam/api/domain/member/Member.java rename to src/main/java/com/moabam/api/domain/Member.java index 58440858..28197eec 100644 --- a/src/main/java/com/moabam/api/domain/member/Member.java +++ b/src/main/java/com/moabam/api/domain/Member.java @@ -1,4 +1,4 @@ -package com.moabam.api.domain.member; +package com.moabam.api.domain; import static java.util.Objects.*; diff --git a/src/main/java/com/moabam/api/domain/Role.java b/src/main/java/com/moabam/api/domain/Role.java new file mode 100644 index 00000000..65cb1a49 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/Role.java @@ -0,0 +1,8 @@ +package com.moabam.api.domain; + +public enum Role { + + USER, + BLACK, + ADMIN +} diff --git a/src/main/java/com/moabam/api/domain/member/Role.java b/src/main/java/com/moabam/api/domain/member/Role.java deleted file mode 100644 index b168314b..00000000 --- a/src/main/java/com/moabam/api/domain/member/Role.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.moabam.api.domain.member; - -public enum Role { - - USER, - @SuppressWarnings("checkstyle:JavadocVariable") BLACK, - ADMIN -} diff --git a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java b/src/main/java/com/moabam/api/dto/AuthorizationCodeIssue.java similarity index 97% rename from src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java rename to src/main/java/com/moabam/api/dto/AuthorizationCodeIssue.java index 80a7ec23..ee346b81 100644 --- a/src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java +++ b/src/main/java/com/moabam/api/dto/AuthorizationCodeIssue.java @@ -1,4 +1,4 @@ -package com.moabam.api.dto.auth; +package com.moabam.api.dto; import static com.moabam.global.common.util.OAuthParameterNames.*; diff --git a/src/main/java/com/moabam/api/presentation/member/MemberController.java b/src/main/java/com/moabam/api/presentation/MemberController.java similarity index 89% rename from src/main/java/com/moabam/api/presentation/member/MemberController.java rename to src/main/java/com/moabam/api/presentation/MemberController.java index 703b415a..050fd8f9 100644 --- a/src/main/java/com/moabam/api/presentation/member/MemberController.java +++ b/src/main/java/com/moabam/api/presentation/MemberController.java @@ -1,4 +1,4 @@ -package com.moabam.api.presentation.member; +package com.moabam.api.presentation; import java.io.IOException; @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.moabam.api.application.auth.AuthenticationService; +import com.moabam.api.application.AuthenticationService; import com.moabam.global.common.util.GlobalConstant; import jakarta.servlet.http.HttpServletResponse; diff --git a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java b/src/test/java/com/moabam/api/application/AuthenticationServiceTest.java similarity index 97% rename from src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java rename to src/test/java/com/moabam/api/application/AuthenticationServiceTest.java index 6f29348e..da912353 100644 --- a/src/test/java/com/moabam/api/application/auth/AuthenticationServiceTest.java +++ b/src/test/java/com/moabam/api/application/AuthenticationServiceTest.java @@ -1,4 +1,4 @@ -package com.moabam.api.application.auth; +package com.moabam.api.application; import static org.assertj.core.api.Assertions.*; diff --git a/src/test/java/com/moabam/api/domain/member/MemberTest.java b/src/test/java/com/moabam/api/domain/MemberTest.java similarity index 75% rename from src/test/java/com/moabam/api/domain/member/MemberTest.java rename to src/test/java/com/moabam/api/domain/MemberTest.java index caa56681..dc435f5c 100644 --- a/src/test/java/com/moabam/api/domain/member/MemberTest.java +++ b/src/test/java/com/moabam/api/domain/MemberTest.java @@ -1,4 +1,4 @@ -package com.moabam.api.domain.member; +package com.moabam.api.domain; import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; @@ -38,7 +38,14 @@ void create_member_noImage_success() { assertAll( () -> assertThat(member.getProfileImage()).isEqualTo(BaseImageUrl.PROFILE_URL.getUrl()), - () -> assertThat(member.getRole()).isEqualTo(Role.USER) + () -> assertThat(member.getRole()).isEqualTo(Role.USER), + () -> assertThat(member.getNightBug()).isZero(), + () -> assertThat(member.getGoldenBug()).isZero(), + () -> assertThat(member.getMorningBug()).isZero(), + () -> assertThat(member.getTotalCertifyCount()).isZero(), + () -> assertThat(member.getReportCount()).isZero(), + () -> assertThat(member.getCurrentMorningCount()).isZero(), + () -> assertThat(member.getCurrentNightCount()).isZero() ); }); } diff --git a/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java similarity index 95% rename from src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java rename to src/test/java/com/moabam/api/presentation/MemberControllerTest.java index bf09a503..e234d9ab 100644 --- a/src/test/java/com/moabam/api/presentation/member/MemberControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java @@ -1,4 +1,4 @@ -package com.moabam.api.presentation.member; +package com.moabam.api.presentation; import static com.moabam.global.common.util.OAuthParameterNames.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -15,7 +15,7 @@ import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.databind.ObjectMapper; -import com.moabam.api.application.auth.AuthenticationService; +import com.moabam.api.application.AuthenticationService; import com.moabam.global.common.util.GlobalConstant; import com.moabam.global.config.OAuthConfig; From 5a76a5072a07b58417dc11d3f83c48e8709c7e07 Mon Sep 17 00:00:00 2001 From: parksey Date: Mon, 30 Oct 2023 23:04:11 +0900 Subject: [PATCH 15/27] refactor: revert merge --- .editorconfig | 18 + config/naver-checkstyle-rules.xml | 433 ++++++++++++++++++ config/naver-intellij-formatter-custom.xml | 143 +++--- .../auth/AuthenticationService.java | 22 + .../com/moabam/api/domain/member/Member.java | 82 ++++ .../com/moabam/api/domain/member/Role.java | 7 + .../api/dto/auth/AuthorizationCodeIssue.java | 43 ++ .../presentation/member/MemberController.java | 40 ++ .../global/common/util/GlobalConstant.java | 4 + .../global/common/util/UrlGenerator.java | 40 ++ .../global/common/util/UrlGeneratorTest.java | 54 +++ 11 files changed, 814 insertions(+), 72 deletions(-) create mode 100644 .editorconfig create mode 100644 config/naver-checkstyle-rules.xml create mode 100644 src/main/java/com/moabam/api/application/auth/AuthenticationService.java create mode 100644 src/main/java/com/moabam/api/domain/member/Member.java create mode 100644 src/main/java/com/moabam/api/domain/member/Role.java create mode 100644 src/main/java/com/moabam/api/dto/auth/AuthorizationCodeIssue.java create mode 100644 src/main/java/com/moabam/api/presentation/member/MemberController.java create mode 100644 src/main/java/com/moabam/global/common/util/UrlGenerator.java create mode 100644 src/test/java/com/moabam/global/common/util/UrlGeneratorTest.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..855c0c54 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 120 +tab_width = 4 +trim_trailing_whitespace = true + +[*.bat] +end_of_line = crlf + +[*.java] +indent_style = tab +ij_java_blank_lines_after_class_header = 1 diff --git a/config/naver-checkstyle-rules.xml b/config/naver-checkstyle-rules.xml new file mode 100644 index 00000000..dafbb4d1 --- /dev/null +++ b/config/naver-checkstyle-rules.xml @@ -0,0 +1,433 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/naver-intellij-formatter-custom.xml b/config/naver-intellij-formatter-custom.xml index dc4c4a2e..26f28954 100644 --- a/config/naver-intellij-formatter-custom.xml +++ b/config/naver-intellij-formatter-custom.xml @@ -1,75 +1,74 @@ - -