Nelze vybrat více než 25 témat
Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
|
- //
- // cntrlStatus.swift
- //
- //
- // Created by Michiel Carman on 4/1/24.
- //
-
- import Fluent
- import Vapor
-
- struct cntrlStatus: RouteCollection {
- func boot(routes: RoutesBuilder) throws {
- let rts = routes.grouped("statuses")
- rts.get(use: index)
- rts.post(use: create)
- rts.put(use: update)
- rts.group(":id") { rt in
- rts.delete(use: delete)
- }
- }
-
- func index(req: Request) async throws -> [mdlStatus] {
- try await mdlStatus.query(on: req.db).all()
- }
-
- func create(req: Request) async throws -> mdlStatus {
- let obj = try req.content.decode(mdlStatus.self)
- try await obj.save(on: req.db)
- return obj
- }
- func update(req: Request) async throws -> mdlStatus{
- let obj = try req.content.decode(mdlStatus.self)
- let dbobj = try await mdlStatus.query(on: req.db).filter(\.$id == obj.id!).first()!
-
- dbobj.updatedate = Date()
- dbobj.updateuserid = -1
- try await dbobj.update(on: req.db)
- return dbobj
-
- }
-
- func delete(req: Request) async throws -> HTTPStatus {
- guard let obj = try await mdlStatus.find(req.parameters.get("id"), on: req.db) else {
- throw Abort(.notFound)
- }
- try await obj.delete(on: req.db)
- return .noContent
- }
- }
|