Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.globalTimes_be.domain.news.controller;

import com.example.globalTimes_be.domain.news.exception.NewsErrorStatus;
import com.example.globalTimes_be.domain.news.service.AiService;
import com.example.globalTimes_be.domain.news.service.AiSseService;
import com.example.globalTimes_be.domain.news.service.NewsService;
import com.example.globalTimes_be.global.apiPayload.code.ApiResponse;
import com.example.globalTimes_be.global.apiPayload.code.status.GlobalSuccessStatus;
import com.example.globalTimes_be.global.exception.BaseException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -28,6 +30,14 @@ public ResponseEntity<ApiResponse> summarizeArticle(@PathVariable Long id,
//ν•΄λ‹Ή 기사 λ‚΄μš©μ„ κ°€μ Έμ˜΄
String crawledContent = newsService.getArticleCrawledContent(id);

//ν¬λ‘€λ§ν•œ 기사 λ‚΄μš©μ΄ μ—†μœΌλ©΄ λ³Έλ¬Έ μ„œλ‘ λ°˜ν™˜
if (crawledContent == null) {
//기사 id에 λ§žλŠ” content κ°€μ Έμ˜΄
String content = newsService.getArticleContent(id);

return ApiResponse.fail(NewsErrorStatus._CRAWLER_ERROR.getResponse(), content);
}

//ν•΄λ‹Ή 기사λ₯Ό μš”μ•½ν•¨
String summary = aiService.summarizeArticle(crawledContent, language);

Expand All @@ -42,6 +52,11 @@ public SseEmitter summarizeArticleSse(@PathVariable Long id,
//ν•΄λ‹Ή 기사 λ‚΄μš©μ„ κ°€μ Έμ˜΄
String crawledContent = newsService.getArticleCrawledContent(id);

//ν¬λ‘€λ§ν•œ 기사 λ‚΄μš©μ΄ μ—†μœΌλ©΄ μ—λŸ¬ 처리
if (crawledContent == null) {
throw new BaseException(NewsErrorStatus._CRAWLER_ERROR.getResponse());
}

//GPT μš”μ•½ μš”μ²­ ν›„ SSE 슀트리밍 전솑
return aiSseService.summarizeContent(crawledContent, language);
}
Expand All @@ -53,7 +68,11 @@ public SseEmitter askArticle(@PathVariable Long id,
@RequestParam String question){
//ν•΄λ‹Ή 기사 λ‚΄μš©μ„ κ°€μ Έμ˜΄
String crawledContent = newsService.getArticleCrawledContent(id);


//ν¬λ‘€λ§ν•œ 기사 λ‚΄μš©μ΄ μ—†μœΌλ©΄ μ—λŸ¬ 처리
if (crawledContent == null) {
throw new BaseException(NewsErrorStatus._CRAWLER_ERROR.getResponse());
}
//GPT λ‹΅λ³€ μš”μ²­ ν›„ SSE 슀트리밍 전솑
return aiSseService.askGPT(crawledContent, question);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public interface AiControllerDocs {
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = """
{
"timestamp": "2024-10-30T15:38:12.43483271",
"isSuccess": false,
"message": "ν•΄λ‹Ή μ–Έλ‘ μ‚¬λŠ” μš”μ•½ 정보 제곡이 λΆˆκ°€λŠ₯ν•©λ‹ˆλ‹€.",
"data": null
}
"timestamp": "2025-04-01T13:37:56.6982049",
"isSuccess": false,
"message": "ν•΄λ‹Ή μ–Έλ‘ μ‚¬λŠ” μš”μ•½ 정보 제곡이 λΆˆκ°€λŠ₯ν•©λ‹ˆλ‹€.",
"data": "NEWARK With a mastery of collaborative, often pretty basketball that belied both its youth and the volatile state of the college sport, Duke soared to the programs 18th Final Four on Saturday night, … [+5884 chars]"
}
""")
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface NewsControllerDocs {
"sourceName": "Politico",
"author": "Seb Starcevic",
"title": "Trump floats possibility of compensation for Jan. 6 rioters - POLITICO",
"viewCount": 1,
"url": "https://www.politico.com/news/2025/03/25/trump-floats-possibility-of-compensation-for-jan-6-rioters-00250063",
"urlToImage": "https://static.politico.com/7a/af/06aa55284352997b83a000983381/trump-63887.jpg",
"publishedAt": "2025-03-26T03:00:31Z"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public NewsResDTO getNewsDetail(Long id) {
.build();
}

//크둀링 μ‹€νŒ¨ μ‹œ λ³Έλ¬Έ μ„œλ‘ λ°˜ν™˜
public String getArticleContent(Long id) {
//λ‰΄μŠ€ 정보 κ°€μ Έμ˜΄
Article article = articleRepository.findById(id)
.orElseThrow(() -> new BaseException(NewsErrorStatus._EMPTY_NEWS_DATA.getResponse()));

return article.getContent();
}

//DB에 λ‰΄μŠ€ 기사가 μ—†μœΌλ©΄ 원본 λ‰΄μŠ€ μ‚¬μ΄νŠΈμ—μ„œ ν¬λ‘€λ§ν•΄μ˜΄
@Transactional
public String getArticleCrawledContent(Long id) {
Expand All @@ -91,9 +100,9 @@ public String getArticleCrawledContent(Long id) {
// 크둀러둜 기사 원문 κ°€μ Έμ˜΄
crawledContent = getCrawlerUrl(article.getUrl());

// 크둀링 μ‹€νŒ¨μ‹œ μ—λŸ¬μ²˜λ¦¬
// 크둀링 μ‹€νŒ¨μ‹œ return;
if (crawledContent == null) {
throw new BaseException(NewsErrorStatus._CRAWLER_ERROR.getResponse());
return null;
}

//DB에 μ €μž₯
Expand Down