support for update

This commit is contained in:
Michael Simard
2021-01-09 09:56:27 -06:00
parent ae66dfd1d6
commit 523b480376
3 changed files with 52 additions and 2 deletions

View File

@@ -25,10 +25,23 @@ struct MatchController: RouteCollection {
guard let id = req.parameters.get("id", as: UUID.self) else {
throw Abort(.badRequest)
}
let newMatch = try req.content.decode(Match.self)
return Match.find(id, on: req.db)
.unwrap(or: Abort(.notFound))
.flatMap { $0.update(on: req.db) }
.flatMap {
$0.update(newMatch: newMatch)
return $0.save(on: req.db)
}
.map { .ok }
}
func deleteMatch(req: Request) throws -> EventLoopFuture<HTTPStatus> {