Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (39 sloc) 1.54 KB
package io.graphqlfederation.satelliteservice.service
import io.graphqlfederation.satelliteservice.model.Satellite
import io.graphqlfederation.satelliteservice.repository.SatelliteRepository
import java.time.LocalDate
import javax.inject.Singleton
class SatelliteService(
private val repository: SatelliteRepository,
private val securityService: SecurityService
) {
fun create(
name: String,
lifeExists: Satellite.LifeExists,
planetId: Long,
firstSpacecraftLandingDate: LocalDate? = null
) =
name = name,
lifeExists = lifeExists,
firstSpacecraftLandingDate = firstSpacecraftLandingDate,
planetId = planetId
fun getAll(): Iterable<Satellite> = repository.findAll()
fun getById(id: Long): Satellite = repository.findById(id).orElse(null)
fun getByName(name: String): Satellite? = repository.findByName(name)
fun getByPlanetId(planetId: Long): List<Satellite> = repository.findByPlanetId(planetId)
fun getLifeExists(id: Long): Satellite.LifeExists {
val userIsAuthenticated = securityService.isAuthenticated
if (userIsAuthenticated) {
return repository.findById(id)
.orElseThrow { RuntimeException("Can't find satellite by id=$id") }
} else {
throw RuntimeException("`lifeExists` property can only be accessed by authenticated users")
You can’t perform that action at this time.