mirror of
https://github.com/headporter81/specialsource-homepage-backend.git
synced 2026-10-07 15:21:09 +09:00
Compare commits
1
Commits
53f28e2f09
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7547a1028 |
@@ -36,6 +36,21 @@ public class ScrapedPostController {
|
||||
return ResponseEntity.ok(posts);
|
||||
}
|
||||
|
||||
@GetMapping("/viewed")
|
||||
public ResponseEntity<?> getViewedPosts(
|
||||
@RequestParam(required = false) String board,
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "20") int size
|
||||
) {
|
||||
if (board != null && !isValidBoardKey(board)) {
|
||||
return ResponseEntity.badRequest().body("존재하지 않는 게시판 키입니다: " + board);
|
||||
}
|
||||
|
||||
Pageable pageable = PageRequest.of(page, Math.min(size, 100));
|
||||
Page<ScrapedPostResponse> posts = scrapedPostQueryService.getViewedPosts(board, pageable);
|
||||
return ResponseEntity.ok(posts);
|
||||
}
|
||||
|
||||
@GetMapping("/boards")
|
||||
public ResponseEntity<List<BoardSummaryResponse>> getBoards() {
|
||||
List<BoardSummaryResponse> boards = Arrays.stream(BoardSource.values())
|
||||
|
||||
@@ -15,6 +15,10 @@ public interface ScrapedPostRepository extends JpaRepository<ScrapedPost, Long>
|
||||
|
||||
Page<ScrapedPost> findByViewedAtIsNullOrderByScrapedAtDesc(Pageable pageable);
|
||||
|
||||
Page<ScrapedPost> findByBoardKeyAndViewedAtIsNotNullOrderByViewedAtDesc(String boardKey, Pageable pageable);
|
||||
|
||||
Page<ScrapedPost> findByViewedAtIsNotNullOrderByViewedAtDesc(Pageable pageable);
|
||||
|
||||
@Transactional
|
||||
long deleteByScrapedAtBefore(LocalDateTime cutoff);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,15 @@ public class ScrapedPostQueryService {
|
||||
return page.map(ScrapedPostResponse::from);
|
||||
}
|
||||
|
||||
public Page<ScrapedPostResponse> getViewedPosts(String boardKey, Pageable pageable) {
|
||||
// 조회한(viewedAt != null) 글만 최근 읽은 순으로 보여준다.
|
||||
Page<ScrapedPost> page = (boardKey == null || boardKey.isBlank())
|
||||
? scrapedPostRepository.findByViewedAtIsNotNullOrderByViewedAtDesc(pageable)
|
||||
: scrapedPostRepository.findByBoardKeyAndViewedAtIsNotNullOrderByViewedAtDesc(boardKey, pageable);
|
||||
|
||||
return page.map(ScrapedPostResponse::from);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void markViewed(Long id) {
|
||||
ScrapedPost post = scrapedPostRepository.findById(id)
|
||||
|
||||
@@ -18,7 +18,8 @@ public record ScrapedPostResponse(
|
||||
Integer likeCount,
|
||||
String content,
|
||||
List<String> imageUrls,
|
||||
LocalDateTime scrapedAt
|
||||
LocalDateTime scrapedAt,
|
||||
LocalDateTime viewedAt
|
||||
) {
|
||||
public static ScrapedPostResponse from(ScrapedPost post) {
|
||||
List<String> imageUrls = (post.getImageUrls() == null || post.getImageUrls().isBlank())
|
||||
@@ -38,7 +39,8 @@ public record ScrapedPostResponse(
|
||||
post.getLikeCount(),
|
||||
post.getContent(),
|
||||
imageUrls,
|
||||
post.getScrapedAt()
|
||||
post.getScrapedAt(),
|
||||
post.getViewedAt()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user