source: bus-n-go-pavel-216049/bus-n-go-backend/src/main/kotlin/mk/ukim/finki/busngobackend/mapper/ClassToDtoMapper.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: 2.8 KB
Line 
1package mk.ukim.finki.busngobackend.mapper
2
3import mk.ukim.finki.busngobackend.api.responses.*
4import mk.ukim.finki.busngobackend.domain.entities.*
5import org.springframework.stereotype.Service
6
7@Service
8class ClassToDtoMapper {
9 fun toUserResponse(user: Korisnik): UserResponse =
10 UserResponse(
11 id = user.id,
12 email = user.email,
13 phoneNumber = user.telefon,
14 address = user.adresa,
15 name = user.ime,
16 )
17
18 fun toTicketResponse(it: Bilet) =
19 TicketResponse(
20 id = it.id,
21 tip = it.tip,
22 datumKupuvanje = it.datumKupuvanje.toLocalDateTime(),
23 status = it.status.name,
24 datumAktivacija = it.datumAktivacija?.toLocalDateTime(),
25 )
26
27 fun toRouteInstanceResponse(it: InstancaNaLinija) =
28 RouteInstanceResponse(
29 line = it.linija,
30 bus = it.avtobus,
31 start = it.startDate.toLocalDateTime(),
32 driver = toUserResponse(it.vozac.vraboten.korisnik),
33 direction = it.pravec,
34 end = it.endDate?.toLocalDateTime(),
35 id = it.id,
36 )
37
38 fun toCommuteResponse(it: Vozenje) =
39 CommuteResponse(
40 status = it.status.name,
41 endDate = it.endDate?.toLocalDateTime(),
42 startDate = it.startDate.toLocalDateTime(),
43 commuter = this.toUserResponse(it.patnik.korisnik),
44 stationStart = it.postojkaNaLinijaStart,
45 ticket = this.toTicketResponse(it.bilet),
46 id = it.id,
47 )
48
49 fun toControlResponse(kontrola: Kontrola) =
50 ControlResponse(
51 id = kontrola.id,
52 instancaNaLinija = this.toRouteInstanceResponse(kontrola.instancaNaLinija),
53 kondukter = this.toUserResponse(kontrola.kondukter.vraboten.korisnik),
54 dateCreated = kontrola.dateCreated,
55 )
56
57 fun toFineResponse(
58 kazna: Kazna,
59 kzr: KaznaZaRegistriran?,
60 kzn: KaznaZaNeregistriran?,
61 ) = FineResponse(
62 dokument = kazna.dokument,
63 kontrola = this.toControlResponse(kazna.kontrola),
64 plateno = kazna.plateno,
65 iznos = kazna.iznos,
66 id = kazna.id,
67 kondukter = this.toUserResponse(kazna.kondukter.vraboten.korisnik),
68 datePayed = kazna.datePayed,
69 dateCreated = kazna.dateCreated,
70 adresa = kzn?.adresa,
71 patnik = kzr?.patnik?.let { this.toUserResponse(it.korisnik) },
72 ime = kzn?.ime,
73 telefon = kzn?.telefon,
74 )
75
76 fun toAdminUsersResponse(user: Korisnik): AdminUsersResponse =
77 AdminUsersResponse(
78 id = user.id,
79 email = user.email,
80 phoneNumber = user.telefon,
81 address = user.adresa,
82 name = user.ime,
83 roles = user.roles!!.map { it.role!!.name },
84 )
85}
Note: See TracBrowser for help on using the repository browser.