Skip to content

Commit

Permalink
chore: Remove unused imports and reorganize Passes module
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Jun 30, 2024
1 parent bc58a7b commit d21c482
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 45 deletions.
28 changes: 0 additions & 28 deletions Sources/PassKit/FakeSendable.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
/// Copyright 2020 Gargoyle Software, LLC
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
/// distribute, sublicense, create a derivative work, and/or sell copies of the
/// Software in any work that is designed, intended, or marketed for pedagogical or
/// instructional purposes related to programming, coding, application development,
/// or information technology. Permission for such use, copying, modification,
/// merger, publication, distribution, sublicensing, creation of derivative works,
/// or sale is expressly withheld.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

// This is a temporary fix until RoutesBuilder and EmptyPayload are not Sendable
package struct FakeSendable<T>: @unchecked Sendable {
package let value: T
Expand Down
3 changes: 1 addition & 2 deletions Sources/PassKit/Models/DeviceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

import Vapor
import Fluent
import FluentKit

/// Represents the `Model` that stores PassKit devices.
public protocol DeviceModel: Model where IDValue == Int {
Expand Down
3 changes: 1 addition & 2 deletions Sources/PassKit/Models/ErrorLogModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

import Vapor
import Fluent
import FluentKit

/// Represents the `Model` that stores PassKit error logs.
public protocol ErrorLogModel: Model {
Expand Down
3 changes: 1 addition & 2 deletions Sources/Passes/Models/Concrete Models/PassesDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Francesco Paolo Severino on 29/06/24.
//

import Foundation
import FluentKit
import PassKit

Expand Down Expand Up @@ -51,4 +50,4 @@ extension PassesDevice {
static let pushToken = FieldKey(stringLiteral: "push_token")
static let deviceLibraryIdentifier = FieldKey(stringLiteral: "device_library_identifier")
}
}
}
4 changes: 2 additions & 2 deletions Sources/Passes/Models/Concrete Models/PassesErrorLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Francesco Paolo Severino on 29/06/24.
//

import Foundation
import struct Foundation.Date
import FluentKit
import PassKit

Expand Down Expand Up @@ -49,4 +49,4 @@ extension PassesErrorLog {
static let createdAt = FieldKey(stringLiteral: "created_at")
static let message = FieldKey(stringLiteral: "message")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Francesco Paolo Severino on 29/06/24.
//

import Foundation
import FluentKit

/// The `Model` that stores passes registrations.
Expand Down
1 change: 0 additions & 1 deletion Sources/Passes/Models/PassDataModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

import Vapor
import FluentKit

/// Represents the `Model` that stores custom app data associated to PassKit passes.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Passes/Models/PassModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

import Vapor
import Foundation
import FluentKit

/// Represents the `Model` that stores PassKit passes.
Expand Down
1 change: 0 additions & 1 deletion Sources/Passes/Models/PassesRegistrationModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

import Vapor
import FluentKit
import PassKit

Expand Down
2 changes: 1 addition & 1 deletion Sources/Passes/PassesDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

import Vapor
import Foundation
import FluentKit

/// The delegate which is responsible for generating the pass files.
Expand Down
14 changes: 10 additions & 4 deletions Sources/Passes/PassesServiceCustom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class PassesServiceCustom<P, D, R: PassesRegistrationModel, E: Erro
///
/// ### Example ###
/// ```swift
/// try pk.registerPushRoutes(environment: .sandbox, middleware: PushAuthMiddleware())
/// try passesService.registerPushRoutes(middleware: SecretMiddleware(secret: "foo"))
/// ```
///
/// - Parameter middleware: The `Middleware` which will control authentication for the routes.
Expand Down Expand Up @@ -106,8 +106,10 @@ public final class PassesServiceCustom<P, D, R: PassesRegistrationModel, E: Erro
pushAuth.post("push", ":passTypeIdentifier", ":passSerial", use: { try await self.pushUpdatesForPass(req: $0) })
pushAuth.get("push", ":passTypeIdentifier", ":passSerial", use: { try await self.tokensForPassUpdate(req: $0) })
}
}

// MARK: - API Routes
// MARK: - API Routes
extension PassesServiceCustom {
func registerDevice(req: Request) async throws -> HTTPStatus {
logger?.debug("Called register device")

Expand Down Expand Up @@ -305,8 +307,10 @@ public final class PassesServiceCustom<P, D, R: PassesRegistrationModel, E: Erro
try await registration.create(on: req.db)
return .created
}
}

// MARK: - Push Notifications
// MARK: - Push Notifications
extension PassesServiceCustom {
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 {
Expand Down Expand Up @@ -356,8 +360,10 @@ public final class PassesServiceCustom<P, D, R: PassesRegistrationModel, E: Erro
.filter(P.self, \._$id == id)
.all()
}
}

// MARK: - pkpass file generation
// MARK: - pkpass file generation
extension PassesServiceCustom {
private static func generateManifestFile(using encoder: JSONEncoder, in root: URL) throws {
var manifest: [String: String] = [:]

Expand Down

0 comments on commit d21c482

Please sign in to comment.