This commit is contained in:
Michael Simard
2020-12-13 09:40:01 -06:00
parent 172b4fed06
commit 550f986dd7
4 changed files with 127 additions and 68 deletions

View File

@@ -0,0 +1,30 @@
//
// MatchController.swift
// App
//
// Created by Michael Simard on 12/13/20.
//
import Foundation
import Fluent
import Vapor
struct MatchController: RouteCollection {
func boot(routes: RoutesBuilder) throws {
let matchRoute = routes.grouped("cod-tracker","api", "match")
matchRoute.delete("delete", "id",":id", use: deleteMatch)
}
func deleteMatch(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.delete(on: req.db) }
.map { .ok }
}
}