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
@RestController | |
@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 !!! | |
*/ | |
@PostMapping | |
fun createProfile(@RequestHeader("User-Id") userId: String, @RequestBody preferences: Preferences): ResponseEntity<Profile> { | |
val profile = createProfile.forUserWithPreferences(userId, preferences.toDomainObject()).toResource() | |
val location = linkTo(this::class.java).slash(profile).toUri() | |
return ResponseEntity.created(location).body(profile) | |
} | |
@ExceptionHandler(ProfileAlreadyExistsException::class) | |
fun handleProfileAlreadyExistsException(response: HttpServletResponse, exception: ProfileAlreadyExistsException) { | |
response.sendError(SC_CONFLICT, exception.message) | |
} | |
} | |
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
@RestController | |
@RequestMapping(path = ["/recommendations"]) | |
class RecommendationController(private val recommendTalks: RecommendTalks) { | |
@PostMapping | |
fun createRecommendation(@RequestHeader("User-Id") user: String): ResponseEntity<Recommendation> { | |
val domainRecommendation = recommendTalks to user | |
val recommendation = domainRecommendation.toResource() | |
val location = linkTo(this::class.java).slash(recommendation).toUri() | |
return ResponseEntity.created(location).body(recommendation) | |
} | |
@ExceptionHandler(ProfileNotFoundException::class) | |
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