diff --git a/.gitignore b/.gitignore
index 17f73d0..27d6dc0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
/*.xcodeproj
xcuserdata/
Package.resolved
+.swiftpm
diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
deleted file mode 100644
index 919434a..0000000
--- a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
: Sendable where P == R.PassType, D == R.DeviceType { + /// The ``PassesDelegate`` to use for pass generation. public unowned let delegate: any PassesDelegate private unowned let app: Application private let v1: any RoutesBuilder private let logger: Logger? + /// Initializes the service. + /// + /// - Parameters: + /// - app: The `Vapor.Application` to use in route handlers and APNs. + /// - delegate: The ``PassesDelegate`` to use for pass generation. + /// - logger: The `Logger` to use. public init(app: Application, delegate: any PassesDelegate, logger: Logger? = nil) { self.delegate = delegate self.logger = logger @@ -45,6 +52,7 @@ public final class PassesServiceCustom
HTTPStatus {
+ let r = try await R.for(deviceLibraryIdentifier: device.deviceLibraryIdentifier, passTypeIdentifier: pass.passTypeIdentifier, on: db)
+ .filter(P.self, \._$id == pass.id!)
+ .first()
+ if r != nil {
+ // If the registration already exists, docs say to return a 200
+ return .ok
}
+
+ let registration = R()
+ registration._$pass.id = pass.id!
+ registration._$device.id = device.id!
+
+ try await registration.create(on: db)
+ return .created
}
func passesForDevice(req: Request) async throws -> PassesForDeviceDTO {
@@ -264,7 +289,31 @@ extension PassesServiceCustom {
return .ok
}
+
+ func personalizedPass(req: Request) async throws -> Response {
+ logger?.debug("Called personalizedPass")
+
+ /*
+ guard let passTypeIdentifier = req.parameters.get("passTypeIdentifier"),
+ let id = req.parameters.get("passSerial", as: UUID.self) else {
+ throw Abort(.badRequest)
+ }
+
+ guard let pass = try await P.query(on: req.db)
+ .filter(\._$id == id)
+ .filter(\._$passTypeIdentifier == passTypeIdentifier)
+ .first()
+ else {
+ throw Abort(.notFound)
+ }
+
+ let personalization = try req.content.decode(PersonalizationDictionaryDTO.self)
+ */
+
+ throw Abort(.notImplemented)
+ }
+ // MARK: - Push Routes
func pushUpdatesForPass(req: Request) async throws -> HTTPStatus {
logger?.debug("Called pushUpdatesForPass")
@@ -290,27 +339,17 @@ extension PassesServiceCustom {
let registrations = try await Self.registrationsForPass(id: id, of: passTypeIdentifier, on: req.db)
return registrations.map { $0.device.pushToken }
}
-
- private static func createRegistration(device: D, pass: P, req: Request) async throws -> HTTPStatus {
- let r = try await R.for(deviceLibraryIdentifier: device.deviceLibraryIdentifier, passTypeIdentifier: pass.passTypeIdentifier, on: req.db)
- .filter(P.self, \._$id == pass.id!)
- .first()
- if r != nil {
- // If the registration already exists, docs say to return a 200
- return .ok
- }
-
- let registration = R()
- registration._$pass.id = pass.id!
- registration._$device.id = device.id!
-
- try await registration.create(on: req.db)
- return .created
- }
}
// MARK: - Push Notifications
extension PassesServiceCustom {
+ /// Sends push notifications for a given pass.
+ ///
+ /// - Parameters:
+ /// - id: The `UUID` of the pass to send the notifications for.
+ /// - passTypeIdentifier: The type identifier of the pass.
+ /// - db: The `Database` to use.
+ /// - app: The `Application` to use.
public static func sendPushNotificationsForPass(id: UUID, of passTypeIdentifier: String, on db: any Database, app: Application) async throws {
let registrations = try await Self.registrationsForPass(id: id, of: passTypeIdentifier, on: db)
for reg in registrations {
@@ -327,6 +366,12 @@ extension PassesServiceCustom {
}
}
+ /// Sends push notifications for a given pass.
+ ///
+ /// - Parameters:
+ /// - pass: The pass to send the notifications for.
+ /// - db: The `Database` to use.
+ /// - app: The `Application` to use.
public static func sendPushNotifications(for pass: P, on db: any Database, app: Application) async throws {
guard let id = pass.id else {
throw FluentError.idRequired
@@ -335,6 +380,12 @@ extension PassesServiceCustom {
try await Self.sendPushNotificationsForPass(id: id, of: pass.passTypeIdentifier, on: db, app: app)
}
+ /// Sends push notifications for a given pass.
+ ///
+ /// - Parameters:
+ /// - pass: The pass (as the `ParentProperty`) to send the notifications for.
+ /// - db: The `Database` to use.
+ /// - app: The `Application` to use.
public static func sendPushNotifications(for pass: ParentProperty