Skip to content

Commit

Permalink
feat: 투표 관련 기본로직 및 도메인 작성 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
key-del-jeeinho authored Aug 22, 2023
1 parent a71cac7 commit 6f42eb4
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/com/mz2mo/domain/emoji/Emoji.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mz2mo.domain.emoji

data class Emoji(
val id: String,
val emoji: String,
val name: String,
val usable: Boolean
)
7 changes: 7 additions & 0 deletions src/main/kotlin/com/mz2mo/domain/vote/CreateVote.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mz2mo.domain.vote

data class CreateVote(
val emojiId: String,
val userId: String,
val musicId: String
)
5 changes: 5 additions & 0 deletions src/main/kotlin/com/mz2mo/domain/vote/QueryVoteUseCase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.mz2mo.domain.vote

fun interface QueryVoteUseCase {
fun getVotes(musicId: String): List<Vote>
}
8 changes: 8 additions & 0 deletions src/main/kotlin/com/mz2mo/domain/vote/Vote.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mz2mo.domain.vote

data class Vote(
val id: String,
val emojiId: String,
val userId: String,
val musicId: String
)
25 changes: 25 additions & 0 deletions src/main/kotlin/com/mz2mo/domain/vote/VoteController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mz2mo.domain.vote

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1/votes")
class VoteController(
private val voteService: VoteService
) {
@PostMapping
fun vote(createVote: CreateVote): Vote {
return voteService.vote(createVote)
}

@GetMapping("/by-music/{musicId}")
fun getVotes(
@PathVariable("musicId") musicId: String
): List<Vote> {
return voteService.getVotes(musicId)
}
}
23 changes: 23 additions & 0 deletions src/main/kotlin/com/mz2mo/domain/vote/VoteService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mz2mo.domain.vote

import org.springframework.stereotype.Service
import java.util.UUID

@Service
class VoteService : QueryVoteUseCase, VoteUseCase {
private val votes = mutableListOf<Vote>()

override fun getVotes(musicId: String): List<Vote> =
votes.filter { it.musicId == musicId }

override fun vote(createVote: CreateVote): Vote {
val vote = Vote(
id = UUID.randomUUID().toString(),
emojiId = createVote.emojiId,
userId = createVote.userId,
musicId = createVote.musicId
)
votes.add(vote)
return vote
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/com/mz2mo/domain/vote/VoteUseCase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.mz2mo.domain.vote

fun interface VoteUseCase {
fun vote(createVote: CreateVote): Vote
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 6f42eb4

Please sign in to comment.