Skip to content

Commit 7b46841

Browse files
authored
Merge pull request #52 from Block-Guard/feat/#51/selected-news-api
[Feat] 주요 뉴스 조회 API
2 parents 7b5ac6e + 93e4e0f commit 7b46841

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/main/java/com/blockguard/server/domain/news/api/NewsApi.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.blockguard.server.domain.news.api;
22

33
import com.blockguard.server.domain.news.application.NewsService;
4+
import com.blockguard.server.domain.news.dto.response.NewsArticleResponse;
45
import com.blockguard.server.domain.news.dto.response.NewsPageResponse;
56
import com.blockguard.server.global.common.codes.SuccessCode;
67
import com.blockguard.server.global.common.response.BaseResponse;
@@ -11,6 +12,8 @@
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.springframework.web.bind.annotation.*;
1314

15+
import java.util.List;
16+
1417
@RestController
1518
@RequestMapping("/api/news")
1619
@AllArgsConstructor
@@ -30,4 +33,12 @@ public BaseResponse<NewsPageResponse> getNewsArticles(
3033
return BaseResponse.of(SuccessCode.GET_NEWS_ARTICLES_SUCCESS, newsPageResponse);
3134
}
3235

36+
@GetMapping("/selected")
37+
@CustomExceptionDescription(SwaggerResponseDescription.GET_NEWS_ARTICLES_FAIL)
38+
@Operation(summary = "주요 뉴스 조회")
39+
public BaseResponse<List<NewsArticleResponse>> getSelectedArticles(){
40+
List<NewsArticleResponse> selectedArticles = newsService.getSelectedArticles();
41+
return BaseResponse.of(SuccessCode.GET_SELECTED_NEWS_SUCCESS, selectedArticles);
42+
}
43+
3344
}

src/main/java/com/blockguard/server/domain/news/application/NewsService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ private Sort getSort(String sort) {
6464
}
6565

6666

67+
public List<NewsArticleResponse> getSelectedArticles() {
68+
List<Long> selectedIds = List.of(1L, 2L, 3L, 4L, 5L, 6L);
69+
List<NewsArticle> articles = newsRepository.findAllById(selectedIds);
70+
71+
return articles.stream().map(NewsArticleResponse::from)
72+
.toList();
73+
}
6774
}

src/main/java/com/blockguard/server/global/common/codes/SuccessCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public enum SuccessCode {
3333
UPDATE_STEP_INFO_SUCCESS(HttpStatus.OK,2022, "신고 단계 정보가 성공적으로 업데이트 되었습니다."),
3434
GET_NEWS_ARTICLES_SUCCESS(HttpStatus.OK, 2023, "뉴스 목록 조회가 완료되었습니다."),
3535
CRWAL_DAUM_NEWS_SUCCESS(HttpStatus.OK, 2024, "뉴스 크롤링이 완료되었습니다."),
36-
ADMIN_TOKEN_SUCCESS(HttpStatus.OK, 2025, "관리자 토큰이 발급되었습니다.");
36+
ADMIN_TOKEN_SUCCESS(HttpStatus.OK, 2025, "관리자 토큰이 발급되었습니다."),
37+
GET_SELECTED_NEWS_SUCCESS(HttpStatus.OK, 2026, "선택된 주요 뉴스 6개가 조회 완료되었습니다.");
3738

3839
private final HttpStatus status;
3940
private final int code;

src/main/java/com/blockguard/server/global/config/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti
5656
.requestMatchers("/api/auth/**").permitAll() // 로그인 및 회원가입
5757
.requestMatchers("/api/admin/login").permitAll() // 관리자 로그인
5858
.requestMatchers("/api/fraud/url", "/api/fraud/number","/api/fraud-analysis").permitAll() // 사기 분석
59-
.requestMatchers("/api/news").permitAll() // 뉴스 조회
59+
.requestMatchers("/api/news","/api/news/selected").permitAll() // 뉴스 조회
6060
.requestMatchers("/actuator/health").permitAll() // 헬스체크 허용
6161
.requestMatchers("/", "/index.html", "/favicon.ico").permitAll()
6262
.requestMatchers("/v3/api-docs/**", "/swagger-ui.html", "/swagger-ui/**", "/swagger-resources/**", "/webjars/**").permitAll()

0 commit comments

Comments
 (0)