Created
June 25, 2018 09:27
-
-
Save aquaibm/609f79f19e575acf2de0e3d1f1265bcb 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
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