This file contains hidden or 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
| context(Raise<UpdatePetDetailsFailure>) | |
| suspend fun updatePetDetails( | |
| petId: PetId, | |
| petOwnerId: PetOwnerId, | |
| petUpdate: PetUpdate | |
| ): Pet { | |
| val pet = petStore.getPet(petId) ?: raise(UpdatePetDetailsFailure.PetNotFound) | |
| val owner = petOwnerStore.getPetOwner(petOwnerId) ?: raise(UpdatePetDetailsFailure.OwnerNotFound) | |
| val microchip = microchipStore.getMicrochip(pet.microchipId) ?: raise(UpdatePetDetailsFailure.MicrochipNotFound) |
This file contains hidden or 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
| suspend fun updatePetDetails( | |
| petId: PetId, | |
| petOwnerId: PetOwnerId, | |
| petUpdate: PetUpdate | |
| ): Either<UpdatePetDetailsFailure, Pet> = either { | |
| val pet = petStore.getPet(petId) ?: raise(UpdatePetDetailsFailure.PetNotFound) | |
| val owner = petOwnerStore.getPetOwner(petOwnerId) ?: raise(UpdatePetDetailsFailure.OwnerNotFound) | |
| val microchip = microchipStore.getMicrochip(pet.microchipId) ?: raise(UpdatePetDetailsFailure.MicrochipNotFound) | |
| ensure(microchip.petId == pet.id) { UpdatePetDetailsFailure.InvalidMicrochip } |
This file contains hidden or 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
| suspend fun updatePetDetails( | |
| petId: PetId, | |
| petOwnerId: PetOwnerId, | |
| petUpdate: PetUpdate | |
| ): UpdatePetDetailsResult { | |
| val pet = petStore.getPet(petId) ?: return UpdatePetDetailsResult.PetNotFound | |
| val owner = petOwnerStore.getPetOwner(petOwnerId) ?: return UpdatePetDetailsResult.OwnerNotFound | |
| val microchip = microchipStore.getMicrochip(pet.microchipId) ?: return UpdatePetDetailsResult.MicrochipNotFound | |
| if (microchip.petId != pet.id) { |
This file contains hidden or 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
| suspend fun updatePetDetails( | |
| petId: PetId, | |
| petOwnerId: PetOwnerId, | |
| petUpdate: PetUpdate | |
| ): Pet = try { | |
| val pet = petStore.getPet(petId) | |
| val owner = petOwnerStore.getPetOwner(petOwnerId) | |
| val microchip = microchipStore.getMicrochip(pet.microchipId) | |
| if (microchip.petId != pet.id) { |
This file contains hidden or 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
| suspend fun updatePetDetails( | |
| petId: PetId, | |
| petOwnerId: PetOwnerId, | |
| petUpdate: PetUpdate | |
| ): Either<UpdatePetDetailsFailure, Pet> = | |
| petStore.getPet(petId) | |
| .toEither { UpdatePetDetailsFailure.PetNotFound } | |
| .flatMap { pet -> | |
| petOwnerStore.getPetOwner(petOwnerId) | |
| .toEither { UpdatePetDetailsFailure.OwnerNotFound } |
This file contains hidden or 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
| suspend fun updatePetDetails( | |
| petId: PetId, | |
| petOwnerId: PetOwnerId, | |
| petUpdate: PetUpdate | |
| ): UpdatePetDetailsResult { | |
| val pet = petStore.getPet(petId) | |
| return if (pet == null) { | |
| UpdatePetDetailsResult.PetNotFound | |
| } else { | |
| val owner = petOwnerStore.getPetOwner(petOwnerId) |
This file contains hidden or 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
| context(Raise<UpdatePetDetailsFailure>) | |
| suspend fun updatePetDetails( | |
| petId: PetId, | |
| petOwnerId: PetOwnerId, | |
| petUpdate: PetUpdate | |
| ): Pet { | |
| val pet = petStore.getPet(petId) ?: raise(UpdatePetDetailsFailure.PetNotFound) | |
| val owner = petOwnerStore.getPetOwner(petOwnerId) ?: raise(UpdatePetDetailsFailure.OwnerNotFound) | |
| val microchip = microchipStore.getMicrochip(pet.microchipId) ?: raise(UpdatePetDetailsFailure.MicrochipNotFound) |