added post method for updating match
This commit is contained in:
@@ -15,6 +15,20 @@ struct MatchController: RouteCollection {
|
|||||||
func boot(routes: RoutesBuilder) throws {
|
func boot(routes: RoutesBuilder) throws {
|
||||||
let matchRoute = routes.grouped("cod-tracker","api", "match")
|
let matchRoute = routes.grouped("cod-tracker","api", "match")
|
||||||
matchRoute.delete("delete", "id",":id", use: deleteMatch)
|
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> {
|
func deleteMatch(req: Request) throws -> EventLoopFuture<HTTPStatus> {
|
||||||
@@ -27,4 +41,12 @@ struct MatchController: RouteCollection {
|
|||||||
.map { .ok }
|
.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}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ struct StatsController: RouteCollection {
|
|||||||
|
|
||||||
statsRoute.get("history","page",":page", use: history)
|
statsRoute.get("history","page",":page", use: history)
|
||||||
statsRoute.get("history", use: history)
|
statsRoute.get("history", use: history)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -47,14 +49,8 @@ struct StatsController: RouteCollection {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Match.query(on: req.db).count().flatMap { (totalMatches) -> EventLoopFuture<MatchHistory> in
|
return Match.query(on: req.db).count().flatMap { (totalMatches) -> EventLoopFuture<MatchHistory> in
|
||||||
|
|
||||||
|
|
||||||
return Match.query(on: req.db).sort(\.$date, .descending).limit(20).all().map { (matches) -> (MatchHistory) in
|
return Match.query(on: req.db).sort(\.$date, .descending).limit(20).all().map { (matches) -> (MatchHistory) in
|
||||||
|
|
||||||
return MatchHistory(total:totalMatches, matches: matches, hasMorePages: totalMatches > 20)
|
return MatchHistory(total:totalMatches, matches: matches, hasMorePages: totalMatches > 20)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -62,28 +58,6 @@ struct StatsController: RouteCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// let startRecord = page * 20
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// if totalRecords.map
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// return Match.query(on: req.db).sort(\.$date, .descending).range(startRecord...).all().map { (matches) -> ([Match]) in
|
|
||||||
// return matches
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// return Match.query(on: req.db).sort(\.$date, .descending).limit(20).all().map { (matches) -> ([Match]) in
|
|
||||||
// return matches
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user