-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from 2024-pre-onboarding-backend-F/feat/create…
…_datapipe [feat] 데이터파이프라인 공공데이터 수집 기능 고도화
- Loading branch information
Showing
20 changed files
with
384 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/wanted/ribbon/datapipe/config/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package wanted.ribbon.datapipe.config; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import org.springframework.web.util.DefaultUriBuilderFactory; | ||
|
||
@Configuration | ||
public class AppConfig { | ||
@Value("${spring.public-api.base-url}") | ||
private String baseUrl; | ||
|
||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
|
||
@Bean | ||
public ObjectMapper objectMapper() { | ||
return new ObjectMapper(); | ||
} | ||
|
||
/* | ||
* WebClient의 UriComponentsBuilder.encode() 방식의 인코딩 방지 | ||
* key 값이 달라지는 것을 방지하기 위해 DefaultUriBuilderFactory 생성 | ||
* encoding 모드 지정 | ||
* */ | ||
@Bean | ||
public DefaultUriBuilderFactory builderFactory() { | ||
DefaultUriBuilderFactory builderFactory = new DefaultUriBuilderFactory(); | ||
builderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY); | ||
return builderFactory; | ||
} | ||
|
||
@Bean | ||
public WebClient webClient() { | ||
return WebClient.builder() | ||
.uriBuilderFactory(builderFactory()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/wanted/ribbon/datapipe/controller/OpenApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package wanted.ribbon.datapipe.controller; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import reactor.core.publisher.Mono; | ||
import wanted.ribbon.datapipe.dto.GyeongGiList; | ||
import wanted.ribbon.datapipe.service.GenrestrtService; | ||
import wanted.ribbon.datapipe.service.RawDataService; | ||
|
||
@RestController | ||
@RequestMapping("/api/datapipes") | ||
@RequiredArgsConstructor | ||
public class OpenApiController { | ||
private final GenrestrtService genrestrtService; | ||
private final RawDataService rawDataService; | ||
|
||
// 경기도 맛집 데이터 수집 API (RestTemplate), responsebody 사용으로 PostMapping으로 진행 | ||
@PostMapping("/fetch-data") | ||
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") | ||
public Mono<ResponseEntity<GyeongGiList>> fetchAndSaveData(@RequestParam("serviceName") String serviceName) { | ||
return rawDataService.getAndSaveByServiceName(serviceName) | ||
.map(ResponseEntity::ok) | ||
.defaultIfEmpty(ResponseEntity.notFound().build()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ed/ribbon/genrestrt/domain/Genrestrt.java → ...ted/ribbon/datapipe/domain/Genrestrt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/genrestrt/dto/GenrestrtApiResponse.java → ...on/datapipe/dto/GenrestrtApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/wanted/ribbon/datapipe/dto/GyeongGiList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package wanted.ribbon.datapipe.dto; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
public record GyeongGiList(String message, | ||
Long total, | ||
List<GyeongGiApiResponse> gyeongGiApiResponses) { | ||
public record GyeongGiApiResponse(String sigunNm, | ||
String sigunCd, | ||
String bizplcNm, | ||
Date licensgDe, | ||
String bsnStateNm, | ||
Date clsbizDe, | ||
Double locplcAr, | ||
String gradFacltDivNm, | ||
Long maleEnflpsnCnt, | ||
Integer yy, | ||
String multiUseBizestblYn, | ||
String gradDivNm, | ||
Double totFacltScale, | ||
Long femaleEnflpsnCnt, | ||
String bsnsiteCircumfrDivNm, | ||
String sanittnIndutypeNm, | ||
String sanittnBizcondNm, | ||
Long totEmplyCnt, | ||
String refineRoadnmAddr, | ||
String refineLotnoAddr, | ||
String refineZipCd, | ||
Double refineWgs84Lat, | ||
Double refineWgs84Logt){} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../wanted/ribbon/genrestrt/dto/RawData.java → ...a/wanted/ribbon/datapipe/dto/RawData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...on/genrestrt/mapper/RawDataRowMapper.java → ...bon/datapipe/mapper/RawDataRowMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../genrestrt/mapper/StoreDataRowMapper.java → ...n/datapipe/mapper/StoreDataRowMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...estrt/repository/GenrestrtRepository.java → ...apipe/repository/GenrestrtRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package wanted.ribbon.genrestrt.repository; | ||
package wanted.ribbon.datapipe.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import wanted.ribbon.genrestrt.domain.Genrestrt; | ||
import wanted.ribbon.datapipe.domain.Genrestrt; | ||
|
||
public interface GenrestrtRepository extends JpaRepository<Genrestrt, Long> { | ||
} |
4 changes: 2 additions & 2 deletions
4
...bbon/genrestrt/service/DataProcessor.java → ...ibbon/datapipe/service/DataProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.