-
-
Save lievendoclo/204487e3ff1afed333bf8aa45dc08207 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import org.apache.activemq.command.ActiveMQTextMessage | |
import org.springframework.context.event.EventListener | |
import org.springframework.http.HttpStatus | |
import org.springframework.http.ResponseEntity | |
import org.springframework.jms.core.JmsTemplate | |
import org.springframework.jms.core.MessageCreator | |
import org.springframework.web.bind.annotation.GetMapping | |
import org.springframework.web.bind.annotation.PostMapping | |
import javax.jms.Queue | |
import javax.jms.TextMessage | |
// rest infra | |
internal class RestController(private val useCase: UseCase) { | |
@PostMapping | |
fun callSomething(body: String): ResponseEntity<*> { | |
val presenter = JsonPresenter() | |
return useCase.doStuff(UseCaseRequest(body), presenter) | |
} | |
} | |
internal class ShizzleExceptionHandler { | |
@ExceptionHandler(UserException::class.java) | |
fun handleUserException(userException: UserException) = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(failReason) | |
} | |
data class JsonResult (val jsonValue: String) | |
internal class JsonPresenter : Presenter<ResponseEntity<*>> { | |
override fun present(value: UseCaseResult) = ResponseEntity.ok(JsonResult(value.value)) | |
} | |
class UserException(failReason: String) : RuntimeException | |
// app api | |
data class UseCaseRequest (val value: String) | |
data class UseCaseResult (val value: String) | |
interface Presenter<T> { | |
fun present(value: UseCaseResult) : T | |
} | |
interface UseCase { | |
<T> fun doStuff(request: UseCaseRequest, presenter: Presenter<T>) : T | |
} | |
// app impl (ommitted interface) | |
internal class UseCaseImpl : UseCase { | |
override <T> fun doStuff(request: UseCaseRequest, presenter: Presenter<T>) : T { | |
if (request.value == "shizzle"){ | |
throw new UserException("We don't take no shizzle") | |
} | |
presenter.present(UseCaseResult("Shizzle 4 life")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment