Skip to content

Commit

Permalink
add :: get apply-user list
Browse files Browse the repository at this point in the history
  • Loading branch information
jyk1029 committed Jan 24, 2024
1 parent b395ce4 commit 9626073
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ interface ApplyRepository : JpaRepository<Apply, UUID> {
fun existsByUserAndFeed(user: User, feed: Feed): Boolean
fun countByFeed(feed: Feed): Int
fun findByUser(user: User): List<Apply>
fun findByFeed(feed: Feed): List<Apply>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.example.boheom.domain.feed.presentation.dto.request.UpdateFeedRequest
import com.example.boheom.domain.feed.presentation.dto.response.FeedDetailsResponse
import com.example.boheom.domain.feed.presentation.dto.response.FeedListResponse
import com.example.boheom.domain.feed.presentation.dto.response.PageFeedListResponse
import com.example.boheom.domain.feed.presentation.dto.response.QueryApplyUserListResponse
import com.example.boheom.domain.feed.service.CreateFeedService
import com.example.boheom.domain.feed.service.DeleteFeedService
import com.example.boheom.domain.feed.service.FeedApplyService
Expand All @@ -16,6 +17,7 @@ import com.example.boheom.domain.feed.service.QueryPopularFeedListService
import com.example.boheom.domain.feed.service.QueryRecentFeedService
import com.example.boheom.domain.feed.service.SearchFeedService
import com.example.boheom.domain.feed.service.CancelApplyService
import com.example.boheom.domain.feed.service.QueryApplyUserListService
import com.example.boheom.domain.feed.service.UpdateFeedService
import org.springframework.data.domain.Pageable
import org.springframework.data.web.PageableDefault
Expand Down Expand Up @@ -48,6 +50,7 @@ class FeedController(
private val searchFeedService: SearchFeedService,
private val queryApplyFeedService: QueryApplyFeedService,
private val queryMyFeedService: QueryMyFeedService,
private val queryApplyUserListService: QueryApplyUserListService,
) {
@ResponseStatus(CREATED)
@PostMapping
Expand Down Expand Up @@ -113,4 +116,9 @@ class FeedController(
fun getMyFeed(): FeedListResponse {
return queryMyFeedService.execute()
}

@GetMapping("/apply-user/{feed-id}")
fun getAppliedUserList(@PathVariable("feed-id") feedId: UUID): QueryApplyUserListResponse {
return queryApplyUserListService.execute(feedId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.boheom.domain.feed.presentation.dto.response

import com.example.boheom.domain.user.presentation.dto.response.UserElement

data class QueryApplyUserListResponse(
val users: List<UserElement>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.boheom.domain.feed.service

import com.example.boheom.domain.feed.domain.repository.ApplyRepository
import com.example.boheom.domain.feed.exception.IncorrectUserException
import com.example.boheom.domain.feed.facade.FeedFacade
import com.example.boheom.domain.feed.presentation.dto.response.QueryApplyUserListResponse
import com.example.boheom.domain.user.presentation.dto.response.UserElement
import com.example.boheom.domain.user.facade.UserFacade
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.UUID

@Service
class QueryApplyUserListService(
private val userFacade: UserFacade,
private val feedFacade: FeedFacade,
private val applyRepository: ApplyRepository,
) {
@Transactional(readOnly = true)
fun execute(feedId: UUID): QueryApplyUserListResponse {
val user = userFacade.getCurrentUser()
val feed = feedFacade.getByFeedId(feedId)
val applyUser = applyRepository.findByFeed(feed).map { it.user }

if (user != feed.user) {
throw IncorrectUserException
}

return QueryApplyUserListResponse(applyUser.map { UserElement(it.profile, it.nickname, it.accountId) })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.boheom.domain.user.presentation.dto.response

data class UserElement(
val profile: String,
val nickname: String,
val accountId: String,
)

0 comments on commit 9626073

Please sign in to comment.