Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: 멀티 모듈로 구조 마이그레이션한다. #145

Merged
merged 6 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ jobs:
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew copyYml
./gradlew --info test
6 changes: 6 additions & 0 deletions api/api-support/exception-handler/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bootJar { enabled = false }
jar { enabled = true }

dependencies {
api project (':core:exception-core')
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thirdparty.ticketing.domain.common;
package com.thirdparty.ticketing.exceptionhandler;

import java.util.List;

Expand All @@ -7,6 +7,10 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.thirdparty.ticketing.exception.ErrorCode;
import com.thirdparty.ticketing.exception.TicketingException;
import com.thirdparty.ticketing.exceptionhandler.dto.ErrorResponse;

import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thirdparty.ticketing.domain.common;
package com.thirdparty.ticketing.exceptionhandler;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.thirdparty.ticketing.domain.common;
package com.thirdparty.ticketing.exceptionhandler.dto;

import java.util.List;

import org.springframework.web.bind.MethodArgumentNotValidException;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.thirdparty.ticketing.exception.ErrorCode;
import com.thirdparty.ticketing.exceptionhandler.ValidationErrorDetail;

import lombok.Data;

Expand Down
40 changes: 40 additions & 0 deletions api/api-support/rest-docs-support/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
id 'org.asciidoctor.jvm.convert' version '3.3.2'
}

bootJar { enabled = false }
jar { enabled = true }

configurations {
asciidoctorExt
}

dependencies {
api project(':api:api-support:security-support')
api 'org.springframework.restdocs:spring-restdocs-mockmvc'

implementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.security:spring-security-test'
implementation 'org.junit.jupiter:junit-jupiter-api:5.11.0'


asciidoctor {
inputs.dir snippetsDir
configurations 'asciidoctorExt'
dependsOn test
}

asciidoctor.doFirst {
delete file('src/main/resources/static/docs')
}

tasks.register('copyDocument', Copy) {
dependsOn asciidoctor
from file("build/docs/asciidoc")
into file("src/main/resources/static/docs")
}

build {
dependsOn copyDocument
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
package com.thirdparty.ticketing.support;

import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
package com.thirdparty.ticketing.restdocs;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -16,18 +10,21 @@
import org.springframework.restdocs.RestDocumentationExtension;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
import org.springframework.restdocs.operation.preprocess.Preprocessors;
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.member.Member;
import com.thirdparty.ticketing.domain.member.MemberRole;
import com.thirdparty.ticketing.domain.member.service.JwtProvider;
import com.thirdparty.ticketing.global.config.SecurityConfig;
import com.thirdparty.ticketing.global.config.WebConfig;
import com.thirdparty.ticketing.support.BaseControllerTest.RestDocsConfig;
import com.thirdparty.ticketing.jpa.member.Member;
import com.thirdparty.ticketing.jpa.member.MemberRole;
import com.thirdparty.ticketing.restdocs.BaseControllerTest.RestDocsConfig;
import com.thirdparty.ticketing.security.config.SecurityConfig;
import com.thirdparty.ticketing.security.config.WebConfig;
import com.thirdparty.ticketing.security.jwt.JwtProvider;

@Import({RestDocsConfig.class, SecurityConfig.class, WebConfig.class})
@ExtendWith(RestDocumentationExtension.class)
Expand All @@ -54,8 +51,8 @@ public static class RestDocsConfig {
public RestDocumentationResultHandler write() {
return MockMvcRestDocumentation.document(
"{class-name}/{method-name}",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()));
Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
Preprocessors.preprocessResponse(Preprocessors.prettyPrint()));
}
}

Expand All @@ -65,9 +62,9 @@ void setUp(
RestDocumentationContextProvider documentationContextProvider) {
this.mockMvc =
MockMvcBuilders.webAppContextSetup(applicationContext)
.alwaysDo(print())
.alwaysDo(MockMvcResultHandlers.print())
.alwaysDo(restDocs)
.apply(springSecurity())
.apply(SecurityMockMvcConfigurers.springSecurity())
.apply(
MockMvcRestDocumentation.documentationConfiguration(
documentationContextProvider))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.thirdparty.ticketing;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TestConfiguration {}
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
package com.thirdparty.ticketing.support;

import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.queryParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
package com.thirdparty.ticketing.docs;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -19,8 +9,12 @@
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.restdocs.payload.PayloadDocumentation;
import org.springframework.restdocs.request.RequestDocumentation;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -29,7 +23,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.thirdparty.ticketing.support.DocumentationTest.DocsController;
import com.thirdparty.ticketing.docs.DocumentationTest.DocsController;
import com.thirdparty.ticketing.restdocs.BaseControllerTest;

@WebMvcTest(controllers = DocumentationTest.class)
@Import(DocsController.class)
Expand Down Expand Up @@ -65,15 +60,20 @@ public void getDocs() throws Exception {
// given

// when
ResultActions result = mockMvc.perform(get("/test/docs/hello").param("name", "ticket"));
ResultActions result =
mockMvc.perform(
RestDocumentationRequestBuilders.get("/test/docs/hello")
.param("name", "ticket"));

// then
result.andExpect(status().isOk())
result.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(
restDocs.document(
queryParameters(parameterWithName("name").description("이름")),
responseFields(
fieldWithPath("hello")
RequestDocumentation.queryParameters(
RequestDocumentation.parameterWithName("name")
.description("이름")),
PayloadDocumentation.responseFields(
PayloadDocumentation.fieldWithPath("hello")
.type(JsonFieldType.STRING)
.description("안녕, 이름"))));
}
Expand All @@ -87,24 +87,26 @@ void postDocs() throws Exception {
// when
ResultActions result =
mockMvc.perform(
post("/test/docs/hello/{test}", 1L)
RestDocumentationRequestBuilders.post("/test/docs/hello/{test}", 1L)
.contentType(MediaType.APPLICATION_JSON)
.content(content));

// then
result.andExpect(status().isOk())
result.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(
restDocs.document(
pathParameters(parameterWithName("test").description("테스트용 경로 변수")),
requestFields(
fieldWithPath("name")
RequestDocumentation.pathParameters(
RequestDocumentation.parameterWithName("test")
.description("테스트용 경로 변수")),
PayloadDocumentation.requestFields(
PayloadDocumentation.fieldWithPath("name")
.type(JsonFieldType.STRING)
.description("이름")),
responseFields(
fieldWithPath("pathVariable")
PayloadDocumentation.responseFields(
PayloadDocumentation.fieldWithPath("pathVariable")
.type(JsonFieldType.STRING)
.description("경로 변수"),
fieldWithPath("hello")
PayloadDocumentation.fieldWithPath("hello")
.type(JsonFieldType.STRING)
.description("안녕, 이름"))));
}
Expand Down
13 changes: 13 additions & 0 deletions api/api-support/security-support/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
bootJar { enabled = false }
jar { enabled = true }

dependencies {
api project (':core:exception-core')
api project (':domain:jpa-domain')

api 'org.springframework.boot:spring-boot-starter-security'

implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.3'
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.thirdparty.ticketing.global.security;
package com.thirdparty.ticketing.security;

import java.util.NoSuchElementException;

import com.thirdparty.ticketing.domain.member.Member;
import com.thirdparty.ticketing.domain.member.service.PasswordEncoder;
import com.thirdparty.ticketing.jpa.member.Member;
import com.thirdparty.ticketing.security.service.PasswordEncoder;

public class BCryptPasswordEncoder implements PasswordEncoder {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thirdparty.ticketing.global.security;
package com.thirdparty.ticketing.security;

import org.springframework.core.MethodParameter;
import org.springframework.security.core.Authentication;
Expand All @@ -8,9 +8,9 @@
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import com.thirdparty.ticketing.domain.common.ErrorCode;
import com.thirdparty.ticketing.domain.common.LoginMember;
import com.thirdparty.ticketing.domain.common.TicketingException;
import com.thirdparty.ticketing.exception.ErrorCode;
import com.thirdparty.ticketing.exception.TicketingException;
import com.thirdparty.ticketing.security.annotation.LoginMember;

import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thirdparty.ticketing.domain.common;
package com.thirdparty.ticketing.security.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thirdparty.ticketing.global.config;
package com.thirdparty.ticketing.security.config;

import java.util.List;

Expand All @@ -17,12 +17,12 @@
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import com.thirdparty.ticketing.domain.member.MemberRole;
import com.thirdparty.ticketing.domain.member.service.JwtProvider;
import com.thirdparty.ticketing.domain.member.service.PasswordEncoder;
import com.thirdparty.ticketing.global.security.AuthenticationFilter;
import com.thirdparty.ticketing.global.security.BCryptPasswordEncoder;
import com.thirdparty.ticketing.global.security.JJwtProvider;
import com.thirdparty.ticketing.jpa.member.MemberRole;
import com.thirdparty.ticketing.security.BCryptPasswordEncoder;
import com.thirdparty.ticketing.security.jwt.AuthenticationFilter;
import com.thirdparty.ticketing.security.jwt.JJwtProvider;
import com.thirdparty.ticketing.security.jwt.JwtProvider;
import com.thirdparty.ticketing.security.service.PasswordEncoder;

@Configuration
public class SecurityConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.thirdparty.ticketing.global.config;
package com.thirdparty.ticketing.security.config;

import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.thirdparty.ticketing.global.security.LoginMemberArgumentResolver;
import com.thirdparty.ticketing.security.LoginMemberArgumentResolver;

import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.thirdparty.ticketing.domain.member.dto.response;
package com.thirdparty.ticketing.security.dto;

import com.thirdparty.ticketing.domain.member.MemberRole;
import com.thirdparty.ticketing.jpa.member.MemberRole;

import lombok.Data;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thirdparty.ticketing.global.security;
package com.thirdparty.ticketing.security.jwt;

import java.io.IOException;
import java.util.Objects;
Expand All @@ -13,10 +13,9 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.OncePerRequestFilter;

import com.thirdparty.ticketing.domain.common.ErrorCode;
import com.thirdparty.ticketing.domain.common.TicketingException;
import com.thirdparty.ticketing.domain.member.dto.response.CustomClaims;
import com.thirdparty.ticketing.domain.member.service.JwtProvider;
import com.thirdparty.ticketing.exception.ErrorCode;
import com.thirdparty.ticketing.exception.TicketingException;
import com.thirdparty.ticketing.security.dto.CustomClaims;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Loading
Loading