Last active
March 4, 2018 08:12
-
-
Save mczachurski/480bc3da218de020b5e4162fde095610 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
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