Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Last active March 4, 2018 08:16
Show Gist options
  • Save mczachurski/2e54508232c3ddabd03bf4d0c36c610d to your computer and use it in GitHub Desktop.
Save mczachurski/2e54508232c3ddabd03bf4d0c36c610d 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,
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