File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
src/main/kotlin/application/presenter/api/deserializer Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments