Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cntrlIncompleteReason.swift 1.2 KiB

2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // cntrlIncompleteReason.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 4/1/24.
  6. //
  7. import Fluent
  8. import Vapor
  9. struct cntrlIncompleteReason: RouteCollection {
  10. func boot(routes: RoutesBuilder) throws {
  11. let rts = routes.grouped("incompletereasons")
  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 -> [mdlIncompleteReason] {
  21. try await mdlIncompleteReason.ObjQuery(req: req).all()
  22. }
  23. func read(req:Request) async throws -> mdlIncompleteReason{
  24. return try await mdlIncompleteReason.ObjQuery(req: req).first()!
  25. }
  26. func create(req: Request) async throws -> mdlIncompleteReason {
  27. let obj = try req.content.decode(mdlIncompleteReason.self)
  28. try await obj.save(on: req.db)
  29. return obj
  30. }
  31. func delete(req: Request) async throws -> HTTPStatus {
  32. guard let obj = try await mdlIncompleteReason.find(req.parameters.get("id"), on: req.db) else {
  33. throw Abort(.notFound)
  34. }
  35. try await obj.delete(on: req.db)
  36. return .noContent
  37. }
  38. }