@@ -7,6 +7,7 @@ import org.springframework.core.io.Resource
7
7
import org.springframework.http.ResponseEntity
8
8
import org.springframework.stereotype.Controller
9
9
import ru.ifmo.se.dating.exception.AuthorizationException
10
+ import ru.ifmo.se.dating.exception.InvalidValueException
10
11
import ru.ifmo.se.dating.exception.orThrowNotFound
11
12
import ru.ifmo.se.dating.pagging.Page
12
13
import ru.ifmo.se.dating.people.api.generated.PeopleApiDelegate
@@ -15,10 +16,7 @@ import ru.ifmo.se.dating.people.api.mapping.toModel
15
16
import ru.ifmo.se.dating.people.logic.InterestService
16
17
import ru.ifmo.se.dating.people.logic.PersonService
17
18
import ru.ifmo.se.dating.people.logic.PictureService
18
- import ru.ifmo.se.dating.people.model.Faculty
19
- import ru.ifmo.se.dating.people.model.Person
20
- import ru.ifmo.se.dating.people.model.Picture
21
- import ru.ifmo.se.dating.people.model.Topic
19
+ import ru.ifmo.se.dating.people.model.*
22
20
import ru.ifmo.se.dating.people.model.generated.*
23
21
import ru.ifmo.se.dating.security.auth.User
24
22
import ru.ifmo.se.dating.spring.security.auth.SpringSecurityContext
@@ -32,6 +30,7 @@ class HttpPeopleApi(
32
30
private val interestService : InterestService ,
33
31
private val pictureService : PictureService ,
34
32
) : PeopleApiDelegate {
33
+ @Suppress(" LongMethod" , " CyclomaticComplexMethod" , " MagicNumber" )
35
34
override fun peopleGet (
36
35
offset : Long ,
37
36
limit : Long ,
@@ -44,39 +43,55 @@ class HttpPeopleApi(
44
43
heightMax : Int? ,
45
44
birthdayMin : LocalDate ? ,
46
45
birthdayMax : LocalDate ? ,
47
- zodiac : List < ZodiacSignMessage > ? ,
48
- faculty : List < Long > ? ,
46
+ zodiac : ZodiacSignMessage ? ,
47
+ facultyId : Long? ,
49
48
latitude : Double? ,
50
49
longitude : Double? ,
51
50
radius : Int? ,
52
51
updatedMin : OffsetDateTime ? ,
53
52
updatedMax : OffsetDateTime ? ,
54
53
sortBy : List <PersonSortingKeyMessage >? ,
55
54
): ResponseEntity <Flow <PersonMessage >> {
56
- if (listOfNotNull(
57
- picturesCountMin,
58
- picturesCountMax,
59
- topicId,
60
- zodiac,
61
- latitude,
62
- longitude,
63
- radius,
64
- updatedMin,
65
- updatedMax,
66
- sortBy
67
- ).isNotEmpty()
68
- ) {
55
+ if (! sortBy.isNullOrEmpty()) {
69
56
TODO (" Unsupported GET /people query parameter was provided" )
70
57
}
71
58
59
+ val area = when (listOfNotNull(latitude, longitude, radius).size) {
60
+ 0 -> {
61
+ null
62
+ }
63
+
64
+ 3 -> {
65
+ Area (
66
+ center = Coordinates (
67
+ latitude = latitude!! ,
68
+ longitude = longitude!!
69
+ ),
70
+ radius = radius!! .toDouble(),
71
+ )
72
+ }
73
+
74
+ else -> {
75
+ buildString {
76
+ append(" Expected a complete area, but got " )
77
+ append(" (latitude: $latitude , longitude: $longitude , radius: $radius )" )
78
+ }.let { throw InvalidValueException (it) }
79
+ }
80
+ }
81
+
72
82
return personService.getFiltered(
73
83
Page (offset = offset.toInt(), limit = limit.toInt()),
74
84
PersonService .Filter (
75
- firstName = firstName?.let { Regex (it) } ? : Regex ( " .* " ) ,
76
- lastName = lastName?.let { Regex (it) } ? : Regex ( " .* " ) ,
85
+ firstName = firstName?.let { Regex (it) },
86
+ lastName = lastName?.let { Regex (it) },
77
87
height = (heightMin ? : Int .MIN_VALUE ).. (heightMax ? : Int .MAX_VALUE ),
78
88
birthday = (birthdayMin ? : LocalDate .MIN ).. (birthdayMax ? : LocalDate .MAX ),
79
- faculty = (faculty ? : listOf ()).map { Faculty .Id (it.toInt()) }.toSet(),
89
+ facultyId = facultyId?.let { Faculty .Id (it.toInt()) },
90
+ updated = (updatedMin ? : OffsetDateTime .MIN ).. (updatedMax ? : OffsetDateTime .MAX ),
91
+ area = area,
92
+ picturesCount = (picturesCountMin ? : 0 ).. (picturesCountMax ? : Int .MAX_VALUE ),
93
+ zodiac = zodiac?.toModel(),
94
+ topicIds = topicId?.map { Topic .Id (it.toInt()) }?.toSet() ? : emptySet(),
80
95
),
81
96
).map { it.toMessage() }.let { ResponseEntity .ok(it) }
82
97
}
0 commit comments