Skip to content

Commit

Permalink
Added x-username as requirement in header
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexYoungmanMoJ committed Feb 3, 2025
1 parent 86da55e commit b823fd5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uk.gov.justice.digital.hmpps.learnerrecordsapi.openapi

import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.enums.ParameterIn
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.ExampleObject
import io.swagger.v3.oas.annotations.media.Schema
Expand All @@ -15,6 +17,7 @@ import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
@Operation(
summary = "Get learning events by learner ULN",
description = "Get personal learning records and events by a ULN",
parameters = [Parameter(name = "X-Username", `in` = ParameterIn.HEADER, required = true)],
requestBody = RequestBody(
description = "ULN and demographic details of the learner",
required = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uk.gov.justice.digital.hmpps.learnerrecordsapi.openapi

import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.enums.ParameterIn
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.ExampleObject
import io.swagger.v3.oas.annotations.media.Schema
Expand All @@ -10,20 +12,13 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnersRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LearnersResponse
import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.text.Charsets.UTF_8

fun readResourceFile(fileName: String): String {
val resourcePath = Paths.get("src/test/resources", fileName)
return Files.readString(resourcePath, UTF_8)
}

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@Operation(
summary = "Find learners by demographic information",
description = "Find possible or exact matches for learners by demographic information",
parameters = [Parameter(name = "X-Username", `in` = ParameterIn.HEADER, required = true)],
requestBody = RequestBody(
description = "Demographic details of the learner",
required = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import jakarta.validation.Valid
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest
Expand All @@ -23,6 +24,7 @@ class LearnerEventsResource(
@LearnerEventsApi
suspend fun findByUln(
@RequestBody @Valid learnerEventsRequest: LearnerEventsRequest,
@RequestHeader("X-Username", required = true) username: String,
): String {
log.inboundRequest(requestModelObject = learnerEventsRequest)
return gson.toJson(learnerEventsService.getLearningEvents(learnerEventsRequest))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import jakarta.validation.Valid
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnersRequest
Expand All @@ -23,6 +24,7 @@ class LearnersResource(
@FindByDemographicApi
suspend fun findByDemographic(
@RequestBody @Valid findLearnerByDemographicsRequest: LearnersRequest,
@RequestHeader("X-Username", required = true) username: String,
): String {
log.inboundRequest(requestModelObject = findLearnerByDemographicsRequest)
return gson.toJson(learnersService.getLearners(findLearnerByDemographicsRequest))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class LearnerEventsResourceIntTest : IntegrationTestBase() {
val actualResponse = webTestClient.post()
.uri("/learner-events")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.header("X-Username", "TestUser")
.bodyValue(getLearningEventsRequest)
.accept(MediaType.parseMediaType("application/json"))
.exchange()
Expand Down Expand Up @@ -81,6 +82,7 @@ class LearnerEventsResourceIntTest : IntegrationTestBase() {
val actualResponse = webTestClient.post()
.uri("/learner-events")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.header("X-Username", "TestUser")
.bodyValue(getLearningEventsRequest)
.accept(MediaType.parseMediaType("application/json"))
.exchange()
Expand Down Expand Up @@ -132,6 +134,7 @@ class LearnerEventsResourceIntTest : IntegrationTestBase() {
val actualResponse = webTestClient.post()
.uri("/learner-events")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.header("X-Username", "TestUser")
.bodyValue(getLearningEventsRequest)
.accept(MediaType.parseMediaType("application/json"))
.exchange()
Expand Down Expand Up @@ -160,6 +163,7 @@ class LearnerEventsResourceIntTest : IntegrationTestBase() {
val actualResponse = webTestClient.post()
.uri("/learner-events")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.header("X-Username", "TestUser")
.bodyValue(getLearningEventsRequest)
.accept(MediaType.parseMediaType("application/json"))
.exchange()
Expand Down Expand Up @@ -188,6 +192,7 @@ class LearnerEventsResourceIntTest : IntegrationTestBase() {
val actualResponse = webTestClient.post()
.uri("/learner-events")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.header("X-Username", "TestUser")
.bodyValue(getLearningEventsRequest)
.accept(MediaType.parseMediaType("application/json"))
.exchange()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LearnersResourceIntTest : IntegrationTestBase() {
val executedRequest = webTestClient.post()
.uri("/learners")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.header("X-Username", "TestUser")
.bodyValue(request)
.accept(MediaType.parseMediaType("application/json"))
.exchange()
Expand Down

0 comments on commit b823fd5

Please sign in to comment.