Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Concurrency Support #41

Merged
merged 11 commits into from
Jun 23, 2024
Prev Previous commit
Next Next commit
refactoring
KazaiMazai committed Jun 23, 2024

Verified

This commit was signed with the committer’s verified signature.
Bouke Bouke Haarsma
commit 1b774ff7a6425635bbb0b5ad628f73ab2d76bbad

This file was deleted.

77 changes: 77 additions & 0 deletions Sources/VaporRestKit/Resources+CRUDs/Resource+Create.swift
Original file line number Diff line number Diff line change
@@ -119,3 +119,80 @@ public extension RelatedResourceController {
}
}
}

//MARK: - Concurrency

public extension ResourceController {

func create<Input, Model>(
req: Request,
using: Input.Type) async throws -> Output
where
Input: ResourceUpdateModel,
Output.Model == Model,
Input.Model == Output.Model {

try await create(req: req, using: Input.self).get()
}
}

public extension RelatedResourceController {
func create<Input, Model, RelatedModel>(
resolver: Resolver<RelatedModel> = .byIdKeys,
req: Request,
using: Input.Type,
willAttach middleware: ControllerMiddleware<Model, RelatedModel> = .empty,
relationKeyPath: ChildrenKeyPath<RelatedModel, Model>) async throws -> Output
where
Input: ResourceUpdateModel,
Model == Output.Model,
Input.Model == Output.Model {

try await create(
resolver: resolver,
req: req, using: Input.self,
willAttach: middleware,
relationKeyPath: relationKeyPath
).get()
}

func create<Input, Model, RelatedModel>(
resolver: Resolver<RelatedModel> = .byIdKeys,
req: Request,
using: Input.Type,
willAttach middleware: ControllerMiddleware<Model, RelatedModel> = .empty,
relationKeyPath: ChildrenKeyPath<Model, RelatedModel>) async throws -> Output
where
Input: ResourceUpdateModel,
Model == Output.Model,
Input.Model == Output.Model {

try await create(
resolver: resolver,
req: req, using: Input.self,
willAttach: middleware,
relationKeyPath: relationKeyPath
).get()
}

func create<Input, Model, RelatedModel, Through>(
resolver: Resolver<RelatedModel> = .byIdKeys,
req: Request,
using: Input.Type,
willAttach middleware: ControllerMiddleware<Model, RelatedModel> = .empty,
relationKeyPath: SiblingKeyPath<RelatedModel, Model, Through>) async throws -> Output
where
Input: ResourceUpdateModel,
Model == Output.Model,
Input.Model == Output.Model,
Through: Fluent.Model {

try await create(
resolver: resolver,
req: req, using: Input.self,
willAttach: middleware,
relationKeyPath: relationKeyPath
).get()
}
}

This file was deleted.

82 changes: 82 additions & 0 deletions Sources/VaporRestKit/Resources+CRUDs/Resource+Delete.swift
Original file line number Diff line number Diff line change
@@ -114,3 +114,85 @@ public extension RelatedResourceController {
}
}
}

//MARK: - Concurrency

public extension ResourceController {
func delete<Model>(
req: Request,
using deleter: Deleter<Model> = .defaultDeleter(),
queryModifier: QueryModifier<Model> = .empty) async throws -> Output
where
Output.Model == Model {

try await delete(
req: req,
using: deleter,
queryModifier: queryModifier
).get()
}
}

public extension RelatedResourceController {

func delete<Model, RelatedModel>(
resolver: ChildResolver<Model, RelatedModel> = .byIdKeys,
req: Request,
using deleter: Deleter<Model> = .defaultDeleter(),
willDetach middleware: ControllerMiddleware<Model, RelatedModel> = .empty,
queryModifier: QueryModifier<Model> = .empty,
relationKeyPath: ChildrenKeyPath<RelatedModel, Model>) async throws -> Output
where
Model == Output.Model {

try await delete(
resolver: resolver,
req: req,
using: deleter,
willDetach: middleware,
queryModifier: queryModifier,
relationKeyPath: relationKeyPath
).get()
}

func delete<Model, RelatedModel>(
resolver: ParentResolver<Model, RelatedModel> = .byIdKeys,
req: Request,
using deleter: Deleter<Model> = .defaultDeleter(),
willDetach middleware: ControllerMiddleware<Model, RelatedModel> = .empty,
queryModifier: QueryModifier<Model> = .empty,
relationKeyPath: ChildrenKeyPath<Model, RelatedModel>) async throws -> Output
where
Model == Output.Model {

try await delete(
resolver: resolver,
req: req,
using: deleter,
willDetach: middleware,
queryModifier: queryModifier,
relationKeyPath: relationKeyPath
).get()
}

func delete<Model, RelatedModel, Through>(
resolver: SiblingsResolver<Model, RelatedModel, Through> = .byIdKeys,
req: Request,
using deleter: Deleter<Model> = .defaultDeleter(),
willDetach middleware: ControllerMiddleware<Model, RelatedModel> = .empty,
queryModifier: QueryModifier<Model> = .empty,
relationKeyPath: SiblingKeyPath<RelatedModel, Model, Through>) async throws -> Output
where

Model == Output.Model {

try await delete(
resolver: resolver,
req: req,
using: deleter,
willDetach: middleware,
queryModifier: queryModifier,
relationKeyPath: relationKeyPath
).get()
}
}
Loading