From dcee69be129d6d3e9b8fb96606c4ce69879676ff Mon Sep 17 00:00:00 2001 From: balysv Date: Wed, 14 Jul 2021 22:18:16 +0200 Subject: [PATCH] Update documentation url --- README.md | 2 +- .../application/MeetingApplicationService.kt | 13 +++++---- .../com/sama/meeting/domain/Exceptions.kt | 28 ++++++++----------- .../java/com/sama/meeting/domain/Meeting.kt | 2 +- .../com/sama/meeting/domain/MeetingIntent.kt | 8 ++---- .../sama/api/meeting/MeetingControllerTest.kt | 21 ++------------ .../MeetingApplicationServiceTest.kt | 4 +-- 7 files changed, 28 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index b4b71a14..a6349c98 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ Backend service for the Sama app. -Api documentation can be found [here](https://app.meetsama.com.smtest.it/swagger-ui/index.html?configUrl=/api/docs/swagger-config#/) \ No newline at end of file +Api documentation can be found [here](https://app.meetsama.com.smtest.it/api/swagger-ui/index.html?configUrl=/api/docs/swagger-config#/) \ No newline at end of file diff --git a/app/src/main/java/com/sama/meeting/application/MeetingApplicationService.kt b/app/src/main/java/com/sama/meeting/application/MeetingApplicationService.kt index f3b3baed..6a6d01f5 100644 --- a/app/src/main/java/com/sama/meeting/application/MeetingApplicationService.kt +++ b/app/src/main/java/com/sama/meeting/application/MeetingApplicationService.kt @@ -3,6 +3,7 @@ package com.sama.meeting.application import com.sama.calendar.application.BlockEventConsumer import com.sama.calendar.domain.BlockRepository import com.sama.common.ApplicationService +import com.sama.common.NotFoundException import com.sama.common.findByIdOrThrow import com.sama.common.toMinutes import com.sama.meeting.domain.* @@ -122,9 +123,9 @@ class MeetingApplicationService( val proposedMeeting = when (val meeting = meetingFrom(intentEntity, meetingEntity).getOrThrow()) { is ProposedMeeting -> meeting - is ConfirmedMeeting -> throw MeetingAlreadyConfirmedException(meeting.meetingId) - is ExpiredMeeting -> throw MeetingProposalExpiredException(meeting.meetingId) - else -> throw InvalidMeetingStatusException(meeting.meetingId, meeting.status) + is ConfirmedMeeting -> throw MeetingAlreadyConfirmedException(meetingCode) + is ExpiredMeeting -> throw NotFoundException(ProposedMeeting::class, meetingCode) + else -> throw InvalidMeetingStatusException(meetingCode, meeting.status) } val (start, end) = proposedMeeting.proposedSlotsRange() @@ -146,9 +147,9 @@ class MeetingApplicationService( val proposedMeeting = when (val meeting = meetingFrom(intentEntity, meetingEntity).getOrThrow()) { is ProposedMeeting -> meeting - is ConfirmedMeeting -> throw MeetingAlreadyConfirmedException(meeting.meetingId) - is ExpiredMeeting -> throw MeetingProposalExpiredException(meeting.meetingId) - else -> throw InvalidMeetingStatusException(meeting.meetingId, meeting.status) + is ConfirmedMeeting -> throw MeetingAlreadyConfirmedException(meetingCode) + is ExpiredMeeting -> throw NotFoundException(ProposedMeeting::class, meetingCode) + else -> throw InvalidMeetingStatusException(meetingCode, meeting.status) } val meetingRecipient = command.recipientEmail.let { MeetingRecipient.fromEmail(it) } diff --git a/app/src/main/java/com/sama/meeting/domain/Exceptions.kt b/app/src/main/java/com/sama/meeting/domain/Exceptions.kt index 6a350da4..83378343 100644 --- a/app/src/main/java/com/sama/meeting/domain/Exceptions.kt +++ b/app/src/main/java/com/sama/meeting/domain/Exceptions.kt @@ -2,27 +2,23 @@ package com.sama.meeting.domain import com.sama.common.DomainEntityStatusException import com.sama.common.DomainInvalidActionException -import com.sama.common.DomainIntegrityException import com.sama.common.DomainValidationException import java.time.Duration -class InvalidDurationException(meetingIntentId: MeetingIntentId, duration: Duration) : - DomainValidationException("MeetingIntent#$meetingIntentId: Unsupported duration '${duration.toMinutes()} min'") +class InvalidDurationException(duration: Duration) : + DomainValidationException("Unsupported duration '${duration.toMinutes()} min'") -class InvalidMeetingSlotException(meetingIntentId: MeetingIntentId, slot: MeetingSlot) : - DomainValidationException("MeetingIntent#$meetingIntentId: Invalid slot '${slot.startDateTime} - ${slot.endDateTime}'") +class InvalidMeetingSlotException(slot: MeetingSlot) : + DomainValidationException("Invalid slot '${slot.startDateTime} - ${slot.endDateTime}'") -class InvalidMeetingProposalException(meetingIntentId: MeetingIntentId, message: String) : - DomainValidationException("MeetingIntent#$meetingIntentId cannot be proposed: $message") +class InvalidMeetingProposalException(message: String) : + DomainValidationException("Meeting cannot be proposed: $message") -class MeetingAlreadyConfirmedException(meetingId: MeetingId) : - DomainEntityStatusException("already_confirmed", "Meeting#$meetingId already confirmed") +class MeetingAlreadyConfirmedException(meetingCode: MeetingCode) : + DomainEntityStatusException("already_confirmed", "Meeting#$meetingCode already confirmed") -class MeetingProposalExpiredException(meetingId: MeetingId) : - DomainEntityStatusException("proposal_expired", "Meeting#$meetingId has expired") +class InvalidMeetingStatusException(meetingCode: MeetingCode, status: MeetingStatus): + DomainEntityStatusException("invalid_status", "Meeting#$meetingCode: Invalid status: $status") -class InvalidMeetingStatusException(meetingId: MeetingId, status: MeetingStatus): - DomainEntityStatusException("invalid_status", "Meeting#$meetingId: Invalid status: $status") - -class MeetingSlotUnavailableException(meetingId: MeetingId, slot: MeetingSlot): - DomainInvalidActionException("slot_unavailable", "Meeting#$meetingId: Slot unavailable: '${slot.startDateTime} - ${slot.endDateTime}'") +class MeetingSlotUnavailableException(meetingCode: MeetingCode, slot: MeetingSlot): + DomainInvalidActionException("slot_unavailable", "Meeting#$meetingCode: Slot unavailable: '${slot.startDateTime} - ${slot.endDateTime}'") diff --git a/app/src/main/java/com/sama/meeting/domain/Meeting.kt b/app/src/main/java/com/sama/meeting/domain/Meeting.kt index 262ab8f8..b76ceecb 100644 --- a/app/src/main/java/com/sama/meeting/domain/Meeting.kt +++ b/app/src/main/java/com/sama/meeting/domain/Meeting.kt @@ -99,7 +99,7 @@ data class ProposedMeeting( fun confirm(slot: MeetingSlot, recipient: MeetingRecipient): Result { return kotlin.runCatching { val confirmedSlot = expandedSlots().find { it == slot } - ?: throw MeetingSlotUnavailableException(meetingId, slot) + ?: throw MeetingSlotUnavailableException(meetingCode, slot) ConfirmedMeeting(meetingId, initiatorId, duration, recipient, confirmedSlot) } diff --git a/app/src/main/java/com/sama/meeting/domain/MeetingIntent.kt b/app/src/main/java/com/sama/meeting/domain/MeetingIntent.kt index a9ddf0fe..f7c4a647 100644 --- a/app/src/main/java/com/sama/meeting/domain/MeetingIntent.kt +++ b/app/src/main/java/com/sama/meeting/domain/MeetingIntent.kt @@ -34,7 +34,7 @@ data class MeetingIntent( init { if (duration < minimumDuration) { - throw InvalidDurationException(meetingIntentId, duration) + throw InvalidDurationException(duration) } validateSlots(suggestedSlots) } @@ -45,7 +45,7 @@ data class MeetingIntent( proposedSlots: List ): Result { if (proposedSlots.isEmpty()) { - return Result.failure(InvalidMeetingProposalException(meetingIntentId, "No slots proposed")) + return Result.failure(InvalidMeetingProposalException("No slots proposed")) } kotlin.runCatching { validateSlots(proposedSlots) } @@ -64,11 +64,9 @@ data class MeetingIntent( } private fun validateSlots(slots: List) { - // TODO: validate duplicates - slots.firstOrNull { it.duration() < duration } ?.run { - throw InvalidMeetingSlotException(meetingIntentId, this) + throw InvalidMeetingSlotException(this) } } } \ No newline at end of file diff --git a/app/src/test/java/com/sama/api/meeting/MeetingControllerTest.kt b/app/src/test/java/com/sama/api/meeting/MeetingControllerTest.kt index 33695159..8be32599 100644 --- a/app/src/test/java/com/sama/api/meeting/MeetingControllerTest.kt +++ b/app/src/test/java/com/sama/api/meeting/MeetingControllerTest.kt @@ -5,7 +5,6 @@ import com.sama.api.config.WebMvcConfiguration import com.sama.meeting.application.* import com.sama.meeting.domain.InvalidMeetingStatusException import com.sama.meeting.domain.MeetingAlreadyConfirmedException -import com.sama.meeting.domain.MeetingProposalExpiredException import com.sama.meeting.domain.MeetingStatus import org.junit.jupiter.api.DynamicTest.dynamicTest import org.junit.jupiter.api.Test @@ -309,7 +308,7 @@ class MeetingControllerTest( @Test fun `meeting already confirmed`() { whenever(meetingApplicationService.loadMeetingProposalFromCode(any())) - .thenThrow(MeetingAlreadyConfirmedException(1L)) + .thenThrow(MeetingAlreadyConfirmedException("VGsUTGno")) val expectedResponse = """ { @@ -322,26 +321,10 @@ class MeetingControllerTest( .andExpect(MockMvcResultMatchers.content().json(expectedResponse)) } - @Test - fun `meeting expired`() { - whenever(meetingApplicationService.loadMeetingProposalFromCode(any())) - .thenThrow(MeetingProposalExpiredException(1L)) - - val expectedResponse = """ - { - "status": 410, - "reason": "proposal_expired" - } - """ - mockMvc.perform(get("/api/meeting/by-code/VGsUTGno")) - .andExpect(status().isGone) - .andExpect(MockMvcResultMatchers.content().json(expectedResponse)) - } - @Test fun `meeting status invalid`() { whenever(meetingApplicationService.loadMeetingProposalFromCode(any())) - .thenThrow(InvalidMeetingStatusException(1L, MeetingStatus.REJECTED)) + .thenThrow(InvalidMeetingStatusException("VGsUTGno", MeetingStatus.REJECTED)) val expectedResponse = """ { diff --git a/app/src/test/java/com/sama/meeting/application/MeetingApplicationServiceTest.kt b/app/src/test/java/com/sama/meeting/application/MeetingApplicationServiceTest.kt index 2798dde3..09acffee 100644 --- a/app/src/test/java/com/sama/meeting/application/MeetingApplicationServiceTest.kt +++ b/app/src/test/java/com/sama/meeting/application/MeetingApplicationServiceTest.kt @@ -265,7 +265,7 @@ class MeetingApplicationServiceTest( return listOf( MeetingStatus.CONFIRMED to MeetingAlreadyConfirmedException::class, - MeetingStatus.EXPIRED to MeetingProposalExpiredException::class, + MeetingStatus.EXPIRED to NotFoundException::class, MeetingStatus.REJECTED to InvalidMeetingStatusException::class ).map { (status, expected) -> DynamicTest.dynamicTest("Meeting status $status throws $expected") { @@ -427,7 +427,7 @@ class MeetingApplicationServiceTest( return listOf( MeetingStatus.CONFIRMED to MeetingAlreadyConfirmedException::class, - MeetingStatus.EXPIRED to MeetingProposalExpiredException::class, + MeetingStatus.EXPIRED to NotFoundException::class, MeetingStatus.REJECTED to InvalidMeetingStatusException::class ).map { (status, expected) -> DynamicTest.dynamicTest("Meeting status $status throws $expected") {