-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Innfører QueryRunner i EgenAnsattApiDao
Co-authored-by: Christian Skovborg Gule<[email protected]>
- Loading branch information
1 parent
df11d0e
commit 375ea10
Showing
1 changed file
with
10 additions
and
21 deletions.
There are no files selected for viewing
31 changes: 10 additions & 21 deletions
31
spesialist-api/src/main/kotlin/no/nav/helse/spesialist/api/egenAnsatt/EgenAnsattApiDao.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,30 +1,19 @@ | ||
package no.nav.helse.spesialist.api.egenAnsatt | ||
|
||
import kotliquery.queryOf | ||
import kotliquery.sessionOf | ||
import org.intellij.lang.annotations.Language | ||
import no.nav.helse.HelseDao.Companion.asSQL | ||
import no.nav.helse.db.MedDataSource | ||
import no.nav.helse.db.QueryRunner | ||
import javax.sql.DataSource | ||
|
||
class EgenAnsattApiDao(private val dataSource: DataSource) { | ||
fun erEgenAnsatt(fødselsnummer: String): Boolean? { | ||
@Language("PostgreSQL") | ||
val query = """ | ||
class EgenAnsattApiDao(private val dataSource: DataSource) : QueryRunner by MedDataSource(dataSource) { | ||
fun erEgenAnsatt(fødselsnummer: String): Boolean? = | ||
asSQL( | ||
""" | ||
SELECT er_egen_ansatt | ||
FROM egen_ansatt ea | ||
INNER JOIN person p on p.id = ea.person_ref | ||
WHERE p.fodselsnummer = :fodselsnummer | ||
""" | ||
return sessionOf(dataSource).use { session -> | ||
session.run( | ||
queryOf( | ||
query, | ||
mapOf( | ||
"fodselsnummer" to fødselsnummer.toLong(), | ||
), | ||
) | ||
.map { it.boolean("er_egen_ansatt") } | ||
.asSingle, | ||
) | ||
} | ||
} | ||
""".trimIndent(), | ||
"fodselsnummer" to fødselsnummer.toLong(), | ||
).singleOrNull { it.boolean("er_egen_ansatt") } | ||
} |