Created
April 9, 2020 12:53
-
-
Save cweinberger/bde3a6a1d8c4e5ff1a3ed3a20a463870 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
func getBook(req: Request) throws -> Book { | |
guard | |
// 1 | |
let bookIDString = req.parameters.get("bookID"), | |
// 2 | |
let bookID = Int(bookIDString), | |
// 3 | |
let book = Self.books.first(where: { $0.id == bookID }) | |
else { | |
// 4 | |
throw Abort(.notFound) | |
} | |
// 5 | |
return book | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment