Skip to content

Commit

Permalink
Forenklinger i API
Browse files Browse the repository at this point in the history
Co-authored-by: Henrik Jackson <[email protected]>
  • Loading branch information
matiasvinjevoll and henrikjackson committed Sep 24, 2024
1 parent ed42c5d commit 7e9d0b9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
14 changes: 5 additions & 9 deletions app/src/main/kotlin/no/nav/aap/brev/App.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.aap.brev

import com.papsign.ktor.openapigen.route.apiRouting
import com.papsign.ktor.openapigen.route.response.respond
import com.papsign.ktor.openapigen.route.response.respondWithStatus
import com.papsign.ktor.openapigen.route.route
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
Expand All @@ -17,9 +17,7 @@ import io.ktor.server.routing.*
import io.micrometer.prometheusmetrics.PrometheusConfig
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import no.nav.aap.brev.api.BestillBrevRequest
import no.nav.aap.brev.api.BestillBrevResponse
import no.nav.aap.brev.api.ErrorRespons
import no.nav.aap.brev.domene.BrevbestillingReferanse
import no.nav.aap.brev.innhold.BrevinnholdService
import no.nav.aap.brev.innhold.SanityBrevinnholdGateway
import no.nav.aap.komponenter.commonKtorModule
Expand All @@ -29,7 +27,6 @@ import no.nav.aap.komponenter.httpklient.httpclient.tokenprovider.azurecc.AzureC
import no.nav.aap.tilgang.authorizedPostWithApprovedList
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.*

private val SECURE_LOGGER: Logger = LoggerFactory.getLogger("secureLog")
const val AZURE = "azure"
Expand Down Expand Up @@ -81,15 +78,14 @@ internal fun Application.server(
apiRouting {
route("/api") {
route("/bestill") {
authorizedPostWithApprovedList<Unit, BestillBrevResponse, BestillBrevRequest>(behandlingsflytAzp) { _, request ->
authorizedPostWithApprovedList<Unit, Unit, BestillBrevRequest>(behandlingsflytAzp) { _, request ->
brevinnholdService.behandleBrevbestilling(
request.behandlingReferanse,
request.brevtype,
request.language,
request.sprak,
)
respond(
response = BestillBrevResponse(BrevbestillingReferanse(UUID.randomUUID())),
statusCode = HttpStatusCode.Created
respondWithStatus(
HttpStatusCode.Created
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import no.nav.aap.brev.domene.Språk
data class BestillBrevRequest(
val behandlingReferanse: BehandlingReferanse,
val brevtype: Brevtype,
val language: Språk,
val sprak: Språk,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SanityBrevinnholdGateway : BrevinnholdGateway {
brevtype: Brevtype,
språk: Språk
): Brevinnhold {
val uri = baseUri.resolve("/api/brev?brevtype=$brevtype&language=$språk")
val uri = baseUri.resolve("/api/brev?brevtype=$brevtype&sprak=$språk")
val httpRequest = GetRequest(
additionalHeaders = listOf(
Header("Accept", "application/json")
Expand Down
23 changes: 10 additions & 13 deletions app/src/test/kotlin/no/nav/aap/brev/AppTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import no.nav.aap.brev.api.BestillBrevRequest
import no.nav.aap.brev.api.BestillBrevResponse
import no.nav.aap.brev.domene.BehandlingReferanse
import no.nav.aap.brev.domene.Brevtype
import no.nav.aap.brev.domene.Språk
Expand All @@ -14,17 +13,17 @@ import no.nav.aap.brev.no.nav.aap.brev.test.Fakes
import no.nav.aap.komponenter.httpklient.httpclient.ClientConfig
import no.nav.aap.komponenter.httpklient.httpclient.RestClient
import no.nav.aap.komponenter.httpklient.httpclient.error.DefaultResponseHandler
import no.nav.aap.komponenter.httpklient.httpclient.post
import no.nav.aap.komponenter.httpklient.httpclient.request.PostRequest
import no.nav.aap.komponenter.httpklient.httpclient.tokenprovider.azurecc.ClientCredentialsTokenProvider
import no.nav.aap.komponenter.httpklient.json.DefaultJsonMapper
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy
import java.net.URI
import java.time.Duration
import java.time.temporal.ChronoUnit
import kotlin.test.assertNotNull

class AppTest {

Expand Down Expand Up @@ -64,16 +63,14 @@ class AppTest {

@Test
fun `bestiller brev`() {
val res: BestillBrevResponse? = restClient.post(
uri = URI.create("http://localhost:8080/").resolve("/api/bestill"),
request = PostRequest(
body = BestillBrevRequest(BehandlingReferanse("123"), Brevtype.INNVILGELSE, Språk.NB)
),
mapper = { body, _ ->
DefaultJsonMapper.fromJson(body)
}
)
assertNotNull(res)
assertDoesNotThrow {
restClient.post<_, Unit>(
uri = URI.create("http://localhost:8080/").resolve("/api/bestill"),
request = PostRequest(
body = BestillBrevRequest(BehandlingReferanse("123"), Brevtype.INNVILGELSE, Språk.NB)
)
)
}
}
}

Expand Down

0 comments on commit 7e9d0b9

Please sign in to comment.