43 lines
1.6 KiB
Java
43 lines
1.6 KiB
Java
package com.myoa.engineering.crawl.ppomppu.processor.controller;
|
|
|
|
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
|
import com.myoa.engineering.crawl.ppomppu.support.dto.APIResponse;
|
|
import com.myoa.engineering.crawl.ppomppu.processor.dto.FeedParsedResult;
|
|
import com.myoa.engineering.crawl.ppomppu.processor.service.PpomppuFeedService;
|
|
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
/**
|
|
* CrawlAPIController
|
|
*
|
|
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
|
* @since 2021-09-05
|
|
*/
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("/api/v1/crawl")
|
|
public class CrawlAPIController {
|
|
|
|
private final PpomppuFeedService ppomppuRSSFeedService;
|
|
|
|
public CrawlAPIController(PpomppuFeedService ppomppuRSSFeedService) {
|
|
this.ppomppuRSSFeedService = ppomppuRSSFeedService;
|
|
}
|
|
|
|
@PostMapping("/boards/{boardName}")
|
|
public Mono<APIResponse<FeedParsedResult>> crawlBoard(@PathVariable("boardName") PpomppuBoardName boardName) {
|
|
log.info("got request... {}", boardName);
|
|
FeedParsedResult result = FeedParsedResult.of(boardName);
|
|
Flux<PpomppuArticle> articles = ppomppuRSSFeedService.getArticles(boardName);
|
|
|
|
return articles.then(Mono.just(APIResponse.success(result.done())));
|
|
}
|
|
|
|
}
|