Skip to content

Commit

Permalink
Merge pull request #24 from 7th-UMC-Hackathon-TeamV/feature/dev
Browse files Browse the repository at this point in the history
Feature/dev
  • Loading branch information
bikooju authored Jan 11, 2025
2 parents 9bf2d04 + ca880df commit 0730e60
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/main/java/banban/springboot/service/NewsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,28 @@ public void deleteOldNews() {
LocalDateTime yesterdayAt6PM = now.minusDays(1).withHour(17).withMinute(59).withSecond(59);
newsRepository.deleteByCreatedAtBetween(twoYesterdayAt6PM, yesterdayAt6PM);
}

/***
* 어제 18시부터 작성한 글에서 오늘 18시전까지 작성한 글 목록 조회
*/
public List<NewsResponseDTO.NewsReadResponseDTO> getNewsBetweenYesterday18ToToday18(String groupKey) {
// 그룹 확인
TeamGroup teamGroup = groupRepository.findByGroupKey(groupKey)
.orElseThrow(() -> new GeneralException(ErrorStatus.TEAMGROUP_NOT_FOUND));

// 현재 시간
LocalDateTime now = getCurrentTime();

// 어제 18시부터 오늘 18시전까지
LocalDateTime yesterdayAt6PM = now.minusDays(1).withHour(18).withMinute(0).withSecond(0);
LocalDateTime todayAt6PM = now.withHour(17).withMinute(59).withSecond(59);

// 뉴스 조회
List<News> newsList = newsRepository.findByTeamGroupAndCreatedAtBetween(teamGroup, yesterdayAt6PM, todayAt6PM);

// 뉴스 -> DTO 변환
return newsList.stream()
.map(NewsResponseDTO.NewsReadResponseDTO::from)
.toList();
}
}
11 changes: 11 additions & 0 deletions src/main/java/banban/springboot/web/controller/NewsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,15 @@ public ApiResponse<List<NewsResponseDTO.NewsYesterdayResponseDTO>> getYesterdayN
List<NewsResponseDTO.NewsYesterdayResponseDTO> yesterdayNews = newsService.getYesterdayNews(groupKey, memberId);
return ApiResponse.onSuccess(yesterdayNews);
}

@GetMapping("/{groupKey}/news/yesterday-today")
@Operation(summary = "어제 18시부터 오늘 18시 전까지 뉴스 조회")
@Parameters({
@Parameter(name = "groupKey", description = "그룹 키")
})
public ApiResponse<List<NewsResponseDTO.NewsReadResponseDTO>> getNewsBetweenYesterday18ToToday18(
@PathVariable String groupKey) {
List<NewsResponseDTO.NewsReadResponseDTO> newsList = newsService.getNewsBetweenYesterday18ToToday18(groupKey);
return ApiResponse.onSuccess(newsList);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package banban.springboot.web.dto.response;

import banban.springboot.domain.entity.News;
import banban.springboot.domain.enums.NewsCategories;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -20,8 +21,8 @@ public static class NewsCreateResponseDTO {
private String headline;
private String content;
private String images;
private boolean isBreakingNews;
private LocalDateTime createdAt;
private boolean isBreakingNews;

public static NewsCreateResponseDTO from(News news) {
return NewsCreateResponseDTO.builder()
Expand All @@ -46,6 +47,7 @@ public static class NewsReadResponseDTO {
private String content;
private String username;
private boolean isBreakingNews;
private NewsCategories newsCategories;
private String images;

public static NewsReadResponseDTO from(News news) {
Expand All @@ -56,6 +58,7 @@ public static NewsReadResponseDTO from(News news) {
.username(news.getMember().getUsername())
.isBreakingNews(news.isBreakingNews())
.images(news.getThumbnail_URL())
.newsCategories(news.getNewsCategories())
.build();
}
}
Expand Down

0 comments on commit 0730e60

Please sign in to comment.