Skip to content

Commit

Permalink
Merge pull request #73 from kookmin-sw/backend/develop/v3
Browse files Browse the repository at this point in the history
Backend/develop/v3
  • Loading branch information
J-Yong99 authored Apr 11, 2024
2 parents 71849a9 + 40ed1d3 commit 360f64d
Show file tree
Hide file tree
Showing 28 changed files with 4,604 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions backend/moment/moment-server/auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.1.7'
id 'io.spring.dependency-management' version '1.1.4'
id "org.asciidoctor.jvm.convert" version "3.3.2"
}

group = 'com.moment'
Expand All @@ -15,6 +16,7 @@ configurations {
compileOnly {
extendsFrom annotationProcessor
}
asciidoctorExt // asciidoctorExt에 대한 선언
}

repositories {
Expand All @@ -39,9 +41,15 @@ dependencies {
implementation 'javax.xml.bind:jaxb-api:2.3.0'
implementation 'commons-io:commons-io:2.11.0'
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'

testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.21.0'
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' // asciidoctorExt에 spring-restdocs-asciidoctor 의존성 추가
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' // mockMvc 사용

}
ext {
set('springCloudVersion', "2022.0.3")
snippetsDir = file('build/generated-snippets') // 스니펫이 생성되는 디렉터리 경로를 설정
}

dependencyManagement {
Expand All @@ -53,3 +61,31 @@ dependencyManagement {
tasks.named('test') {
useJUnitPlatform()
}
asciidoctor { // Gradle이 asciidoctor Task를 수행하는 설정 (함수 선언)
configurations 'asciidoctorExt' // asciidoctor 확장 설정
baseDirFollowsSourceFile() // .adoc 파일을 include 하면서 사용하기 위한 설정
inputs.dir snippetsDir // 스니펫을 불러올 위치 설정
dependsOn test // Gradle의 test Task 이후 asciidoctor를 수행
}

asciidoctor.doFirst { // asciidoctor Task가 수행될 때 가장 먼저 수행
delete file('src/main/resources/static/docs')
}

task copyDocument(type: Copy) { // 생성된 html 파일을 옮긴다
dependsOn asciidoctor // Gradle의 asciidoctor Task 이후 수행
from file("${asciidoctor.outputDir}")
into file("src/main/resources/static/docs")
}

build {
dependsOn copyDocument // build 이후 html 파일 복사
}

bootJar {
dependsOn asciidoctor // asciidoctor 이후 bootJar 수행
from ("${asciidoctor.outputDir}") {
into 'static/docs'
}

}
14 changes: 14 additions & 0 deletions backend/moment/moment-server/auth/src/docs/asciidoc/Auth.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
== Auth
:doctype: book
:source-highlighter: highlightjs
:sectlinks:
:toc: left
:toclevels: 3
=== 로그인
operation::auth/login[snippets="http-request,request-body,request-fields,http-response,response-fields"]
=== 비밀번호 변경
operation::auth/changePassword[snippets="http-request,request-headers,request-body,request-fields,http-response,response-fields"]
=== 인증코드 요청
operation::auth/sendCode[snippets="http-request,request-body,request-fields,http-response,response-fields"]
=== 인증코드 확인
operation::auth/verifyCode[snippets="http-request,request-headers,request-body,request-fields,http-response,response-fields"]
10 changes: 10 additions & 0 deletions backend/moment/moment-server/auth/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// index.adoc
= Moment Application API Document
:doctype: book
:source-highlighter: highlightjs
:sectlinks:
:toc: left
:toclevels: 3

include::Auth.adoc[]

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@


import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.Setter;

import lombok.*;


public class AuthRequest {

//자체회원가입 폼
@Getter
@Setter
@Builder
public static class Login {

private String email;
Expand All @@ -23,19 +22,26 @@ public static class Login {

@Getter
@Setter
@Builder
public static class SendCode {
private String email;
private String isSignUp;
}

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class VerifyCode {
private String code;
}

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class ChangePassword {

private String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.moment.auth.config;

import org.springframework.restdocs.snippet.Attributes;

import static org.springframework.restdocs.snippet.Attributes.key;

public interface DocumentFormatGenerator {

static Attributes.Attribute getDateFormat() { // (2)
return key("format").value("yyyy-MM-dd");
}

static Attributes.Attribute getDateTimeFormat() { // (2)
return key("format").value("yyyy-MM-dd'T'HH:mm:ss");
}

static Attributes.Attribute getBooleanFormat() { // (3)
return key("format").value("true or false");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.moment.auth.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.RestDocumentationExtension;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
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(RestDocsConfiguration.class)
@ExtendWith(RestDocumentationExtension.class)
//@WebMvcTest(MemberController.class)
public class RestDocsBasic {

@Autowired
MockMvc mvc;

@Autowired
RestDocumentationResultHandler restDocs;

@Autowired
ObjectMapper mapper;

@BeforeEach
void setUp(WebApplicationContext context, RestDocumentationContextProvider provider){
this.mvc= MockMvcBuilders.webAppContextSetup(context)
.apply(MockMvcRestDocumentation.documentationConfiguration(provider))
.alwaysDo(MockMvcResultHandlers.print())
.alwaysDo(restDocs)
.addFilters(new CharacterEncodingFilter("UTF-8",true))
.build();
}

protected String createStringJson(Object dto) throws JsonProcessingException {
return mapper.writeValueAsString(dto);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.moment.auth.config;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
import org.springframework.restdocs.operation.preprocess.Preprocessors;

@TestConfiguration
public class RestDocsConfiguration {
@Bean
public RestDocumentationResultHandler write() {
return MockMvcRestDocumentation.document("{class-name}/{method-name}",
Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
Preprocessors.preprocessResponse(Preprocessors.prettyPrint()));
}
}
Loading

0 comments on commit 360f64d

Please sign in to comment.