diff --git a/Sources/App/Controllers/MatchController.swift b/Sources/App/Controllers/MatchController.swift index 60b21ce..f236b05 100644 --- a/Sources/App/Controllers/MatchController.swift +++ b/Sources/App/Controllers/MatchController.swift @@ -25,10 +25,23 @@ struct MatchController: RouteCollection { guard let id = req.parameters.get("id", as: UUID.self) else { throw Abort(.badRequest) } + + let newMatch = try req.content.decode(Match.self) + return Match.find(id, on: req.db) .unwrap(or: Abort(.notFound)) - .flatMap { $0.update(on: req.db) } + .flatMap { + + + $0.update(newMatch: newMatch) + + return $0.save(on: req.db) + + } .map { .ok } + + + } func deleteMatch(req: Request) throws -> EventLoopFuture { diff --git a/Sources/App/Models/Match.swift b/Sources/App/Models/Match.swift index 28b7334..b37ea0b 100644 --- a/Sources/App/Models/Match.swift +++ b/Sources/App/Models/Match.swift @@ -46,6 +46,22 @@ final class Match: Model, Content { self.players = players } + func update( newMatch:Match) { + + guard let _ = newMatch.id else { + return + } + + self.map = newMatch.map + self.win = newMatch.win + self.date = newMatch.date + self.roundsWon = newMatch.roundsWon + self.roundsLost = newMatch.roundsLost + self.codGame = newMatch.codGame; + self.notes = newMatch.notes; + self.players = newMatch.players + } + } extension Match { diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index c90ff36..ffa966c 100644 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -35,12 +35,33 @@ public func configure(_ app: Application) throws { let formatter = DateFormatter() formatter.calendar = Calendar(identifier: .iso8601) formatter.locale = Locale(identifier: "en_US_POSIX") - formatter.timeZone = TimeZone(secondsFromGMT: 0) +formatter.timeZone = TimeZone(secondsFromGMT: 0) formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" decoder.dateDecodingStrategy = .formatted(formatter) + + + let encoder = JSONEncoder() + let encodeFormatter = DateFormatter() + encodeFormatter.calendar = Calendar(identifier: .iso8601) + encodeFormatter.locale = Locale(identifier: "en_US_POSIX") + + let date = Date() + let tz = TimeZone.current +// if tz.isDaylightSavingTime(for: date) { +// encodeFormatter.timeZone = TimeZone(abbreviation: "EST") +// } +// else{ +// encodeFormatter.timeZone = TimeZone(abbreviation: "EDT") +// +// } + + encodeFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + encoder.dateEncodingStrategy = .formatted(encodeFormatter) + // override the global encoder used for the `.json` media type ContentConfiguration.global.use(decoder: decoder, for: .json) + // ContentConfiguration.global.use(encoder: encoder, for: .json) // register routes try routes(app)