You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- //
- // FuelEntryController.swift
- //
- //
- // Created by Bill Ryckman on 4/24/23.
- //
-
- import Vapor
-
- struct FuelEntryController: RouteCollection {
- func boot(routes: RoutesBuilder) throws {
- let fuelEntries = routes.grouped("fuel_entries")
- fuelEntries.get(use: index)
- fuelEntries.post(use: create)
- fuelEntries.group(":fuelEntryID") { fuelEntry in
- fuelEntry.delete(use: delete)
- }
- }
-
- func index(req: Request) async throws -> [FuelEntry] {
- try await FuelEntry.query(on: req.db).all()
- }
-
- func create(req: Request) async throws -> [FuelEntry] {
- let fuelEntry = try req.content.decode([FuelEntry].self)
- try await fuelEntry.create(on: req.db)
- return fuelEntry
- }
-
- func delete(req: Request) async throws -> HTTPStatus {
- guard let fuelEntry = try await FuelEntry.find(req.parameters.get("fuelEntryID"), on: req.db) else {
- throw Abort(.notFound)
- }
- try await fuelEntry.delete(on: req.db)
- return .noContent
- }
- }
-
-
-
-
|