Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

#104 swagger 추가 #105

Merged
merged 19 commits into from
Jul 31, 2021
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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ dependencies {
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.2' // caffeine cache
implementation 'net.time4j:time4j-base:5.7' // time4j 음력->양력 변환을 위해 사용

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

// lombok
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class UserAuthInterceptor implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if (!(handler instanceof HandlerMethod)) {
return true;
}

if (Authentication.isAnnotated(((HandlerMethod) handler).getMethod())) {
Authentication auth = authenticationService.getAuthentication(request.getHeader(AUTHORIZATION))
.orElseThrow(() -> new ApiException(INVALID_AUTHENTICATION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@


@RequestMapping("/users")
@AuthenticationRequired
public interface UserManagementController {

@AuthenticationRequired
@GetMapping("/")
ResponseEntity<HttpResponse<Authentication>> getLoggedInUser(Authentication user);

Expand All @@ -32,12 +33,14 @@ public interface UserManagementController {
* @param request
* @return 요청 성공시 204 NO_CONTENT
*/
@AuthenticationRequired
@DeleteMapping("/{id}")
ResponseEntity<?> deleteAccount(@PathVariable("id") Long id,
@Valid @RequestBody DeleteAccountRequest deleteRequest,
HttpServletRequest request);



@AuthenticationRequired
@PatchMapping("/{id}")
ResponseEntity<HttpResponse<?>> updateAccount(@PathVariable Long id,
@Valid @RequestBody UpdateAccountRequest updateRequest,
Expand All @@ -50,6 +53,7 @@ ResponseEntity<HttpResponse<?>> updateAccount(@PathVariable Long id,
* @param addressParam 주소 정보
* @return
*/
@AuthenticationRequired
@PostMapping("/{id}/addresses")
ResponseEntity<HttpResponse<?>> addAddress(@PathVariable("id") Long id,
@Valid @RequestBody AddAddressRequest addressParam);
Expand All @@ -61,6 +65,7 @@ ResponseEntity<HttpResponse<?>> addAddress(@PathVariable("id") Long id,
* @param addressId 주소 정보
* @return
*/
@AuthenticationRequired
@PostMapping("/{id}/addresses/main/{addrId}")
ResponseEntity<HttpResponse<?>> setMainAddress(@PathVariable("id") Long id, @PathVariable("addrId") Long addressId);

Expand All @@ -71,6 +76,7 @@ ResponseEntity<HttpResponse<?>> addAddress(@PathVariable("id") Long id,
* @param addressId 주소 정보
* @return
*/
@AuthenticationRequired
@DeleteMapping("/{id}/addresses/{addrId}")
ResponseEntity<?> removeAddress(@PathVariable("id") Long id, @PathVariable("addrId") Long addressId);

Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/bluedelivery/common/config/Swagger2Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.bluedelivery.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import com.google.common.net.HttpHeaders;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
@Profile("!prod")
public class Swagger2Config {
private static final String API_NAME = "Blue-Delivery API";
private static final String API_VERSION = "0.0.1";
private static final String API_DESCRIPTION = "API 명세서";

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}

public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(API_NAME)
.version(API_VERSION)
.description(API_DESCRIPTION)
.build();
}

}