Skip to content

Commit

Permalink
Merge pull request #31 from 2024-pre-onboarding-backend-F/feat/create…
Browse files Browse the repository at this point in the history
…_swagger

[feat] swagger 설정 기능 구현
  • Loading branch information
jeongeungyeong authored Oct 2, 2024
2 parents 58e256b + 7de58b2 commit 0e301e7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt:0.9.1' // 자바 JWT 라이브러리
implementation 'javax.xml.bind:jaxb-api:2.3.1' // XML 문서와 Java 객체 간 매핑 자동화
testAnnotationProcessor('org.projectlombok:lombok')

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
// Jackson
implementation 'com.fasterxml.jackson.core:jackson-databind'
// Spring Batch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package wanted.ribbon.datapipe.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -12,24 +14,28 @@
@RestController
@RequestMapping("/api/datapipes")
@RequiredArgsConstructor
@Tag(name="DataPipe",description = "경기도 공공데이터 수집 관련 API입니다.")
public class OpenApiController {
private final GenrestrtService genrestrtService;
private final RawDataService rawDataService;

// 경기도 맛집 데이터 수집 API (RestTemplate), responsebody 사용으로 PostMapping으로 진행
@PostMapping("/fetch-data")
@Operation(summary = "경기도 맛집 수집", description = "경기도 맛집 데이터를 restTemplate 방식으로 가져옵니다. " +
"김밥, 중국식, 일식 등 일부 카테고리만 가져올 수 있습니다.")
public ResponseEntity<String> fetchData(@RequestParam("serviceName") String serviceName) {
// openAPI 호출
genrestrtService.fetchAndSaveData(serviceName);
return ResponseEntity.ok(serviceName + "가 db에 성공적으로 저장됐습니다.");
}

// 경기도 맛집 데이터 수집 API (WebClient, 모든 경기도 맛집 api 가능)
/**
* 데이터 조회로 GetMapping 사용
* 비동기 처리를 위한 Mono 사용
*/
@GetMapping("/fetch-and-save")
@Operation(summary = "경기도 맛집 수집", description = "경기도 맛집 데이터를 webClient 방식으로 가져옵니다. " +
"경기도 맛집의 모든 음식점 카테고리를 가져올 수 있습니다.")
public Mono<ResponseEntity<GyeongGiList>> fetchAndSaveData(@RequestParam("serviceName") String serviceName) {
return rawDataService.getAndSaveByServiceName(serviceName)
.map(ResponseEntity::ok)
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/wanted/ribbon/global/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package wanted.ribbon.global.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder() //경로 설정
.group("springdoc-public")
.pathsToMatch("/**")
.build();
}

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("Yellow-Ribbon API")
.version("v2")
.description("옐로리본 운영서버 API 명세서"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.authorizeRequests(auth -> auth
.requestMatchers("/api/users/login", "/api/users/signup").permitAll()
.requestMatchers("/api/datapipes/**").permitAll() // 데이터파이프라인 모든 권한 허용
.requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-resources/**").permitAll() //swagger
.anyRequest().authenticated())
.formLogin(AbstractHttpConfigurer::disable)
.addFilterBefore(new TokenAuthenticationFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class);
Expand Down

0 comments on commit 0e301e7

Please sign in to comment.