-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IS-2871: Add possibility to search on name
- Loading branch information
1 parent
ba3e09d
commit 32a51d9
Showing
9 changed files
with
220 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 20 additions & 9 deletions
29
src/main/kotlin/no/nav/syfo/personstatus/api/v2/model/SearchQueryDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
package no.nav.syfo.personstatus.api.v2.model | ||
|
||
import no.nav.syfo.personstatus.domain.Initials | ||
import no.nav.syfo.personstatus.domain.SearchQuery | ||
import no.nav.syfo.personstatus.domain.Name | ||
import no.nav.syfo.personstatus.domain.Search | ||
import java.time.LocalDate | ||
|
||
data class SearchQueryDTO( | ||
val initials: String?, | ||
val birthdate: LocalDate, | ||
val initials: String? = null, | ||
val name: String? = null, | ||
val birthdate: LocalDate?, | ||
) { | ||
fun toSearchQuery(): SearchQuery = SearchQuery( | ||
birthdate = birthdate, | ||
initials = Initials( | ||
initials | ||
) | ||
) | ||
fun toSearchQuery(): Search = | ||
if (name != null && birthdate != null) { | ||
Search.ByNameAndDate( | ||
name = Name(name), | ||
birthdate = birthdate | ||
) | ||
} else if (initials != null && birthdate != null) { | ||
Search.ByInitialsAndDate(initials = Initials(initials), birthdate = birthdate) | ||
} else if (name != null) { | ||
Search.ByName(name = Name(name)) | ||
} else if (birthdate != null) { | ||
Search.ByDate(birthdate = birthdate) | ||
} else { | ||
throw IllegalArgumentException("SearchQueryDTO values did not conform to allowed search rules") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/kotlin/no/nav/syfo/personstatus/application/PersonoversiktSearchService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package no.nav.syfo.personstatus.domain | ||
|
||
import java.time.LocalDate | ||
|
||
sealed class Search { | ||
data class ByName(val name: Name) : Search() | ||
data class ByNameAndDate(val name: Name, val birthdate: LocalDate) : Search() | ||
data class ByDate(val birthdate: LocalDate) : Search() | ||
data class ByInitialsAndDate(val initials: Initials, val birthdate: LocalDate) : Search() | ||
} | ||
|
||
@JvmInline | ||
value class Initials(val value: String) { | ||
init { | ||
require(value.isEmpty() || value.length > 1) { "Initials must be null or more than one characters long" } | ||
} | ||
} | ||
|
||
@JvmInline | ||
value class Name(val value: String) { | ||
init { | ||
require(value.split(" ").size > 1) { "Name must consist of two continuous strings or more" } | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
src/main/kotlin/no/nav/syfo/personstatus/domain/SearchQuery.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.