Skip to content

Commit

Permalink
update :: feed element
Browse files Browse the repository at this point in the history
  • Loading branch information
jyk1029 committed Jan 24, 2024
1 parent 9aa5b88 commit b395ce4
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.example.boheom.domain.feed.domain.repository.FeedTagRepository
import com.example.boheom.domain.feed.exception.FeedNotFoundException
import com.example.boheom.domain.feed.presentation.dto.response.FeedElement
import com.example.boheom.domain.feed.presentation.dto.response.FeedListResponse
import com.example.boheom.domain.user.domain.User
import org.springframework.stereotype.Component
import java.util.*

Expand All @@ -20,12 +21,13 @@ class FeedFacade(
return feedRepository.findById(feedId).orElseThrow { FeedNotFoundException }
}

fun getFeedList(feeds: List<Feed>): List<FeedElement> {
fun getFeedList(feeds: List<Feed>, user: User): List<FeedElement> {
return feeds.map { feed ->
val tags = feedTagRepository.findAllByFeed(feed)
val applyCount = applyRepository.countByFeed(feed)
val isApplied = applyRepository.existsByUserAndFeed(user, feed)

FeedElement(feed.id, feed.title, feed.content, feed.view, tags.map { it.name }, feed.recruitment, applyCount)
FeedElement(feed.id, feed.title, feed.content, feed.view, tags.map { it.name }, feed.recruitment, applyCount, isApplied)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ data class FeedElement(
val view: Int,
val tags: List<String>,
val recruitment: Int,
val applyCount: Int
val applyCount: Int,
val isApplied: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class QueryApplyFeedService(
fun execute(): FeedListResponse {
val user = userFacade.getCurrentUser()
val feeds = applyRepository.findByUser(user).map { it.feed }
return FeedListResponse(feedFacade.getFeedList(feeds))
return FeedListResponse(feedFacade.getFeedList(feeds, user))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package com.example.boheom.domain.feed.service
import com.example.boheom.domain.feed.domain.repository.FeedTagRepository
import com.example.boheom.domain.feed.facade.FeedFacade
import com.example.boheom.domain.feed.presentation.dto.response.FeedListResponse
import com.example.boheom.domain.user.facade.UserFacade
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class QueryCategoryFeedService(
private val feedTagRepository: FeedTagRepository,
private val feedFacade: FeedFacade,
private val userFacade: UserFacade,
) {
@Transactional(readOnly = true)
fun execute(keyword: String): FeedListResponse {
val user = userFacade.getCurrentUser()
val feedTags = feedTagRepository.findAllByNameContaining(keyword)
return FeedListResponse(feedFacade.getFeedList(feedTags.map { it.feed }))
return FeedListResponse(feedFacade.getFeedList(feedTags.map { it.feed }, user))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class QueryMyFeedService(
fun execute(): FeedListResponse {
val user = userFacade.getCurrentUser()
val feeds = feedRepository.findAllByUserOrderByCreatedAtAsc(user)
return FeedListResponse(feedFacade.getFeedList(feeds))
return FeedListResponse(feedFacade.getFeedList(feeds, user))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package com.example.boheom.domain.feed.service
import com.example.boheom.domain.feed.domain.repository.FeedRepository
import com.example.boheom.domain.feed.facade.FeedFacade
import com.example.boheom.domain.feed.presentation.dto.response.FeedListResponse
import com.example.boheom.domain.user.facade.UserFacade
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class QueryPopularFeedListService(
private val feedRepository: FeedRepository,
private val feedFacade: FeedFacade,
private val userFacade: UserFacade,
) {
@Transactional(readOnly = true)
fun execute(): FeedListResponse {
val user = userFacade.getCurrentUser()
val feeds = feedRepository.findAllByOrderByViewDesc()
return FeedListResponse(feedFacade.getFeedList(feeds))
return FeedListResponse(feedFacade.getFeedList(feeds, user))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package com.example.boheom.domain.feed.service
import com.example.boheom.domain.feed.domain.repository.FeedRepository
import com.example.boheom.domain.feed.facade.FeedFacade
import com.example.boheom.domain.feed.presentation.dto.response.FeedListResponse
import com.example.boheom.domain.user.facade.UserFacade
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class QueryRecentFeedService(
private val feedRepository: FeedRepository,
private val feedFacade: FeedFacade,
private val userFacade: UserFacade,
) {
@Transactional(readOnly = true)
fun execute(): FeedListResponse {
val user = userFacade.getCurrentUser()
val feeds = feedRepository.findAllByOrderByCreatedAtAsc()
return FeedListResponse(feedFacade.getFeedList(feeds))
return FeedListResponse(feedFacade.getFeedList(feeds, user))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ package com.example.boheom.domain.feed.service
import com.example.boheom.domain.feed.domain.repository.FeedRepository
import com.example.boheom.domain.feed.facade.FeedFacade
import com.example.boheom.domain.feed.presentation.dto.response.PageFeedListResponse
import com.example.boheom.domain.user.facade.UserFacade
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class SearchFeedService(
private val userFacade: UserFacade,
private val feedFacade: FeedFacade,
private val feedRepository: FeedRepository
) {
@Transactional(readOnly = true)
fun execute(keyword: String, pageable: Pageable): PageFeedListResponse {
val user = userFacade.getCurrentUser()
val feeds = feedRepository.findAllByTitleContainingOrderByCreatedAtAsc(keyword, pageable)
return PageFeedListResponse(
feeds.totalPages,
feeds.totalPages.equals(pageable.pageNumber + 1),
feedFacade.getFeedList(feeds.content)
feedFacade.getFeedList(feeds.content, user)
)
}
}

0 comments on commit b395ce4

Please sign in to comment.