Skip to content

Commit bebd02b

Browse files
giacomoaccursiandrea-acampora
authored andcommitted
chore: add method to obtain the Room from the dto
1 parent f724087 commit bebd02b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/main/kotlin/application/presenter/serialization/RoomSerializer.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ import application.presenter.api.report.measurements.ValueWithUnit
1212
import application.presenter.api.report.room.RoomApiDto
1313
import application.presenter.api.report.room.RoomApiDtoType
1414
import application.presenter.api.report.room.RoomEnvironmentalDataApiDto
15+
import entity.surgeryreport.measurements.Humidity
16+
import entity.surgeryreport.measurements.Luminosity
17+
import entity.surgeryreport.measurements.Percentage
18+
import entity.surgeryreport.measurements.Presence
19+
import entity.surgeryreport.measurements.Temperature
1520
import entity.surgeryreport.room.Room
1621
import entity.surgeryreport.room.RoomEnvironmentalData
22+
import entity.surgeryreport.room.RoomID
1723
import entity.surgeryreport.room.RoomType
1824

1925
/**
@@ -28,6 +34,14 @@ object RoomSerializer {
2834
type = this.type.toApiDtoType(),
2935
)
3036

37+
/**
38+
* Extension method to obtain the room from the dto.
39+
*/
40+
fun RoomApiDto.toRoom(): Room = Room(
41+
RoomID(this.id),
42+
this.type.toRoomType(),
43+
)
44+
3145
/**
3246
* Extension method to obtain the api dto type of a room.
3347
*/
@@ -36,6 +50,14 @@ object RoomSerializer {
3650
RoomType.PRE_OPERATING_ROOM -> RoomApiDtoType.PRE_OPERATING_ROOM
3751
}
3852

53+
/**
54+
* Extension method to obtain the room type from the api dto.
55+
*/
56+
fun RoomApiDtoType.toRoomType() = when (this) {
57+
RoomApiDtoType.OPERATING_ROOM -> RoomType.OPERATING_ROOM
58+
RoomApiDtoType.PRE_OPERATING_ROOM -> RoomType.PRE_OPERATING_ROOM
59+
}
60+
3961
/**
4062
* Extension method to obtain the api dto of room environmental data.
4163
*/
@@ -45,4 +67,14 @@ object RoomSerializer {
4567
luminosity = this.luminosity?.let { ValueWithUnit(it.value, it.unit.toString()) },
4668
presence = this.presence?.presenceDetected,
4769
)
70+
71+
/**
72+
* Extension method to obtain room environmental data from dto.
73+
*/
74+
fun RoomEnvironmentalDataApiDto.toRoomEnvironmentalData() = RoomEnvironmentalData(
75+
temperature = this.temperature?.let { Temperature(it.value) },
76+
humidity = this.humidity?.let { Percentage(it) }?.let { Humidity(it) },
77+
luminosity = this.luminosity?.let { Luminosity(it.value) },
78+
presence = this.presence?.let { Presence(it) },
79+
)
4880
}

0 commit comments

Comments
 (0)