Last active
March 4, 2018 08:16
-
-
Save mczachurski/2e54508232c3ddabd03bf4d0c36c610d to your computer and use it in GitHub Desktop.
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
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, | |
requirement: OperationAuthorizationRequirement(operation: .read)) { | |
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