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.
 
 

48 regels
1.2 KiB

  1. //
  2. // cntrlStatus.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 4/1/24.
  6. //
  7. import Fluent
  8. import Vapor
  9. struct cntrlStatus: RouteCollection {
  10. func boot(routes: RoutesBuilder) throws {
  11. let rts = routes.grouped("statuses")
  12. rts.get(use: index)
  13. rts.get(":x", use: read)
  14. rts.post(use: create)
  15. rts.group(":x") { rt in
  16. rts.delete(use: delete)
  17. }
  18. ///Add custom routes here
  19. }
  20. func index(req: Request) async throws -> [mdlStatus] {
  21. try await mdlStatus.ObjQuery(req: req).all()
  22. }
  23. func read(req:Request) async throws -> mdlStatus{
  24. return try await mdlStatus.ObjQuery(req: req).first()!
  25. }
  26. func create(req: Request) async throws -> mdlStatus {
  27. let obj = try req.content.decode(mdlStatus.self)
  28. if(obj.id != nil){
  29. obj._$idExists = true
  30. }
  31. try await obj.save(on: req.db)
  32. return obj
  33. }
  34. func delete(req: Request) async throws -> HTTPStatus {
  35. guard let obj = try await mdlStatus.find(req.parameters.get("id"), on: req.db) else {
  36. throw Abort(.notFound)
  37. }
  38. try await obj.delete(on: req.db)
  39. return .noContent
  40. }
  41. }