Skip to content

Commit

Permalink
Hotfix version (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasanchez authored May 30, 2023
2 parents f241d50 + f885e6b commit 913e226
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotEmpty
import org.springframework.data.annotation.Id
import org.springframework.data.annotation.Version
import org.springframework.data.mongodb.core.mapping.Document
import java.time.LocalDateTime

Expand All @@ -28,6 +29,7 @@ data class Schedule(
@Id
val id: String? = null,

@Version
@field:Min(value = 0, message = "Version must be greater or equal to 0")
val version: Int = 0,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class MeetingScheduler : ScheduleService {
class MeetingScheduler(
@Autowired
private lateinit var schedules : ScheduleRepositoryMongo
val schedules: ScheduleRepositoryMongo
) : ScheduleService {


override fun scheduleMeeting(command: ScheduleMeeting): MeetingScheduled {

Expand All @@ -42,66 +44,58 @@ class MeetingScheduler : ScheduleService {
}

override fun joinAMeeting(id: String, username: String): MeetingScheduled {
if(schedules.findById(id).isPresent) {
val schedule = schedules.findById(id).get()

val joined = schedule.join(username = username)
val joined = schedules
.findById(id)
.orElseThrow { ScheduleNotFoundException(id) }
.join(username = username)

return modelToEvent(schedules.save(joined))
}
throw ScheduleNotFoundException(id)
return modelToEvent(schedules.save(joined))
}

override fun toggleVoting(id: String, command: ToggleVoting): MeetingScheduled {
if(schedules.findById(id).isPresent) {
val schedule = schedules.findById(id).get()

try {
val toggled = schedule.toggleVoting(username = command.username,
enabledVotes = command.voting)
val schedule = schedules
.findById(id)
.orElseThrow { ScheduleNotFoundException(id) }

return modelToEvent(schedules.save(toggled))
} catch (e: IllegalScheduleException) {
try {
val toggled = schedule
.toggleVoting(username = command.username, enabledVotes = command.voting)

throw ScheduleAuthorizationException(e)
}
return modelToEvent(schedules.save(toggled))
} catch (e: IllegalScheduleException) {
throw ScheduleAuthorizationException(e)
}
throw ScheduleNotFoundException(id)
}

override fun voteForAnOption(id: String, command: VoteForOption): MeetingScheduled {
if(schedules.findById(id).isPresent) {
val schedule = schedules.findById(id).get()

val option = MeetingOption(
date = command.option.date,
hour = command.option.hour,
minute = command.option.minute,
)
override fun voteForAnOption(id: String, command: VoteForOption): MeetingScheduled {
val schedule = schedules
.findById(id)
.orElseThrow { ScheduleNotFoundException(id) }

val option = MeetingOption(
date = command.option.date,
hour = command.option.hour,
minute = command.option.minute,
)

try {
try {
val voted: Schedule = schedule.vote(option = option, username = command.username)
return modelToEvent(schedules.save(voted))
} catch (e: IllegalVoteException) {
throw ScheduleAuthorizationException(e)
}

val voted: Schedule = schedule.vote(option = option, username = command.username)
return modelToEvent(schedules.save(voted))
}

} catch (e: IllegalVoteException) {
override fun scheduleById(id: String): MeetingScheduled =
modelToEvent(schedules.findById(id).orElseThrow { ScheduleNotFoundException(id) })

throw ScheduleAuthorizationException(e)
}
}
throw ScheduleNotFoundException(id)
}

override fun scheduleById(id: String): MeetingScheduled {
if(schedules.findById(id).isPresent) {
return modelToEvent(schedules.findById(id).get())
}
throw ScheduleNotFoundException(id)
}
override fun findAll(): Collection<MeetingScheduled> = schedules.findAll().map(::modelToEvent)

override fun findAll(): Collection<MeetingScheduled> {
return schedules.findAll().map(::modelToEvent)
}

/**
* Converts a Schedule to a MeetingScheduled
Expand Down
Loading

0 comments on commit 913e226

Please sign in to comment.