Skip to content

Commit bd529ac

Browse files
chore: add room api dto deserialization
1 parent 384eb46 commit bd529ac

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2023. Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
package application.presenter.api.deserializer
10+
11+
import application.presenter.api.model.RoomApiDto
12+
import application.presenter.api.model.RoomApiDtoType
13+
import entity.zone.Room
14+
import entity.zone.RoomID
15+
import entity.zone.RoomType
16+
import entity.zone.ZoneID
17+
18+
/**
19+
* Deserializer for data that comes from API.
20+
*/
21+
object ApiDeserializer {
22+
/**
23+
* Extension method to convert Room API DTO to [entity.zone.Room] class.
24+
*/
25+
fun RoomApiDto.toRoom() = Room(
26+
id = RoomID(this.id),
27+
type = this.type.toRoomType(),
28+
zoneId = ZoneID(this.zoneId),
29+
name = this.name,
30+
)
31+
32+
private fun RoomApiDtoType.toRoomType() = when (this) {
33+
RoomApiDtoType.OPERATING_ROOM -> RoomType.OPERATING_ROOM
34+
RoomApiDtoType.PRE_OPERATING_ROOM -> RoomType.PRE_OPERATING_ROOM
35+
}
36+
}

0 commit comments

Comments
 (0)