Created
March 31, 2021 23:31
-
-
Save jaimedantas/7410a580801a76ee59408d19b63076f3 to your computer and use it in GitHub Desktop.
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
@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