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

Feature/199 spring swagger #204

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ dependencies {

//spring aop
implementation 'org.springframework.boot:spring-boot-starter-aop'

//Swagger
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '3.0.0'
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
}

tasks.named('test') {
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/sptp/backend/common/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.sptp.backend.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Collections;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.ignoredParameterTypes(AuthenticationPrincipal.class)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfo(
"Atties REST API TEST",
"μ•„λ μ¦ˆ API λ¬Έμ„œ λͺ©λ‘",
"V1",
"Terms of service",
new Contact("administrator", "www.example.com", "administrator@email.com"),
"License of API", "www.example.com", Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.PATCH, "/artists").hasAnyRole("ARTIST", "ADMIN")
.antMatchers(HttpMethod.POST, "/art-works").hasAnyRole("ARTIST", "ADMIN")
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/swagger-ui/**").permitAll() // TODO : 좔후에 λ”°λ‘œ κΆŒν•œ μ„€μ • λ…Όμ˜ ν•„μš”
.antMatchers("/swagger-ui.html").permitAll() // TODO : 좔후에 λ”°λ‘œ κΆŒν•œ μ„€μ • λ…Όμ˜ ν•„μš”
.antMatchers("/api/v2/**").permitAll() // TODO : 좔후에 λ”°λ‘œ κΆŒν•œ μ„€μ • λ…Όμ˜ ν•„μš”
.antMatchers("/v2/api-docs/**").permitAll() // TODO : 좔후에 λ”°λ‘œ κΆŒν•œ μ„€μ • λ…Όμ˜ ν•„μš”
.antMatchers("/swagger/**").permitAll() // TODO : 좔후에 λ”°λ‘œ κΆŒν•œ μ„€μ • λ…Όμ˜ ν•„μš”
.antMatchers("/swagger-resources/**").permitAll() // TODO : 좔후에 λ”°λ‘œ κΆŒν•œ μ„€μ • λ…Όμ˜ ν•„μš”
.antMatchers("/webjars/**").permitAll() // TODO : 좔후에 λ”°λ‘œ κΆŒν•œ μ„€μ • λ…Όμ˜ ν•„μš”

.anyRequest().authenticated(); // κ·Έμ™Έ λ‚˜λ¨Έμ§€ μš”μ²­μ€ 인증 ν•„μš”

http.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
Expand All @@ -76,6 +84,7 @@ public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

configuration.addAllowedOrigin("http://localhost:3000");
configuration.addAllowedOrigin("http://localhost:8080");
configuration.addAllowedOrigin("https://atties.vercel.app");
configuration.addAllowedOrigin("https://attiess.netlify.app");
configuration.addAllowedHeader("*");
Expand Down
40 changes: 39 additions & 1 deletion src/main/java/com/sptp/backend/member/web/MemberController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.member.web.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.List;
Expand All @@ -11,14 +12,24 @@
@Builder
public class ArtistUpdateRequest {

@ApiModelProperty(required = true, value = "μœ μ € λ‹‰λ„€μž„", example = "아라")
private String nickname;
@ApiModelProperty(required = true, value = "μœ μ € 이메일", example = "test1234@naver.com")
private String email;
@ApiModelProperty(required = true, value = "ν•™λ ₯", example = "xxλŒ€ν•™κ΅ xxν•™κ³Ό")
private String education;
@ApiModelProperty(required = true, value = "이λ ₯", example = "이λ ₯μž…λ‹ˆλ‹€.")
private String history;
@ApiModelProperty(required = true, value = "μ†Œκ°œ,μ„€λͺ…", example = "μ†Œκ°œκΈ€μž…λ‹ˆλ‹€.")
private String description;
@ApiModelProperty(required = true, value = "μΈμŠ€νƒ€κ·Έλž¨ μ£Όμ†Œ", example = "www.instagram.com")
private String instagram;
@ApiModelProperty(required = true, value = "λΉ„ν—¨μŠ€ μ£Όμ†Œ", example = "www.behance.com")
private String behance;
@ApiModelProperty(required = true, value = "μœ μ € μ£Όμ†Œ", example = "μ„œμšΈμ‹œ xxꡬ xx동 123동 1234호")
private String address;
@ApiModelProperty(required = true, value = "μœ μ € μ—°λ½μ²˜", example = "01012345678")
private String telephone;
@ApiModelProperty(required = true, value = "이미지 λ³€κ²½ μ—¬λΆ€", example = "true")
private Boolean isChanged;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.member.web.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;

@Getter
Expand All @@ -9,5 +10,6 @@
@Builder
public class MemberAnswerRequest {

@ApiModelProperty(required = true, value = "문의 κΈ€ λ‹΅λ³€", example = "λ‹΅λ³€")
private String answer;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.member.web.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -10,7 +11,10 @@
@Builder
public class MemberAskRequestDto {

@ApiModelProperty(required = true, value = "문의 κΈ€ 제λͺ©", example = "제λͺ©")
private String title;
@ApiModelProperty(required = true, value = "문의 κΈ€ λ‚΄μš©", example = "λ‚΄μš©")
private String content;
@ApiModelProperty(required = true, value = "문의 κΈ€ 첨뢀 사진")
private MultipartFile[] image;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.member.web.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;

@Getter
Expand All @@ -9,6 +10,8 @@
@Builder
public class MemberLoginRequestDto {

@ApiModelProperty(required = true, value = "μœ μ € 아이디", example = "test1234")
private String userId;
@ApiModelProperty(required = true, value = "μœ μ € νŒ¨μŠ€μ›Œλ“œ", example = "password1234")
private String password;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.member.web.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.List;
Expand All @@ -11,11 +12,17 @@
@Builder
public class MemberSaveRequestDto {

@ApiModelProperty(required = true, value = "μœ μ € λ‹‰λ„€μž„", example = "아라")
private String nickname;
@ApiModelProperty(required = true, value = "μœ μ € 아이디", example = "test1234")
private String userId;
@ApiModelProperty(required = true, value = "μœ μ € 이메일", example = "test1234@naver.com")
private String email;
@ApiModelProperty(required = true, value = "μœ μ € νŒ¨μŠ€μ›Œλ“œ", example = "password1234")
private String password;
@ApiModelProperty(required = true, value = "μœ μ € μ—°λ½μ²˜", example = "01012345678")
private String telephone;
@ApiModelProperty(required = true, value = "μœ μ € 관심 ν‚€μ›Œλ“œ", example = "ν™”λ €ν•œ,μœ ν™”")
private List<String> keywords;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.member.web.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.List;
Expand All @@ -11,5 +12,6 @@
@Builder
public class MemberUpdateKeywordsRequestDto {

@ApiModelProperty(required = true, value = "μœ μ € 관심 ν‚€μ›Œλ“œ", example = "['ν™”λ €ν•œ','μœ ν™”']")
private List<String> keywords;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.member.web.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.List;
Expand All @@ -11,9 +12,14 @@
@Builder
public class MemberUpdateRequest {

@ApiModelProperty(required = true, value = "μœ μ € λ‹‰λ„€μž„", example = "아라")
private String nickname;
@ApiModelProperty(required = true, value = "μœ μ € 이메일", example = "test1234@naver.com")
private String email;
@ApiModelProperty(required = true, value = "μœ μ € μ£Όμ†Œ", example = "μ„œμšΈμ‹œ xxꡬ xx동 123동 1234호")
private String address;
@ApiModelProperty(required = true, value = "μœ μ € μ—°λ½μ²˜", example = "01012345678")
private String telephone;
@ApiModelProperty(required = true, value = "이미지 λ³€κ²½ μ—¬λΆ€", example = "true")
private Boolean isChanged;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.member.web.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.validator.constraints.Length;

Expand All @@ -12,6 +13,7 @@
@Builder
public class PasswordChangeRequest {

@ApiModelProperty(required = true, value = "μœ μ € λΉ„λ°€λ²ˆν˜Έ", example = "password1234")
@Length(min = 8, message = "λΉ„λ°€λ²ˆν˜ΈλŠ” 8자 이상 μž…λ ₯ν•΄μ£Όμ„Έμš”.")
@NotBlank(message = "λΉ„λ°€λ²ˆν˜ΈλŠ” 곡백일 수 μ—†μŠ΅λ‹ˆλ‹€.")
private String password;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ server:

spring:

mvc:
pathmatch:
matching-strategy: ant_path_matcher

servlet:
multipart:
max-file-size: 10MB
Expand Down