source: bus-n-go-pavel-216049/bus-n-go-backend/src/main/kotlin/mk/ukim/finki/busngobackend/service/RouteInstanceOnStationService.kt

Last change on this file was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 1.6 KB
Line 
1package mk.ukim.finki.busngobackend.service
2
3import mk.ukim.finki.busngobackend.domain.entities.InstancaNaLinijaPostojkaNaLinija
4import mk.ukim.finki.busngobackend.repository.InstancaNaLinijaPostojkaNaLinijaRepository
5import mk.ukim.finki.busngobackend.repository.InstancaNaLinijaRepository
6import mk.ukim.finki.busngobackend.repository.PostojkaNaLinijaRepository
7import mk.ukim.finki.busngobackend.service.exceptions.NotFoundException
8import org.springframework.data.repository.findByIdOrNull
9import org.springframework.stereotype.Service
10import java.sql.Timestamp
11
12@Service
13class RouteInstanceOnStationService(
14 private val instancaNaLinijaPostojkaNaLinijaRepository: InstancaNaLinijaPostojkaNaLinijaRepository,
15 private val instancaNaLinijaRepository: InstancaNaLinijaRepository,
16 private val postojkaNaLinijaRepository: PostojkaNaLinijaRepository,
17) {
18 fun create(
19 routeInstanceId: Long,
20 lineStationId: Long,
21 timestamp: Timestamp,
22 ): InstancaNaLinijaPostojkaNaLinija {
23 val routeInstance =
24 instancaNaLinijaRepository.findByIdOrNull(routeInstanceId) ?: throw NotFoundException("Route instance not found")
25 val lineStation = postojkaNaLinijaRepository.findByIdOrNull(lineStationId) ?: throw NotFoundException("Line station not found")
26 return instancaNaLinijaPostojkaNaLinijaRepository.save(
27 InstancaNaLinijaPostojkaNaLinija(
28 instancaNaLinija = routeInstance,
29 postojkaNaLinija = lineStation,
30 timestamp = timestamp,
31 id = 0L,
32 ),
33 )
34 }
35}
Note: See TracBrowser for help on using the repository browser.