Skip to content

Commit

Permalink
Change PKRegistration to PassesRegistration
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Jun 27, 2024
1 parent d997d29 commit 49aae8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ The table below shows a list of PassKit major releases alongside their compatibl

|Version|Swift|SPM|
|---|---|---|
|0.3.1|5.10+|`from: "0.3.1"`|
|0.4.0|5.10+|`from: "0.4.0"`|
|0.2.0|5.9+|`from: "0.2.0"`|
|0.1.0|5.9+|`from: "0.1.0"`|

Use the SPM string to easily include the dependendency in your `Package.swift` file

```swift
.package(url: "https://github.com/vapor-community/PassKit.git", from: "0.3.1")
.package(url: "https://github.com/vapor-community/PassKit.git", from: "0.4.0")
```

and add it to your target's dependencies:
Expand All @@ -42,7 +42,7 @@ and add it to your target's dependencies:
.product(name: "Passes", package: "PassKit")
```

> Note: This package requires Vapor 4.
> Note: This package is made for Vapor 4.
## Usage

Expand Down Expand Up @@ -99,15 +99,15 @@ CREATE OR REPLACE FUNCTION public."RemoveUnregisteredItems"() RETURNS trigger
DELETE FROM devices d
WHERE NOT EXISTS (
SELECT 1
FROM registrations r
FROM passes_registrations r
WHERE d."id" = r.device_id
LIMIT 1
);

DELETE FROM passes p
WHERE NOT EXISTS (
SELECT 1
FROM registrations r
FROM passes_registrations r
WHERE p."id" = r.pass_id
LIMIT 1
);
Expand All @@ -117,7 +117,7 @@ END
$$;

CREATE TRIGGER "OnRegistrationDelete"
AFTER DELETE ON "public"."registrations"
AFTER DELETE ON "public"."passes_registrations"
FOR EACH ROW
EXECUTE PROCEDURE "public"."RemoveUnregisteredItems"();
```
Expand Down
18 changes: 9 additions & 9 deletions Sources/Passes/Models/ConcreteModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,30 @@ extension PKErrorLog {
}

/// The `Model` that stores PassKit registrations.
final public class PKRegistration: PassesRegistrationModel, @unchecked Sendable {
final public class PassesRegistration: PassesRegistrationModel, @unchecked Sendable {
public typealias PassType = PKPass
public typealias DeviceType = PKDevice

public static let schema = PKRegistration.FieldKeys.schemaName
public static let schema = PassesRegistration.FieldKeys.schemaName

@ID(custom: .id)
public var id: Int?

@Parent(key: PKRegistration.FieldKeys.deviceID)
@Parent(key: PassesRegistration.FieldKeys.deviceID)
public var device: DeviceType

@Parent(key: PKRegistration.FieldKeys.passID)
@Parent(key: PassesRegistration.FieldKeys.passID)
public var pass: PassType

public init() {}
}

extension PKRegistration: AsyncMigration {
extension PassesRegistration: AsyncMigration {
public func prepare(on database: any Database) async throws {
try await database.schema(Self.schema)
.field(.id, .int, .identifier(auto: true))
.field(PKRegistration.FieldKeys.deviceID, .int, .required, .references(DeviceType.schema, .id, onDelete: .cascade))
.field(PKRegistration.FieldKeys.passID, .uuid, .required, .references(PassType.schema, .id, onDelete: .cascade))
.field(PassesRegistration.FieldKeys.deviceID, .int, .required, .references(DeviceType.schema, .id, onDelete: .cascade))
.field(PassesRegistration.FieldKeys.passID, .uuid, .required, .references(PassType.schema, .id, onDelete: .cascade))
.create()
}

Expand All @@ -190,9 +190,9 @@ extension PKRegistration: AsyncMigration {
}
}

extension PKRegistration {
extension PassesRegistration {
enum FieldKeys {
static let schemaName = "registrations"
static let schemaName = "passes_registrations"
static let deviceID = FieldKey(stringLiteral: "device_id")
static let passID = FieldKey(stringLiteral: "pass_id")
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/Passes/PassesService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import PassKit

/// The main class that handles PassKit passes.
public final class PassesService: Sendable {
private let kit: PassesServiceCustom<PKPass, PKDevice, PKRegistration, PKErrorLog>
private let kit: PassesServiceCustom<PKPass, PKDevice, PassesRegistration, PKErrorLog>

public init(app: Application, delegate: any PassesDelegate, logger: Logger? = nil) {
kit = .init(app: app, delegate: delegate, logger: logger)
Expand Down Expand Up @@ -72,7 +72,7 @@ public final class PassesService: Sendable {
public static func register(migrations: Migrations) {
migrations.add(PKPass())
migrations.add(PKDevice())
migrations.add(PKRegistration())
migrations.add(PassesRegistration())
migrations.add(PKErrorLog())
}

Expand All @@ -84,7 +84,7 @@ public final class PassesService: Sendable {
/// - 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 {
try await PassesServiceCustom<PKPass, PKDevice, PKRegistration, PKErrorLog>.sendPushNotificationsForPass(id: id, of: passTypeIdentifier, on: db, app: app)
try await PassesServiceCustom<PKPass, PKDevice, PassesRegistration, PKErrorLog>.sendPushNotificationsForPass(id: id, of: passTypeIdentifier, on: db, app: app)
}

/// Sends push notifications for a given pass.
Expand All @@ -94,7 +94,7 @@ public final class PassesService: Sendable {
/// - db: The `Database` to use.
/// - app: The `Application` to use.
public static func sendPushNotifications(for pass: PKPass, on db: any Database, app: Application) async throws {
try await PassesServiceCustom<PKPass, PKDevice, PKRegistration, PKErrorLog>.sendPushNotifications(for: pass, on: db, app: app)
try await PassesServiceCustom<PKPass, PKDevice, PassesRegistration, PKErrorLog>.sendPushNotifications(for: pass, on: db, app: app)
}

/// Sends push notifications for a given pass.
Expand All @@ -103,8 +103,8 @@ public final class PassesService: Sendable {
/// - 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<PKRegistration, PKPass>, on db: any Database, app: Application) async throws {
try await PassesServiceCustom<PKPass, PKDevice, PKRegistration, PKErrorLog>.sendPushNotifications(for: pass, on: db, app: app)
public static func sendPushNotifications(for pass: ParentProperty<PassesRegistration, PKPass>, on db: any Database, app: Application) async throws {
try await PassesServiceCustom<PKPass, PKDevice, PassesRegistration, PKErrorLog>.sendPushNotifications(for: pass, on: db, app: app)
}
}

Expand Down

0 comments on commit 49aae8d

Please sign in to comment.