Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Last active March 4, 2018 08:12
Show Gist options
  • Save mczachurski/480bc3da218de020b5e4162fde095610 to your computer and use it in GitHub Desktop.
Save mczachurski/480bc3da218de020b5e4162fde095610 to your computer and use it in GitHub Desktop.
public func get(request: HTTPRequest, response: HTTPResponse) {
do {
guard let stringId = request.urlVariables["id"],
let id = UUID(uuidString: stringId) else {
return response.sendBadRequestError()
}
guard let task = try self.tasksService.get(byId: id) else {
return response.sendNotFoundError()
}
guard let user = request.getUserCredentials() else {
return response.sendUnauthorizedError()
}
if try !self.authorizationService.authorize(user: user,
resource: task,
policy: "EditPolicy") {
return response.sendForbiddenError()
}
let taskDto = TaskDto(task: task)
return response.sendJson(taskDto)
}
catch {
response.sendInternalServerError(error: error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment