Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#71 - 투표할 친구들을 순서대로가 아닌 랜덤으로 결정한다. #72

Merged
merged 6 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,14 @@ class CustomUrlFilter(
"/api/v1/users/backgrounds",
"/api/v1/users/characters",
"/api/v1/users/search",
"/api/v1/votes/options",
"/api/v1/votes",
"/api/v1/votes/tops",
"/api/v1/votes/sent",
"/api/v1/votes/received",
"/api/v1/votes/sent/options",
"/api/v1/votes/received/options",
"/api/v1/reports/users",
"/api/v1/messages",
"/api/v1/messages/send",
"/api/v1/messages/status/me",
"/api/v1/messages/check-profanity",
"/api/v1/messages/**",
"/api/v1/votes/**",
"/api/v1/reports/**",
"/api/v1/notifications/**",
)

override fun doFilterInternal(
Expand Down
1 change: 0 additions & 1 deletion app/src/main/kotlin/com/wespot/vote/VoteController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class VoteController(

@GetMapping("/received/options/{optionId}")
fun getReceivedVote(
userId: Long,
@PathVariable optionId: Long,
@RequestParam date: LocalDate
): ResponseEntity<ReceivedVoteResponse> {
Expand Down
19 changes: 10 additions & 9 deletions app/src/test/kotlin/com/wespot/vote/domain/VoteTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.throwable.shouldHaveMessage
import java.time.LocalDate
import java.time.LocalDateTime
Expand Down Expand Up @@ -139,7 +140,8 @@ class VoteTest() : BehaviorSpec({

given("현재 사용자가 아직 투표하지 인원 중에") {
val ballots = listOf(
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 1L, 2L)
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 1L, 2L),
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 2L, 3L)
)
`when`("5명 이하의 학생들을") {
val users = createUserByCount(5)
Expand All @@ -148,9 +150,9 @@ class VoteTest() : BehaviorSpec({
val voteUsers = vote.findUsersForVote(users, me)
then("정상적으로 반환한다.") {
voteUsers.size shouldBe 3
voteUsers[0].id shouldBe 3
voteUsers[1].id shouldBe 4
voteUsers[2].id shouldBe 5
voteUsers.find { it.id == 3L } shouldNotBe null
voteUsers.find { it.id == 4L } shouldNotBe null
voteUsers.find { it.id == 5L } shouldNotBe null
}
}

Expand All @@ -159,13 +161,12 @@ class VoteTest() : BehaviorSpec({
val vote = VoteFixture.createWithVoteNumberAndBallots(0, ballots)
val me = users[0]
val voteUsers = vote.findUsersForVote(users, me)
val userCounts= voteUsers.map { it.id }.toSet()
val doesNotContainsMe = voteUsers.stream().allMatch { it.id != users[0].id }
then("정상적으로 반환한다.") {
voteUsers.size shouldBe 5
voteUsers[0].id shouldBe 3
voteUsers[1].id shouldBe 4
voteUsers[2].id shouldBe 5
voteUsers[3].id shouldBe 6
voteUsers[4].id shouldBe 7
userCounts.size shouldBe 5
doesNotContainsMe shouldBe true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.wespot.notification.Notification
data class NotificationResponse(
val id: Long,
val type: String,
val date: String,
val targetId: Long,
val content: String,
val isNew: Boolean,
Expand All @@ -18,6 +19,7 @@ data class NotificationResponse(
return NotificationResponse(
id = notification.id,
type = notification.type.name,
date = notification.date.toString(),
targetId = notification.targetId,
content = notification.title,
isNew = !notification.isRead,
Expand Down
1 change: 1 addition & 0 deletions domain/src/main/kotlin/com/wespot/vote/Vote.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ data class Vote(
return classmates.stream()
.filter { !alreadyVotedByUser.contains(it.id) && isNotMe(it, user) }
.toList()
.shuffled()
.take(NUMBER_OF_VOTE_USERS)
}

Expand Down
Loading