-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from mash-up-kr/feature/voting
feat: Voting process
- Loading branch information
Showing
7 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
24 changes: 19 additions & 5 deletions
24
pic-api/src/main/kotlin/com/mashup/pic/vote/applicationservice/VoteApplicationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
package com.mashup.pic.vote.applicationservice | ||
|
||
import com.mashup.pic.domain.event.EventService | ||
import com.mashup.pic.domain.vote.VoteService | ||
import com.mashup.pic.vote.applicationservice.dto.VoteServiceRequest | ||
import com.mashup.pic.vote.controller.dto.VoteOptionItem | ||
import com.mashup.pic.vote.controller.dto.VoteOptionResponse | ||
import com.mashup.pic.vote.controller.dto.VoteResponse | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.springframework.web.bind.annotation.PathVariable | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class VoteApplicationService( | ||
private val voteService: VoteService | ||
private val voteService: VoteService, | ||
private val eventService: EventService | ||
) { | ||
fun getVoteOptions( | ||
@PathVariable eventId: Long | ||
): VoteOptionResponse { | ||
fun getVoteOptions(eventId: Long): VoteOptionResponse { | ||
val options = voteService.getVoteOptions(eventId).map { VoteOptionItem(it.id, it.imageUrl) } | ||
return VoteOptionResponse(options) | ||
} | ||
|
||
@Transactional | ||
fun vote(request: VoteServiceRequest): VoteResponse { | ||
voteService.vote( | ||
userId = request.userId, | ||
eventId = request.eventId, | ||
likedOptionIds = request.likedOptionIds | ||
) | ||
if (voteService.hasEveryoneVoted(request.eventId)) { | ||
eventService.endEventVoting(request.eventId) | ||
} | ||
return VoteResponse(request.eventId) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
pic-api/src/main/kotlin/com/mashup/pic/vote/applicationservice/dto/VoteServiceRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mashup.pic.vote.applicationservice.dto | ||
|
||
data class VoteServiceRequest( | ||
val userId: Long, | ||
val eventId: Long, | ||
val likedOptionIds: List<Long> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
pic-api/src/main/kotlin/com/mashup/pic/vote/controller/dto/VoteRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.mashup.pic.vote.controller.dto | ||
|
||
import com.mashup.pic.vote.applicationservice.dto.VoteServiceRequest | ||
import jakarta.validation.constraints.Size | ||
|
||
data class VoteRequest( | ||
val eventId: Long, | ||
@field:Size(min = 1) val likedOptionIds: List<Long> | ||
) | ||
|
||
fun VoteRequest.toServiceRequest(userId: Long): VoteServiceRequest = VoteServiceRequest(userId, this.eventId, this.likedOptionIds) |
5 changes: 5 additions & 0 deletions
5
pic-api/src/main/kotlin/com/mashup/pic/vote/controller/dto/VoteResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.mashup.pic.vote.controller.dto | ||
|
||
data class VoteResponse( | ||
val eventId: Long | ||
) |
4 changes: 4 additions & 0 deletions
4
pic-domain/src/main/kotlin/com/mashup/pic/domain/vote/VoteRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package com.mashup.pic.domain.vote | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
|
||
interface VoteRepository : JpaRepository<Vote, Long> { | ||
fun existsByEventJoinId(id: Long): Boolean | ||
|
||
@Query("SELECT COUNT(DISTINCT v.eventJoinId) FROM Vote v") | ||
fun countDistinctEventJoinIds(): Int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters