feat: Moves api controller to it's own module.

This commit is contained in:
2025-01-25 15:54:02 -05:00
parent 67e689b51e
commit 0fad024350
14 changed files with 234 additions and 80 deletions

View File

@@ -0,0 +1,34 @@
import Dependencies
import DependenciesMacros
import Logging
import SharedModels
public extension DependencyValues {
var apiController: ApiController {
get { self[ApiController.self] }
set { self[ApiController.self] = newValue }
}
}
@DependencyClient
public struct ApiController: Sendable {
public var json: @Sendable (Request) async throws -> (any Encodable)?
public func json(_ route: ApiRoute, logger: Logger) async throws -> (any Encodable)? {
try await json(.init(route, logger: logger))
}
public struct Request: Sendable {
public let route: ApiRoute
public let logger: Logger
public init(_ route: ApiRoute, logger: Logger) {
self.route = route
self.logger = logger
}
}
}
extension ApiController: TestDependencyKey {
public static let testValue: ApiController = Self()
}