-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85c3f6b
commit 8fbf839
Showing
3 changed files
with
53 additions
and
0 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
40 changes: 40 additions & 0 deletions
40
...PNCommunityCoreiOS/Root/RouteCollections/Subscriptions/SubscriptionsRouteCollection.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,40 @@ | ||
// | ||
// SubscriptionsRouteCollection.swift | ||
// SOLARdVPNCommunityCoreiOS | ||
// | ||
// Created by Viktoriia Kostyleva on 06.10.2022. | ||
// | ||
|
||
import Vapor | ||
|
||
private struct Constants { | ||
let path: PathComponent = "subscriptions" | ||
} | ||
private let constants = Constants() | ||
|
||
struct SubscriptionsRouteCollection: RouteCollection { | ||
let context: HasSubscriptionsService | ||
|
||
func boot(routes: RoutesBuilder) throws { | ||
routes.get(constants.path, use: getSubscriptions) | ||
} | ||
} | ||
|
||
extension SubscriptionsRouteCollection { | ||
func getSubscriptions(_ req: Request) async throws -> String { | ||
try await withCheckedThrowingContinuation({ (continuation: CheckedContinuation<String, Error>) in | ||
context.subscriptionsService.loadActiveSubscriptions { result in | ||
switch result { | ||
case let .failure(error): | ||
continuation.resume(throwing: Abort(.init(statusCode: 500), reason: error.localizedDescription)) | ||
|
||
case let .success(subscriptions): | ||
let subscriptions = subscriptions.map { $0.node } | ||
let response = Array(Set(subscriptions)) | ||
|
||
Encoder.encode(model: response, continuation: continuation) | ||
} | ||
} | ||
}) | ||
} | ||
} |
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