Skip to content

Instantly share code, notes, and snippets.

@aquaibm
Created June 25, 2018 09:27
Show Gist options
  • Save aquaibm/609f79f19e575acf2de0e3d1f1265bcb to your computer and use it in GitHub Desktop.
Save aquaibm/609f79f19e575acf2de0e3d1f1265bcb to your computer and use it in GitHub Desktop.
struct TopicController {
func getTopicSubscriber(_ req: Request) throws -> Future<[User]> {
let name = try req.parameters.next(String.self)
guard let convert = name.removingPercentEncoding else {
throw Abort(.expectationFailed, reason: "主题名称无效", identifier: nil)
}
return Topic.query(on: req).filter(\.name ~= convert).first().flatMap({ (topic) in
guard let topic = topic else {
throw Abort(.badRequest, reason: "主题不存在", identifier: nil)
}
return try topic.subcribers.query(on: req).all()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment