-
Notifications
You must be signed in to change notification settings - Fork 1
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 #64 from mash-up-kr/feature/vote
feat: 투표하기 API
- Loading branch information
Showing
30 changed files
with
271 additions
and
126 deletions.
There are no files selected for viewing
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
3 changes: 0 additions & 3 deletions
3
piikii-application/src/main/kotlin/com/piikii/application/consts/Consts.kt
This file was deleted.
Oops, something went wrong.
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
9 changes: 0 additions & 9 deletions
9
piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVote.kt
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVoteService.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.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,9 @@ | ||
package com.piikii.application.domain.vote | ||
|
||
import java.util.UUID | ||
|
||
data class Vote( | ||
val userId: UUID, | ||
val roomPlaceId: Long, | ||
val result: VoteResult, | ||
) |
6 changes: 6 additions & 0 deletions
6
piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteResult.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,6 @@ | ||
package com.piikii.application.domain.vote | ||
|
||
enum class VoteResult { | ||
O, | ||
X, | ||
} |
33 changes: 33 additions & 0 deletions
33
piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.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,33 @@ | ||
package com.piikii.application.domain.vote | ||
|
||
import com.piikii.application.port.input.vote.VoteUseCase | ||
import com.piikii.application.port.output.persistence.RoomQueryPort | ||
import com.piikii.application.port.output.persistence.VoteCommandPort | ||
import com.piikii.common.exception.ExceptionCode | ||
import com.piikii.common.exception.PiikiiException | ||
import org.springframework.stereotype.Service | ||
import java.util.UUID | ||
|
||
@Service | ||
class VoteService( | ||
private val voteCommandPort: VoteCommandPort, | ||
private val roomQueryPort: RoomQueryPort, | ||
) : VoteUseCase { | ||
override fun vote( | ||
roomId: UUID, | ||
votes: List<Vote>, | ||
) { | ||
if (roomQueryPort.retrieve(roomId).isUnavailableToVote()) { | ||
throw PiikiiException( | ||
exceptionCode = ExceptionCode.ACCESS_DENIED, | ||
detailMessage = VOTE_ACCESS_DENIED, | ||
) | ||
} | ||
// TODO: votes.map { it.roomPlaceId } 존재여부 검증 필요 -> 도현이 작업 완료되면 붙일 예정 | ||
voteCommandPort.vote(votes) | ||
} | ||
|
||
companion object { | ||
const val VOTE_ACCESS_DENIED = "투표가 시작되지 않았거나, 마감되었습니다." | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.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.piikii.application.port.input.vote | ||
|
||
import com.piikii.application.domain.vote.Vote | ||
import java.util.UUID | ||
|
||
interface VoteUseCase { | ||
fun vote( | ||
roomId: UUID, | ||
votes: List<Vote>, | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
...ii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.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,9 @@ | ||
package com.piikii.application.port.output.persistence | ||
|
||
import com.piikii.application.domain.vote.Vote | ||
|
||
interface VoteQueryPort | ||
|
||
interface VoteCommandPort { | ||
fun vote(votes: List<Vote>) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
piikii-input-http/src/main/kotlin/com/piikii/input/http/config/WebMvcConfig.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
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
4 changes: 2 additions & 2 deletions
4
...n/com/piikii/input/http/TestController.kt → ...i/input/http/controller/TestController.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
25 changes: 25 additions & 0 deletions
25
piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.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,25 @@ | ||
package com.piikii.input.http.controller | ||
|
||
import com.piikii.application.port.input.vote.VoteUseCase | ||
import com.piikii.input.http.docs.VoteApiDocs | ||
import com.piikii.input.http.dto.ResponseForm | ||
import com.piikii.input.http.dto.request.VoteRequest | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.ResponseStatus | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/room/votes") | ||
class VoteApi(private val voteUseCase: VoteUseCase) : VoteApiDocs { | ||
@ResponseStatus(HttpStatus.CREATED) | ||
@PostMapping | ||
override fun vote( | ||
@RequestBody voteRequest: VoteRequest, | ||
): ResponseForm<Unit> { | ||
voteUseCase.vote(voteRequest.roomId, voteRequest.toDomains()) | ||
return ResponseForm.EMPTY_RESPONSE | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.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,24 @@ | ||
package com.piikii.input.http.docs | ||
|
||
import com.piikii.input.http.dto.ResponseForm | ||
import com.piikii.input.http.dto.request.VoteRequest | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.media.Content | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import io.swagger.v3.oas.annotations.parameters.RequestBody | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
|
||
@Tag(name = "VoteApi", description = "Vote (투표) API") | ||
interface VoteApiDocs { | ||
@Operation(summary = "투표 API", description = "투표를 진행합니다") | ||
@ApiResponses(value = [ApiResponse(responseCode = "201", description = "Vote succeed")]) | ||
fun vote( | ||
@RequestBody( | ||
description = "투표 생성 Request body", | ||
required = true, | ||
content = [Content(schema = Schema(implementation = VoteRequest::class))], | ||
) voteRequest: VoteRequest, | ||
): ResponseForm<Unit> | ||
} |
8 changes: 6 additions & 2 deletions
8
...piikii/input/http/generic/ResponseForm.kt → ...com/piikii/input/http/dto/ResponseForm.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.piikii.input.http.generic | ||
package com.piikii.input.http.dto | ||
|
||
class ResponseForm<T>( | ||
val data: T? = null, | ||
val message: String? = null, | ||
val timestamp: Long = System.currentTimeMillis(), | ||
) | ||
) { | ||
companion object { | ||
val EMPTY_RESPONSE = ResponseForm<Unit>() | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../piikii/input/http/message/RoomMessage.kt → .../com/piikii/input/http/dto/RoomMessage.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
20 changes: 20 additions & 0 deletions
20
piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/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,20 @@ | ||
package com.piikii.input.http.dto.request | ||
|
||
import com.piikii.application.domain.vote.Vote | ||
import com.piikii.application.domain.vote.VoteResult | ||
import java.util.UUID | ||
|
||
data class VoteRequest( | ||
val userId: UUID, | ||
val roomId: UUID, | ||
val votes: List<PlaceVoteResult>, | ||
) { | ||
fun toDomains(): List<Vote> { | ||
return this.votes.map { Vote(userId = userId, roomPlaceId = it.roomPlaceId, result = it.voteResult) } | ||
} | ||
} | ||
|
||
data class PlaceVoteResult( | ||
val roomPlaceId: Long, | ||
val voteResult: VoteResult, | ||
) |
2 changes: 1 addition & 1 deletion
2
...input/http/exception/ExceptionResponse.kt → ...ut/http/dto/response/ExceptionResponse.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
2 changes: 1 addition & 1 deletion
2
...nput/http/filter/ServletWrappingFilter.kt → .../http/web/filter/ServletWrappingFilter.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
2 changes: 1 addition & 1 deletion
2
...ut/http/interceptor/LoggingInterceptor.kt → ...ttp/web/interceptor/LoggingInterceptor.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
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
20 changes: 20 additions & 0 deletions
20
...esql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.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,20 @@ | ||
package com.piikii.output.persistence.postgresql.adapter.vote | ||
|
||
import com.piikii.application.domain.vote.Vote | ||
import com.piikii.application.port.output.persistence.VoteCommandPort | ||
import com.piikii.application.port.output.persistence.VoteQueryPort | ||
import com.piikii.output.persistence.postgresql.persistence.entity.VoteEntity | ||
import com.piikii.output.persistence.postgresql.persistence.repository.VoteRepository | ||
import org.springframework.stereotype.Repository | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Repository | ||
@Transactional(readOnly = true) | ||
class VoteAdapter( | ||
private val voteRepository: VoteRepository, | ||
) : VoteCommandPort, VoteQueryPort { | ||
@Transactional | ||
override fun vote(votes: List<Vote>) { | ||
voteRepository.saveAll(votes.map(VoteEntity::from)) | ||
} | ||
} |
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
Oops, something went wrong.