58 lines
1.7 KiB
Swift
58 lines
1.7 KiB
Swift
// import Dependencies
|
|
// import Fluent
|
|
// import Vapor
|
|
//
|
|
// struct VendorApiController: RouteCollection {
|
|
//
|
|
// @Dependency(\.vendors) var vendors
|
|
//
|
|
// func boot(routes: any RoutesBuilder) throws {
|
|
// let protected = routes.apiProtected(route: "vendors")
|
|
// protected.get(use: index(req:))
|
|
// protected.post(use: create(req:))
|
|
// protected.group(":id") {
|
|
// $0.put(use: update(req:))
|
|
// $0.delete(use: delete(req:))
|
|
// }
|
|
// }
|
|
//
|
|
// @Sendable
|
|
// func index(req: Request) async throws -> [Vendor.DTO] {
|
|
// let params = try req.query.decode(VendorsIndexQuery.self)
|
|
// return try await vendors.fetchAll(params.fetchRequest)
|
|
// }
|
|
//
|
|
// @Sendable
|
|
// func create(req: Request) async throws -> Vendor.DTO {
|
|
// try await vendors.create(req.ensureValidContent(Vendor.Create.self))
|
|
// }
|
|
//
|
|
// @Sendable
|
|
// func update(req: Request) async throws -> Vendor.DTO {
|
|
// guard let id = req.parameters.get("id", as: Vendor.IDValue.self) else {
|
|
// throw Abort(.badRequest, reason: "Vendor id not provided.")
|
|
// }
|
|
// try Vendor.Update.validate(content: req)
|
|
// let updates = try req.content.decode(Vendor.Update.self)
|
|
// return try await vendors.update(id, updates)
|
|
// }
|
|
//
|
|
// @Sendable
|
|
// func delete(req: Request) async throws -> HTTPStatus {
|
|
// guard let id = req.parameters.get("id", as: Vendor.IDValue.self) else {
|
|
// throw Abort(.badRequest, reason: "Vendor id not provided.")
|
|
// }
|
|
// try await vendors.delete(id)
|
|
// return .ok
|
|
// }
|
|
// }
|
|
//
|
|
// struct VendorsIndexQuery: Content {
|
|
// let branches: Bool?
|
|
//
|
|
// var fetchRequest: VendorDB.FetchRequest {
|
|
// if branches == true { return .withBranches }
|
|
// return .default
|
|
// }
|
|
// }
|