Skip to content

Commit

Permalink
Merge pull request #86 from wafflestudio/feat/feed
Browse files Browse the repository at this point in the history
동네생활 게시물 인기순 목록 반환 기능
  • Loading branch information
alpakar02 authored Feb 1, 2025
2 parents 0834ebb + b84b198 commit 0d9c413
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ class FeedController(
return ResponseEntity.ok(response)
}

@GetMapping("/feed/popular")
fun getPopularFeeds(
@RequestParam("feedId") feedId: Long,
@AuthUser user: User,
): ResponseEntity<List<FeedPreview>> {
val feeds = feedService.getPopularFeeds(feedId)
val response: List<FeedPreview> =
feeds.map { feed ->
FeedPreview.fromEntity(feed)
}
return ResponseEntity.ok(response)
}

@GetMapping("/feed/search/{feedId}")
fun searchFeeds(
@RequestBody request: SearchRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ interface FeedRepository : JpaRepository<FeedEntity, Long> {
content: String,
id: Long,
): List<FeedEntity>

fun findTop10ByIdLessThanOrderByViewCountDescIdDesc(id: Long): List<FeedEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ class FeedService(
return feeds.subList(0, 10)
}

@Transactional
fun getPopularFeeds(feedId: Long): List<FeedEntity> {
val feeds = feedRepository.findTop10ByIdLessThanOrderByViewCountDescIdDesc(feedId)
refreshPresignedUrlIfExpired(feeds)
return feeds
}

@Transactional
fun searchFeed(
request: SearchRequest,
Expand Down

0 comments on commit 0d9c413

Please sign in to comment.