Skip to content

Commit 51d5161

Browse files
authored
Merge pull request #67 from FixLog/chore/#64-swaggerSetting-cw
[CHORE] Swagger 설정 초기 세팅
2 parents ec1d36f + 81bfc59 commit 51d5161

10 files changed

Lines changed: 131 additions & 33 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ out/
4040

4141
.env
4242
*.env
43+
.env

build.gradle

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.4.5'
3+
id 'org.springframework.boot' version '3.2.5'//스웨거로 인해 버전 낮춤
44
id 'io.spring.dependency-management' version '1.1.7'
55
}
66

@@ -17,6 +17,10 @@ java {
1717
}
1818
}
1919

20+
ext {
21+
queryDslVersion = "5.0.0"
22+
}
23+
2024
configurations {
2125
compileOnly {
2226
extendsFrom annotationProcessor
@@ -25,47 +29,69 @@ configurations {
2529

2630
repositories {
2731
mavenCentral()
32+
33+
// springdoc 2.5.0은 여기서 제공됨
34+
maven { url 'https://repo.spring.io/release' }
2835
}
2936

3037
dependencies {
38+
// Spring Boot
3139
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
32-
implementation 'org.springframework.boot:spring-boot-starter-security'
40+
implementation 'org.springframework.boot:spring-boot-starter-security'
3341
implementation 'org.springframework.boot:spring-boot-starter-web'
3442
implementation 'org.springframework.boot:spring-boot-starter-validation'
43+
44+
// JWT
3545
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
3646
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
37-
runtimeOnly('io.jsonwebtoken:jjwt-jackson:0.11.5')
47+
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
48+
49+
// DB
3850
runtimeOnly 'com.h2database:h2'
3951
runtimeOnly 'com.mysql:mysql-connector-j'
40-
compileOnly 'org.projectlombok:lombok'
41-
annotationProcessor 'org.projectlombok:lombok'
42-
testImplementation 'org.springframework.boot:spring-boot-starter-test'
43-
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
52+
53+
// AWS
4454
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.538'
55+
56+
// QueryDSL
4557
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}:jakarta"
4658
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jakarta"
4759
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
4860
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
49-
}
61+
62+
// Swagger (springdoc)
63+
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
64+
65+
// Lombok
66+
compileOnly 'org.projectlombok:lombok'
67+
annotationProcessor 'org.projectlombok:lombok'
68+
69+
// Test
70+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
71+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
5072

5173
tasks.named('test') {
5274
useJUnitPlatform()
5375
}
5476

77+
// WAR 파일 안 만들게 설정
5578
jar {
5679
enabled = false
5780
}
5881

82+
// QueryDSL 설정
5983
def querydslDir = "src/main/generated"
6084

6185
sourceSets {
62-
main {
63-
java {
64-
srcDirs += querydslDir
65-
}
66-
}
86+
main {
87+
java {
88+
srcDirs += querydslDir
89+
}
90+
}
6791
}
6892

6993
tasks.withType(JavaCompile).configureEach {
70-
options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir)
94+
options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir)
7195
}
96+
97+

src/main/java/com/example/FixLog/config/SecurityConfig.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.example.FixLog.repository.MemberRepository;
44
import com.example.FixLog.util.JwtUtil;
5-
import com.example.FixLog.config.JwtAuthenticationFilter;
65
import jakarta.servlet.Filter;
76
import lombok.RequiredArgsConstructor;
87
import org.springframework.context.annotation.Bean;
@@ -35,12 +34,16 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3534
.requestMatchers(HttpMethod.POST, "/members/signup").permitAll()
3635
.requestMatchers(HttpMethod.GET, "/members/check-email").permitAll()
3736
.requestMatchers(HttpMethod.GET, "/members/check-nickname").permitAll()
38-
.requestMatchers(HttpMethod.GET, "/main/**").permitAll()
37+
.requestMatchers(HttpMethod.GET, "/", "/main", "/main/**").permitAll()
3938
.requestMatchers(HttpMethod.GET, "/posts/**").permitAll()
4039
// h2-console (로컬 테스트용)
4140
.requestMatchers(HttpMethod.GET, "/h2-console/**").permitAll()
4241
// 배포 확인용 임시 허용
4342
.requestMatchers(HttpMethod.GET, "/test", "/test/**").permitAll()
43+
// Swagger 허용
44+
.requestMatchers(HttpMethod.GET,"/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
45+
.requestMatchers(HttpMethod.POST,"/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
46+
.requestMatchers(HttpMethod.PATCH,"/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
4447
// 그 외 모든 요청은 인증 필요
4548

4649
.anyRequest().authenticated()
@@ -53,7 +56,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
5356

5457
@Bean
5558
public Filter jwtAuthenticationFilter() {
56-
return new JwtAuthenticationFilter(jwtUtil, memberRepository);
59+
return new com.example.FixLog.config.JwtAuthenticationFilter(jwtUtil, memberRepository);
5760
}
5861

5962
@Bean
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.example.FixLog.config;
2+
3+
import io.swagger.v3.oas.models.Components;
4+
import io.swagger.v3.oas.models.OpenAPI;
5+
import io.swagger.v3.oas.models.info.Info;
6+
import io.swagger.v3.oas.models.security.SecurityRequirement;
7+
import io.swagger.v3.oas.models.security.SecurityScheme;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
@Configuration
12+
public class SwaggerConfig {
13+
14+
@Bean
15+
public OpenAPI openAPI() {
16+
final String securitySchemeName = "bearerAuth";
17+
18+
return new OpenAPI()
19+
.info(new Info()
20+
.title("FixLog API Docs")
21+
.description("FixLog 백엔드 API 명세서")
22+
.version("v1.0"))
23+
.addSecurityItem(new SecurityRequirement().addList(securitySchemeName)) // 전체 보안 요구사항
24+
.components(new Components().addSecuritySchemes(securitySchemeName,
25+
new SecurityScheme()
26+
.name(securitySchemeName)
27+
.type(SecurityScheme.Type.HTTP)
28+
.scheme("bearer")
29+
.bearerFormat("JWT")
30+
));
31+
}
32+
}

src/main/java/com/example/FixLog/controller/FollowController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.example.FixLog.dto.follow.response.FollowerListResponseDto;
88
import com.example.FixLog.dto.follow.response.FollowingListResponseDto;
99
import com.example.FixLog.service.FollowService;
10+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
1011
import lombok.RequiredArgsConstructor;
1112
import org.springframework.http.ResponseEntity;
1213
import org.springframework.security.core.annotation.AuthenticationPrincipal;
@@ -22,17 +23,19 @@ public class FollowController {
2223
private final FollowService followService;
2324

2425
// 팔로우하기
26+
@SecurityRequirement(name = "bearerAuth")
2527
@PostMapping
2628
public ResponseEntity<Response<FollowResponseDto>> follow(
2729
@RequestBody FollowRequestDto followRequestDto,
2830
@AuthenticationPrincipal UserDetails userDetails // jwt 구현 전까지 임시 사용 -> 이후 AuthenticationPrincipal 사용 예정
29-
){
31+
){
3032
String requesterEmail = userDetails.getUsername();
3133
FollowResponseDto result = followService.follow(requesterEmail, followRequestDto.getTargetMemberId());
3234
return ResponseEntity.ok(Response.success("팔로우 완료", result));
3335
}
3436

3537
// 언팔로우하기
38+
@SecurityRequirement(name = "bearerAuth")
3639
@PostMapping("/unfollow")
3740
public ResponseEntity<Response<Void>> unfollow(
3841
@RequestBody UnfollowRequestDto requestDto,
@@ -44,6 +47,7 @@ public ResponseEntity<Response<Void>> unfollow(
4447
}
4548

4649
// 나를 팔로우하는 목록 조회
50+
@SecurityRequirement(name = "bearerAuth")
4751
@GetMapping("/followers")
4852
public ResponseEntity<Response<List<FollowerListResponseDto>>> getMyFollowers(
4953
@AuthenticationPrincipal UserDetails userDetails
@@ -54,6 +58,7 @@ public ResponseEntity<Response<List<FollowerListResponseDto>>> getMyFollowers(
5458
}
5559

5660
// 내가 팔로우하는 목록 조회
61+
@SecurityRequirement(name = "bearerAuth")
5762
@GetMapping("/followings")
5863
public ResponseEntity<Response<List<FollowingListResponseDto>>> getMyFollowings(
5964
@AuthenticationPrincipal UserDetails userDetails

src/main/java/com/example/FixLog/controller/MemberController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.http.ResponseEntity;
1313
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1414
import org.springframework.web.bind.annotation.*;
15+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
1516

1617
@RestController
1718
@RequestMapping("/members")
@@ -40,15 +41,18 @@ public ResponseEntity<Response<DuplicateCheckResponseDto>> checkNickname(@Reques
4041
return ResponseEntity.ok(Response.success(msg, new DuplicateCheckResponseDto(exists)));
4142
}
4243

44+
@SecurityRequirement(name = "bearerAuth")
4345
@GetMapping("/me")
4446
public ResponseEntity<Response<MemberInfoResponseDto>> getMyInfo(@AuthenticationPrincipal Member member) {
47+
System.out.println("회원 정보 조회 요청: " + member.getEmail()); //추후에 log.info()로 바꿀 예정
4548
MemberInfoResponseDto responseDto = new MemberInfoResponseDto(
4649
member.getEmail(),
4750
member.getNickname(),
4851
member.getProfileImageUrl(),
4952
member.getBio(),
5053
member.getSocialType()
5154
);
55+
System.out.println("회원 정보 조회 완료: " + member.getEmail());
5256
return ResponseEntity.ok(Response.success("회원 정보 조회 성공", responseDto));
5357
}
5458

@@ -62,6 +66,7 @@ public ResponseEntity<Response<ProfilePreviewResponseDto>> getProfilePreview() {
6266
return ResponseEntity.ok(Response.success("닉네임&프로필사진 조회 성공", dto));
6367
}
6468

69+
@SecurityRequirement(name = "bearerAuth")
6570
@DeleteMapping("/me")
6671
public ResponseEntity<Response<Void>> withdraw(
6772
@AuthenticationPrincipal Member member,

src/main/java/com/example/FixLog/controller/MypageMemberController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.example.FixLog.service.S3Service;
1111
import com.example.FixLog.service.MemberService;
1212
import com.example.FixLog.domain.member.Member;
13+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
1314
import lombok.RequiredArgsConstructor;
1415
import org.springframework.http.ResponseEntity;
1516
import jakarta.validation.Valid;
@@ -26,6 +27,7 @@ public class MypageMemberController {
2627
private final MemberService memberService;
2728
private final S3Service s3Service;
2829

30+
@SecurityRequirement(name = "bearerAuth")
2931
@PatchMapping("/members/nickname")
3032
public ResponseEntity<Response<String>> editNickname(
3133
@RequestBody @Valid EditNicknameRequestDto requestDto
@@ -35,6 +37,7 @@ public ResponseEntity<Response<String>> editNickname(
3537
return ResponseEntity.ok(Response.success("닉네임 수정 성공", "SUCCESS"));
3638
}
3739

40+
@SecurityRequirement(name = "bearerAuth")
3841
@PatchMapping("/members/password")
3942
public ResponseEntity<Response<String>> editPassword(
4043
@RequestBody @Valid EditPasswordRequestDto requestDto
@@ -44,6 +47,7 @@ public ResponseEntity<Response<String>> editPassword(
4447
return ResponseEntity.ok(Response.success("비밀번호 변경 성공", "SUCCESS"));
4548
}
4649

50+
@SecurityRequirement(name = "bearerAuth")
4751
@GetMapping("/members/profile-image/presign")
4852
public ResponseEntity<Response<PresignResponseDto>> presignProfileImage(
4953
@AuthenticationPrincipal Member member,
@@ -59,6 +63,7 @@ public ResponseEntity<Response<PresignResponseDto>> presignProfileImage(
5963
return ResponseEntity.ok(Response.success("Presigned URL 발급 성공", dto));
6064
}
6165

66+
@SecurityRequirement(name = "bearerAuth")
6267
@PatchMapping("/members/profile-image")
6368
public ResponseEntity<Response<String>> updateProfileImageUrl(
6469
@AuthenticationPrincipal Member member,
@@ -72,6 +77,7 @@ public ResponseEntity<Response<String>> updateProfileImageUrl(
7277
return ResponseEntity.ok(Response.success("프로필 이미지 저장 성공", "SUCCESS"));
7378
}
7479

80+
@SecurityRequirement(name = "bearerAuth")
7581
@PatchMapping("/members/bio")
7682
public ResponseEntity<Response<String>> editBio(
7783
@RequestBody @Valid EditBioRequestDto requestDto

src/main/java/com/example/FixLog/controller/MypagePostController.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ public ResponseEntity<Response<PageResponseDto<MyPostPageResponseDto>>> getMyPos
3333
return ResponseEntity.ok(Response.success("내가 작성한 글 보기 성공", data));
3434
}
3535

36-
// // 내가 좋아요한 글
37-
// @GetMapping("/likes")
38-
// public ResponseEntity<Response<PageResponseDto<MyPostPageResponseDto>>> getLikedPosts(
39-
// @AuthenticationPrincipal UserDetails userDetails,
40-
// @RequestParam(defaultValue = "0") int page,
41-
// @RequestParam(defaultValue = "4") int size,
42-
// @RequestParam(defaultValue = "0") int sort) {
43-
//
44-
// String email = userDetails.getUsername();
45-
// PageResponseDto<MyPostPageResponseDto> result = mypagePostService.getLikedPosts(email, page, sort, size);
46-
// return ResponseEntity.ok(Response.success("내가 좋아요한 글 보기 성공", result));
47-
// }
36+
// 내가 좋아요한 글
37+
@GetMapping("/likes")
38+
public ResponseEntity<Response<PageResponseDto<MyPostPageResponseDto>>> getLikedPosts(
39+
@AuthenticationPrincipal UserDetails userDetails,
40+
@RequestParam(defaultValue = "0") int page,
41+
@RequestParam(defaultValue = "4") int size,
42+
@RequestParam(defaultValue = "0") int sort) {
43+
44+
String email = userDetails.getUsername();
45+
PageResponseDto<MyPostPageResponseDto> result = mypagePostService.getLikedPosts(email, page, sort, size);
46+
return ResponseEntity.ok(Response.success("내가 좋아요한 글 보기 성공", result));
47+
}
4848

4949

5050
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.FixLog.controller;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
6+
@Controller
7+
public class RedirectController {
8+
9+
@GetMapping("/")
10+
public String redirectToMain() {
11+
return "redirect:/main";
12+
}
13+
}

src/main/resources/application.properties

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
spring.application.name=FixLog
22

3-
##### [DEV - ?? ??] #####
3+
4+
##### [DEV] #####
5+
server.port=8083
6+
7+
# DB
8+
49
server.port=8083
510

6-
# DB (MySQL - ???)
11+
# DB (MySQL)
712
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
813
spring.datasource.url=jdbc:mysql://fixlog-db.c7cau8y2srl7.ap-northeast-2.rds.amazonaws.com:3306/fixlog?serverTimezone=Asia/Seoul
914
spring.datasource.username=admin
@@ -29,7 +34,9 @@ logging.level.org.springframework.security=DEBUG
2934

3035

3136

32-
##### [PROD - ?? ??] #####
37+
38+
##### [PROD] #####
39+
3340
# server.port=8083
3441
#
3542
# spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

0 commit comments

Comments
 (0)