package com.aramark.ess.command.api import com.aramark.ess.common.RegisterSyncHostCommand import com.aramark.ess.util.AuditEntry import org.axonframework.commandhandling.callbacks.LoggingCallback import org.axonframework.commandhandling.gateway.CommandGateway import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.* import java.util.* @RestController class SyncHostController(private val commandGateway: CommandGateway) { private val currentUser: String get() = "TEST" private val auditEntry: AuditEntry get() = AuditEntry(currentUser, Calendar.getInstance().time) @GetMapping(value = "/synchost") fun getAll(): String { return "Hello World 2" } @PostMapping(value = "/synchost/register") @ResponseStatus(value = HttpStatus.CREATED) fun registerSyncHost(@RequestBody registerHostRequest: RegisterHostRequest) { commandGateway.send( RegisterSyncHostCommand( name = registerHostRequest.name, uri = registerHostRequest.uri, headerParams = registerHostRequest.headerParams, environment = registerHostRequest.environment, auditEntry = auditEntry), LoggingCallback.INSTANCE) } } class RegisterHostRequest(val name: String, val uri: String, val headerParams: List, val environment: String)