Skip to content

Commit

Permalink
#10 Adjusted binding
Browse files Browse the repository at this point in the history
  • Loading branch information
loreV committed Jan 30, 2024
1 parent 1638d12 commit ba4551b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class ErtEventMicroserviceAdapter @Autowired constructor(
lateinit var endpointUrl: String

override fun getByIstat1(
istat: String
istat: String,
skip: Int,
limit: Int,
): ResponseEntity<EventResponse>? {
return try {
restTemplateBuilder.build()
.getForEntity(
endpointUrl.plus(
"/${istat}"
"/${istat}?skip=${skip}&limit=${limit}"
),
org.openapitools.model.EventResponse::class.java
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.sc.controller.microservice

import io.swagger.v3.oas.annotations.Operation
import org.hikit.common.ControllerConstants
import org.openapitools.model.EventResponse
import org.sc.adapter.microservice.ErtEventMicroserviceAdapter
import org.sc.data.validator.GeneralValidator
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
@ConditionalOnExpression("\${microservice.ert.events.enabled:false}")
Expand All @@ -25,13 +23,15 @@ class ErtEventsController @Autowired constructor(
@Operation(summary = "Retrieve events by istat code")
@GetMapping("/{istat}", produces = ["application/json"])
operator fun get(
@PathVariable(required = true) istat: String
@PathVariable(required = true) istat: String,
@RequestParam(required = false, defaultValue = ControllerConstants.MIN_DOCS_ON_READ) skip: Int,
@RequestParam(required = false, defaultValue = ControllerConstants.MAX_DOCS_ON_READ) limit: Int,
): EventResponse? {
val validationErrors = generalValidator.validateIstat(istat)
if(validationErrors.isNotEmpty()) {
composeErrorResponse(validationErrors)
}
return ertEventMicroserviceAdapter.getByIstat1(istat)!!.body
return ertEventMicroserviceAdapter.getByIstat1(istat, skip, limit)!!.body
}

private fun composeErrorResponse(validationErrors: Set<String>) {
Expand Down
85 changes: 21 additions & 64 deletions backend/src/main/resources/microservice/ert-swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@
"schema": {
"type": "string"
}
},
{
"name": "skip",
"in": "query",
"required": false,
"schema": {
"type": "integer",
"format": "int32",
"default": 0
}
},
{
"name": "limit",
"in": "query",
"required": false,
"schema": {
"type": "integer",
"format": "int32",
"default": 150
}
}
],
"responses": {
Expand Down Expand Up @@ -538,43 +558,6 @@
}
}
},
"CityRef": {
"type": "object",
"properties": {
"istat": {
"type": "string"
},
"city": {
"type": "string"
},
"province": {
"type": "string"
},
"province_short": {
"type": "string"
},
"iat": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Iat"
}
}
}
},
"Contact": {
"type": "object",
"properties": {
"label": {
"type": "string"
},
"type": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"EventDto": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -609,10 +592,7 @@
}
},
"cityRef": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CityRef"
}
"$ref": "#/components/schemas/CityRefDto"
},
"attachments": {
"type": "array",
Expand Down Expand Up @@ -683,29 +663,6 @@
}
}
},
"Iat": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "string"
},
"number": {
"type": "string"
},
"coordinates": {
"$ref": "#/components/schemas/Coordinates"
},
"contacts": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Contact"
}
}
}
},
"TicketDto": {
"type": "object",
"properties": {
Expand Down

0 comments on commit ba4551b

Please sign in to comment.