added post method for updating match

This commit is contained in:
Michael Simard
2020-12-21 10:26:32 -06:00
parent 3d0a14ba4a
commit 87726f6b99
2 changed files with 25 additions and 29 deletions

View File

@@ -15,6 +15,20 @@ struct MatchController: RouteCollection {
func boot(routes: RoutesBuilder) throws {
let matchRoute = routes.grouped("cod-tracker","api", "match")
matchRoute.delete("delete", "id",":id", use: deleteMatch)
matchRoute.post("update", "id",":id", use: updateMatch)
matchRoute.post("add", use: logMatch)
}
func updateMatch(req: Request) throws -> EventLoopFuture<HTTPStatus> {
guard let id = req.parameters.get("id", as: UUID.self) else {
throw Abort(.badRequest)
}
return Match.find(id, on: req.db)
.unwrap(or: Abort(.notFound))
.flatMap { $0.update(on: req.db) }
.map { .ok }
}
func deleteMatch(req: Request) throws -> EventLoopFuture<HTTPStatus> {
@@ -27,4 +41,12 @@ struct MatchController: RouteCollection {
.map { .ok }
}
func logMatch(req: Request) throws -> EventLoopFuture<Match> {
let newMatch = try req.content.decode(Match.self)
return newMatch.save(on: req.db).map { newMatch}
}
}