diff --git a/src/main/kotlin/com/example/boheom/domain/feed/facade/FeedFacade.kt b/src/main/kotlin/com/example/boheom/domain/feed/facade/FeedFacade.kt index 771ae94..11da587 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/facade/FeedFacade.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/facade/FeedFacade.kt @@ -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.* @@ -20,12 +21,13 @@ class FeedFacade( return feedRepository.findById(feedId).orElseThrow { FeedNotFoundException } } - fun getFeedList(feeds: List): List { + fun getFeedList(feeds: List, user: User): List { 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) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/presentation/dto/response/FeedElement.kt b/src/main/kotlin/com/example/boheom/domain/feed/presentation/dto/response/FeedElement.kt index 2e0b09b..794d92b 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/presentation/dto/response/FeedElement.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/presentation/dto/response/FeedElement.kt @@ -9,5 +9,6 @@ data class FeedElement( val view: Int, val tags: List, val recruitment: Int, - val applyCount: Int + val applyCount: Int, + val isApplied: Boolean, ) \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryApplyFeedService.kt b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryApplyFeedService.kt index ae6d4b9..f8c64a1 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryApplyFeedService.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryApplyFeedService.kt @@ -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)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryCategoryFeedService.kt b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryCategoryFeedService.kt index 0d29d1a..26b972e 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryCategoryFeedService.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryCategoryFeedService.kt @@ -3,6 +3,7 @@ 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 @@ -10,10 +11,12 @@ import org.springframework.transaction.annotation.Transactional 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)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryMyFeedService.kt b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryMyFeedService.kt index 9e9826f..6b75a35 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryMyFeedService.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryMyFeedService.kt @@ -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)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryPopularFeedListService.kt b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryPopularFeedListService.kt index 5236c09..ec242d4 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryPopularFeedListService.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryPopularFeedListService.kt @@ -3,6 +3,7 @@ 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 @@ -10,10 +11,12 @@ import org.springframework.transaction.annotation.Transactional 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)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryRecentFeedService.kt b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryRecentFeedService.kt index e1baffc..98c3355 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/service/QueryRecentFeedService.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/service/QueryRecentFeedService.kt @@ -3,6 +3,7 @@ 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 @@ -10,10 +11,12 @@ import org.springframework.transaction.annotation.Transactional 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)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/service/SearchFeedService.kt b/src/main/kotlin/com/example/boheom/domain/feed/service/SearchFeedService.kt index 0fcf0aa..0de684b 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/service/SearchFeedService.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/service/SearchFeedService.kt @@ -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) ) } } \ No newline at end of file