Skip to content

Instantly share code, notes, and snippets.

@jaimedantas
Created March 31, 2021 23:31
Show Gist options
  • Save jaimedantas/7410a580801a76ee59408d19b63076f3 to your computer and use it in GitHub Desktop.
Save jaimedantas/7410a580801a76ee59408d19b63076f3 to your computer and use it in GitHub Desktop.
@Controller
class RestController {
@Inject
lateinit var loadSimulator: LoadSimulator
private val logger: Logger = LoggerFactory.getLogger(javaClass)
val validator: Validator<Resource> = ResourceValidator()
/**
* Simulates an API call with some processing.
*/
@Get(uri = "/resource/{resourceId}")
@Produces(MediaType.APPLICATION_JSON)
suspend fun loadSimulator(resourceId: String): HttpResponse<Any> {
val correlationId = UUID.randomUUID()
val httpResponse: HttpResponse<Any>
logger.info("Processing request {}", correlationId)
val validationResult = validator.validate(Resource(resourceId))
httpResponse = if (validationResult.isValid){
val response = loadSimulator.processLoad()
HttpResponse.status<Any>(HttpStatus.OK).body<Any>(response)
} else {
HttpResponse.status<Any>(HttpStatus.BAD_REQUEST).body<Any>(validationResult.errors)
}
logger.info("Finished Processing {}", correlationId)
return httpResponse
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment