1
1
package ru.ifmo.se.dating.people.api.mapping
2
2
3
- import ru.ifmo.se.dating.people.model.Faculty
4
- import ru.ifmo.se.dating.people.model.Location
5
- import ru.ifmo.se.dating.people.model.Person
6
- import ru.ifmo.se.dating.people.model.PersonVariant
3
+ import ru.ifmo.se.dating.people.model.*
7
4
import ru.ifmo.se.dating.people.model.generated.*
8
5
import ru.ifmo.se.dating.security.auth.User
9
6
@@ -13,6 +10,7 @@ fun PersonPatchMessage.toModel(id: Int) = Person.Draft(
13
10
lastName = lastName?.let { Person .Name (it) },
14
11
height = height,
15
12
birthday = birthday,
13
+ interests = emptySet(),
16
14
facultyId = facultyId?.let { Faculty .Id (it.toInt()) },
17
15
locationId = locationId?.let { Location .Id (it.toInt()) },
18
16
)
@@ -31,7 +29,7 @@ fun Person.toMessage() = PersonMessage(
31
29
birthday = birthday,
32
30
facultyId = facultyId.number.toLong(),
33
31
locationId = locationId.number.toLong(),
34
- interests = emptySet (),
32
+ interests = interests.map { it.toMessage() }.toSet (),
35
33
zodiac = ZodiacSignMessage .leo,
36
34
pictures = pictureIds.map { PictureMessage (id = it.number.toLong()) }.toSet()
37
35
)
@@ -45,6 +43,18 @@ fun Person.Draft.toMessage() = PersonDraftMessage(
45
43
birthday = birthday,
46
44
facultyId = facultyId?.number?.toLong(),
47
45
locationId = locationId?.number?.toLong(),
48
- interests = emptySet (),
46
+ interests = interests.map { it.toMessage() }.toSet (),
49
47
pictures = pictureIds.map { PictureMessage (id = it.number.toLong()) }.toSet()
50
48
)
49
+
50
+ fun InterestMessage.toModel (): Person .Interest =
51
+ Person .Interest (
52
+ topicId = Topic .Id (topicId.toInt()),
53
+ degree = level.value.toInt(),
54
+ )
55
+
56
+ fun Person.Interest.toMessage (): InterestMessage =
57
+ InterestMessage (
58
+ topicId = topicId.number.toLong(),
59
+ level = InterestLevelMessage .forValue(degree.toString()),
60
+ )
0 commit comments