-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Completely remove the delegates and move their methods to `PassDataModel` and `OrderDataModel` - Provide a default implementation for the model middleware of `PassDataModel` and `OrderDataModel` - Update DocC
- Loading branch information
1 parent
61371c3
commit 01bd819
Showing
49 changed files
with
562 additions
and
933 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Sources/Orders/Middleware/OrdersService+AsyncModelMiddleware.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import FluentKit | ||
import Foundation | ||
|
||
extension OrdersService: AsyncModelMiddleware { | ||
public func create(model: OD, on db: any Database, next: any AnyAsyncModelResponder) async throws { | ||
let order = Order( | ||
typeIdentifier: OD.typeIdentifier, | ||
authenticationToken: Data([UInt8].random(count: 12)).base64EncodedString() | ||
) | ||
try await order.save(on: db) | ||
model._$order.id = try order.requireID() | ||
try await next.create(model, on: db) | ||
} | ||
|
||
public func update(model: OD, on db: any Database, next: any AnyAsyncModelResponder) async throws { | ||
let order = try await model._$order.get(on: db) | ||
order.updatedAt = Date.now | ||
try await order.save(on: db) | ||
try await next.update(model, on: db) | ||
try await self.sendPushNotifications(for: model, on: db) | ||
} | ||
} | ||
|
||
extension OrdersServiceCustom: AsyncModelMiddleware { | ||
public func create(model: OD, on db: any Database, next: any AnyAsyncModelResponder) async throws { | ||
let order = O( | ||
typeIdentifier: OD.typeIdentifier, | ||
authenticationToken: Data([UInt8].random(count: 12)).base64EncodedString() | ||
) | ||
try await order.save(on: db) | ||
model._$order.id = try order.requireID() | ||
try await next.create(model, on: db) | ||
} | ||
|
||
public func update(model: OD, on db: any Database, next: any AnyAsyncModelResponder) async throws { | ||
let order = try await model._$order.get(on: db) | ||
order.updatedAt = Date.now | ||
try await order.save(on: db) | ||
try await next.update(model, on: db) | ||
try await self.sendPushNotifications(for: model, on: db) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
Sources/Orders/Models/Concrete Models/OrdersRegistration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.