From 172b4fed06e61c5cd6d15db663b152f405ec014d Mon Sep 17 00:00:00 2001 From: Michael Simard Date: Fri, 11 Dec 2020 07:56:06 -0600 Subject: [PATCH] new history function --- Sources/App/Controllers/StatsController.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/App/Controllers/StatsController.swift b/Sources/App/Controllers/StatsController.swift index c71d6ce..bd2696b 100644 --- a/Sources/App/Controllers/StatsController.swift +++ b/Sources/App/Controllers/StatsController.swift @@ -23,10 +23,20 @@ struct StatsController: RouteCollection { statsRoute.get("test", use: test) statsRoute.post("logMatch", use: logMatch) + + statsRoute.get("history", use: history) + } + func history(req: Request) throws -> EventLoopFuture<[Match]> { + return Match.query(on: req.db).sort(\.$date, .descending).limit(20).all().map { (matches) -> ([Match]) in + return matches + } + } + + func logMatch(req: Request) throws -> EventLoopFuture {