source: bus-n-go-pavel-216049/bus-n-go-backend/src/main/kotlin/mk/ukim/finki/busngobackend/service/StationService.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.7 KB
Line 
1package mk.ukim.finki.busngobackend.service
2
3import mk.ukim.finki.busngobackend.domain.entities.Postojka
4import mk.ukim.finki.busngobackend.domain.entities.PostojkaNaLinija
5import mk.ukim.finki.busngobackend.repository.LinijaRepository
6import mk.ukim.finki.busngobackend.repository.PostojkaNaLinijaRepository
7import mk.ukim.finki.busngobackend.repository.PostojkaRepository
8import mk.ukim.finki.busngobackend.repository.PravecRepository
9import mk.ukim.finki.busngobackend.service.exceptions.NotFoundException
10import org.springframework.data.repository.findByIdOrNull
11import org.springframework.stereotype.Service
12
13@Service
14class StationService(
15 private val postojkaRepository: PostojkaRepository,
16 private val postojkaNaLinijaRepository: PostojkaNaLinijaRepository,
17 private val linijaRepository: LinijaRepository,
18 private val pravecRepository: PravecRepository,
19) {
20 fun findStationsByLineId(lineId: Int): List<PostojkaNaLinija> {
21 val linija = linijaRepository.findByIdOrNull(lineId) ?: throw NotFoundException("Linija not found")
22 return this.postojkaNaLinijaRepository.findByLinija(linija)
23 }
24
25 fun findStationsByLineIdAndDirectionId(
26 lineId: Int,
27 directionId: Long?,
28 ): List<PostojkaNaLinija> {
29 if (directionId == null) {
30 return this.findStationsByLineId(lineId)
31 }
32
33 val linija = linijaRepository.findByIdOrNull(lineId) ?: throw NotFoundException("Linija not found")
34 val pravec = pravecRepository.findByIdOrNull(directionId) ?: throw NotFoundException("Pravec not found")
35
36 return postojkaNaLinijaRepository.findByLinijaAndPravec(linija, pravec)
37 }
38
39 fun getAll(): List<Postojka> = this.postojkaRepository.findAll()
40}
Note: See TracBrowser for help on using the repository browser.