update date decoder
This commit is contained in:
@@ -24,20 +24,13 @@ struct StatsController: RouteCollection {
|
|||||||
statsRoute.post("logMatch", use: logMatch)
|
statsRoute.post("logMatch", use: logMatch)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct CreateMatchRequestBody: Content {
|
|
||||||
let match: Match
|
|
||||||
|
|
||||||
func makeMatch(match:Match) -> Match {
|
|
||||||
return Match(id: match.id, map: match.map, win: match.win, date: match.date, roundsWon: match.roundsWon, roundsLost: match.roundsLost, codGame: match.codGame, notes: match.notes, players: match.players)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
func logMatch(req: Request) throws -> EventLoopFuture<Match> {
|
func logMatch(req: Request) throws -> EventLoopFuture<Match> {
|
||||||
|
|
||||||
let newMatch = try req.content.decode(Match.self)
|
|
||||||
|
|
||||||
|
let newMatch = try req.content.decode(Match.self)
|
||||||
return newMatch.save(on: req.db).map { newMatch}
|
return newMatch.save(on: req.db).map { newMatch}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +239,7 @@ struct StatsController: RouteCollection {
|
|||||||
let mostRecentDailyStats = self.mostRecentDailyStats(matches: matches)
|
let mostRecentDailyStats = self.mostRecentDailyStats(matches: matches)
|
||||||
|
|
||||||
return AllStats.init(overall: overallStats,mwStats: mwStats, bocwStats: bocwStats, byMonth: monthlyStats, highestWinLossRatio: highestWinLossRatio, dataPoints: cumulativeWinLossRatios, mostRecentRecord: "\(mostRecentDailyStats.totalWins) - \(mostRecentDailyStats.totalLosses)")
|
return AllStats.init(overall: overallStats,mwStats: mwStats, bocwStats: bocwStats, byMonth: monthlyStats, highestWinLossRatio: highestWinLossRatio, dataPoints: cumulativeWinLossRatios, mostRecentRecord: "\(mostRecentDailyStats.totalWins) - \(mostRecentDailyStats.totalLosses)")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,20 @@ public func configure(_ app: Application) throws {
|
|||||||
app.migrations.add(AddCODGame2())
|
app.migrations.add(AddCODGame2())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// create a new JSON encoder that uses unix-timestamp dates
|
||||||
|
let decoder = JSONDecoder()
|
||||||
|
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.calendar = Calendar(identifier: .iso8601)
|
||||||
|
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||||
|
formatter.timeZone = TimeZone(secondsFromGMT: 0)
|
||||||
|
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
||||||
|
decoder.dateDecodingStrategy = .formatted(formatter)
|
||||||
|
|
||||||
|
// override the global encoder used for the `.json` media type
|
||||||
|
ContentConfiguration.global.use(decoder: decoder, for: .json)
|
||||||
|
|
||||||
// register routes
|
// register routes
|
||||||
try routes(app)
|
try routes(app)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user