Files
cod-backend/Sources/App/Controllers/MatchController.swift
Michael Simard 550f986dd7 updates
2020-12-13 09:40:01 -06:00

31 lines
731 B
Swift

//
// 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 }
}
}