Skip to content

Instantly share code, notes, and snippets.

Last active August 12, 2020 22:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
@RequestMapping(path = ["/profiles"])
class ProfileController(private val createProfile: CreateProfile) {
* simulating an authentication context by passing the userId in a header,
* no need to set up all the security frameworks for this demo, but never do that in production !!!
fun createProfile(@RequestHeader("User-Id") userId: String, @RequestBody preferences: Preferences): ResponseEntity<Profile> {
val profile = createProfile.forUserWithPreferences(userId, preferences.toDomainObject()).toResource()
val location = linkTo(
return ResponseEntity.created(location).body(profile)
fun handleProfileAlreadyExistsException(response: HttpServletResponse, exception: ProfileAlreadyExistsException) {
response.sendError(SC_CONFLICT, exception.message)
@RequestMapping(path = ["/recommendations"])
class RecommendationController(private val recommendTalks: RecommendTalks) {
fun createRecommendation(@RequestHeader("User-Id") user: String): ResponseEntity<Recommendation> {
val domainRecommendation = recommendTalks to user
val recommendation = domainRecommendation.toResource()
val location = linkTo(
return ResponseEntity.created(location).body(recommendation)
fun handleProfileNotFoundException(response: HttpServletResponse, exception: ProfileNotFoundException) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, exception.message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment