Created
June 13, 2023 22:11
-
-
Save tdcolvin/372782614b7bce60155fd33ba4b40826 to your computer and use it in GitHub Desktop.
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
class AddPlanetUseCase @Inject constructor(private val planetsRepository: PlanetsRepository) { | |
suspend operator fun invoke(planet: Planet) { | |
if (planet.name.isEmpty()) { | |
throw Exception("Please specify a planet name") | |
} | |
if (planet.distanceLy < 0) { | |
throw Exception("Please enter a positive distance") | |
} | |
if (planet.discovered.after(Date())) { | |
throw Exception("Please enter a discovery date in the past") | |
} | |
planetsRepository.addPlanet(planet) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment