Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

cntrlCompartmentLocation.swift 1.7 KiB

2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // cntrlCompartmentLocation.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 4/1/24.
  6. //
  7. import Fluent
  8. import Vapor
  9. struct cntrlCompartmentLocation: RouteCollection {
  10. func boot(routes: RoutesBuilder) throws {
  11. let rts = routes.grouped("compartmentlocations")
  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 -> [mdlCompartmentLocation] {
  21. try await mdlCompartmentLocation.ObjQuery(req: req).all()
  22. }
  23. func read(req:Request) async throws -> mdlCompartmentLocation{
  24. return try await mdlCompartmentLocation.ObjQuery(req: req).first()!
  25. }
  26. func create(req: Request) async throws -> mdlCompartmentLocation {
  27. let obj = try req.content.decode(mdlCompartmentLocation.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 update(req: Request) async throws -> mdlCompartmentLocation{
  35. let obj = try req.content.decode(mdlCompartmentLocation.self)
  36. let dbobj = try await mdlCompartmentLocation.query(on: req.db).filter(\.$id == obj.id!).first()!
  37. dbobj.updatedate = Date()
  38. dbobj.updateuserid = -1
  39. try await dbobj.update(on: req.db)
  40. return dbobj
  41. }
  42. func delete(req: Request) async throws -> HTTPStatus {
  43. guard let obj = try await mdlCompartmentLocation.find(req.parameters.get("id"), on: req.db) else {
  44. throw Abort(.notFound)
  45. }
  46. try await obj.delete(on: req.db)
  47. return .noContent
  48. }
  49. }