-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from navikt/tiltaksvariant-navneendring
tc-33 tiltaksvariant -> tiltakstype
- Loading branch information
Showing
50 changed files
with
410 additions
and
407 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
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
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
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
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
80 changes: 80 additions & 0 deletions
80
backend/src/main/kotlin/no/nav/mulighetsrommet/api/services/TiltakstypeService.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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package no.nav.mulighetsrommet.api.services | ||
|
||
import no.nav.mulighetsrommet.api.database.DatabaseFactory | ||
import no.nav.mulighetsrommet.api.domain.Tiltakstype | ||
import no.nav.mulighetsrommet.api.domain.TiltakstypeTable | ||
import org.jetbrains.exposed.sql.ResultRow | ||
import org.jetbrains.exposed.sql.SortOrder | ||
import org.jetbrains.exposed.sql.and | ||
import org.jetbrains.exposed.sql.andWhere | ||
import org.jetbrains.exposed.sql.insertAndGetId | ||
import org.jetbrains.exposed.sql.select | ||
import org.jetbrains.exposed.sql.update | ||
|
||
class TiltakstypeService(private val db: DatabaseFactory) { | ||
|
||
suspend fun getTiltakstyper(innsatsgruppe: Int?): List<Tiltakstype> { | ||
val rows = db.dbQuery { | ||
val query = TiltakstypeTable | ||
.select { TiltakstypeTable.archived eq false } | ||
.orderBy(TiltakstypeTable.id to SortOrder.ASC) | ||
|
||
innsatsgruppe?.let { query.andWhere { TiltakstypeTable.innsatsgruppeId eq it } } | ||
|
||
query.toList() | ||
} | ||
return rows.map { row -> | ||
toTiltakstype(row) | ||
} | ||
} | ||
|
||
suspend fun createTiltakstype(tiltakstype: Tiltakstype): Tiltakstype { | ||
val id = db.dbQuery { | ||
TiltakstypeTable.insertAndGetId { | ||
it[innsatsgruppeId] = tiltakstype.innsatsgruppe | ||
it[tittel] = tiltakstype.tittel | ||
it[beskrivelse] = tiltakstype.beskrivelse | ||
it[ingress] = tiltakstype.ingress | ||
it[archived] = false | ||
} | ||
} | ||
return getTiltakstypeById(id.value)!! | ||
} | ||
|
||
suspend fun updateTiltakstype(id: Int, tiltakstype: Tiltakstype): Tiltakstype? { | ||
db.dbQuery { | ||
TiltakstypeTable.update({ TiltakstypeTable.id eq id and (TiltakstypeTable.archived eq false) }) { | ||
it[innsatsgruppeId] = tiltakstype.innsatsgruppe | ||
it[tittel] = tiltakstype.tittel | ||
it[beskrivelse] = tiltakstype.beskrivelse | ||
it[ingress] = tiltakstype.ingress | ||
} | ||
} | ||
return getTiltakstypeById(id) | ||
} | ||
|
||
suspend fun archivedTiltakstype(tiltakstype: Tiltakstype) = db.dbQuery { | ||
TiltakstypeTable.update({ TiltakstypeTable.id eq tiltakstype.id }) { | ||
it[archived] = true | ||
} | ||
} | ||
|
||
suspend fun getTiltakstypeById(id: Int): Tiltakstype? { | ||
val tiltakstypeRow = db.dbQuery { | ||
TiltakstypeTable | ||
.select { TiltakstypeTable.id eq id and (TiltakstypeTable.archived eq false) } | ||
.firstOrNull() | ||
} | ||
|
||
return tiltakstypeRow?.let { toTiltakstype(it) } | ||
} | ||
|
||
private fun toTiltakstype(row: ResultRow): Tiltakstype = | ||
Tiltakstype( | ||
id = row[TiltakstypeTable.id].value, | ||
tittel = row[TiltakstypeTable.tittel], | ||
beskrivelse = row[TiltakstypeTable.beskrivelse], | ||
ingress = row[TiltakstypeTable.ingress], | ||
innsatsgruppe = row[TiltakstypeTable.innsatsgruppeId] | ||
) | ||
} |
80 changes: 0 additions & 80 deletions
80
backend/src/main/kotlin/no/nav/mulighetsrommet/api/services/TiltaksvariantService.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.