@@ -2,22 +2,34 @@ package team.aliens.dms.domain.vote
22
33import jakarta.validation.Valid
44import org.jetbrains.annotations.NotNull
5+ import org.springframework.http.HttpStatus
56import org.springframework.web.bind.annotation.DeleteMapping
67import org.springframework.web.bind.annotation.GetMapping
78import org.springframework.web.bind.annotation.PatchMapping
89import org.springframework.web.bind.annotation.PathVariable
910import org.springframework.web.bind.annotation.PostMapping
1011import org.springframework.web.bind.annotation.RequestBody
1112import org.springframework.web.bind.annotation.RequestMapping
13+ import org.springframework.web.bind.annotation.RequestParam
14+ import org.springframework.web.bind.annotation.ResponseStatus
1215import org.springframework.web.bind.annotation.RestController
1316import team.aliens.dms.domain.vote.dto.reponse.VotingTopicsResponse
1417import team.aliens.dms.domain.vote.dto.request.CreateVoteTopicRequest
18+ import team.aliens.dms.domain.vote.dto.request.CreateVotingOptionRequest
19+ import team.aliens.dms.domain.vote.dto.request.CreateVotingOptionWebRequest
1520import team.aliens.dms.domain.vote.dto.request.CreateVotingTopicWebRequest
1621import team.aliens.dms.domain.vote.dto.request.UpdateVotingTopicRequest
1722import team.aliens.dms.domain.vote.dto.request.UpdateVotingTopicWebRequest
23+ import team.aliens.dms.domain.vote.dto.response.VotesResponse
24+ import team.aliens.dms.domain.vote.dto.response.VotingOptionsResponse
25+ import team.aliens.dms.domain.vote.usecase.CreateVoteUseCase
26+ import team.aliens.dms.domain.vote.usecase.CreateVotingOptionUseCase
1827import team.aliens.dms.domain.vote.usecase.CreateVotingTopicUseCase
28+ import team.aliens.dms.domain.vote.usecase.DeleteVoteUseCase
1929import team.aliens.dms.domain.vote.usecase.DeleteVotingTopicUseCase
2030import team.aliens.dms.domain.vote.usecase.QueryAllVotingTopicUseCase
31+ import team.aliens.dms.domain.vote.usecase.QueryVotesUseCase
32+ import team.aliens.dms.domain.vote.usecase.QueryVotingOptionsUseCase
2133import team.aliens.dms.domain.vote.usecase.UpdateVotingTopicUseCase
2234import java.util.UUID
2335
@@ -27,8 +39,15 @@ class VoteWebAdapter(
2739 private val createVotingTopicUseCase : CreateVotingTopicUseCase ,
2840 private val deleteVotingTopicUseCase : DeleteVotingTopicUseCase ,
2941 private val queryAllVotingTopicUseCase : QueryAllVotingTopicUseCase ,
30- private val updateVotingTopicUseCase : UpdateVotingTopicUseCase
42+ private val updateVotingTopicUseCase : UpdateVotingTopicUseCase ,
43+ private val createVoteUseCase : CreateVoteUseCase ,
44+ private val createVotingOptionUseCase : CreateVotingOptionUseCase ,
45+ private val queryVotesUseCase : QueryVotesUseCase ,
46+ private val queryVotingOptionsUseCase : QueryVotingOptionsUseCase ,
47+ private val deleteVoteUseCase : DeleteVoteUseCase ,
48+ private val removeVotingOptionsUseCase : QueryVotingOptionsUseCase
3149) {
50+
3251 @PostMapping
3352 fun saveVotingTopic (@RequestBody @Valid request : CreateVotingTopicWebRequest ) {
3453 createVotingTopicUseCase.execute(
@@ -68,4 +87,48 @@ class VoteWebAdapter(
6887 fun getAllVotingTopic (): VotingTopicsResponse {
6988 return queryAllVotingTopicUseCase.execute()
7089 }
90+
91+ @ResponseStatus(HttpStatus .CREATED )
92+ @PostMapping(" /option" )
93+ fun createVotingOption (@RequestBody request : CreateVotingOptionWebRequest ) {
94+ createVotingOptionUseCase.execute(
95+ CreateVotingOptionRequest .of(
96+ request.votingTopicId,
97+ request.optionName
98+ )
99+ )
100+ }
101+
102+ @ResponseStatus(HttpStatus .OK )
103+ @GetMapping(" /option/{voting-topic-id}" )
104+ fun getVotingOptions (@PathVariable(" voting-topic-id" ) votingTopicId : UUID ): VotingOptionsResponse {
105+ return queryVotingOptionsUseCase.execute(votingTopicId)
106+ }
107+
108+ @ResponseStatus(HttpStatus .NO_CONTENT )
109+ @DeleteMapping(" /option/{voting-option-id}" )
110+ fun removeVotingOption (@PathVariable(" voting-option-id" ) votingOptionId : UUID ) {
111+ removeVotingOptionsUseCase.execute(votingOptionId)
112+ }
113+
114+ @ResponseStatus(HttpStatus .CREATED )
115+ @PostMapping(" /student/{voting-topic-id}" )
116+ fun createVote (
117+ @PathVariable(" voting-topic-id" ) votingTopicId : UUID ,
118+ @RequestParam(name = " selected-id" ) selectedId : UUID
119+ ) {
120+ createVoteUseCase.execute(selectedId, votingTopicId)
121+ }
122+
123+ @ResponseStatus(HttpStatus .NO_CONTENT )
124+ @DeleteMapping(" /student/{voting-topic-id}" )
125+ fun removeVote (@PathVariable(" voting-topic-id" ) votingTopicId : UUID ) {
126+ deleteVoteUseCase.execute(votingTopicId)
127+ }
128+
129+ @ResponseStatus(HttpStatus .OK )
130+ @GetMapping(" /result/{voting-topic-id}" )
131+ fun getVoteResults (@PathVariable(" voting-topic-id" ) votingTopicId : UUID ): VotesResponse {
132+ return queryVotesUseCase.execute(votingTopicId)
133+ }
71134}
0 commit comments