Skip to content

Commit a62f02b

Browse files
committed
Remove MiddlewareController in favor of just RouterController.
1 parent 1b59ff6 commit a62f02b

File tree

3 files changed

+29
-101
lines changed

3 files changed

+29
-101
lines changed

Sources/Hummingbird/Middleware/MiddlewareController.swift

-64
This file was deleted.

Sources/Hummingbird/Router/RouterController.swift

+29-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
// MARK: - RouterController
1616

17-
/// A type that represents part of your app's middleware and routes where their ``MiddlewareController/Input`` is
18-
/// ``Request`` and ``MiddlewareController/Output`` is ``Response``.
19-
///
17+
/// A type that represents part of your app's middleware and routes
18+
///
2019
/// You create custom controllers by declaring types that conform to the `RouterController`
2120
/// protocol. Implement the required ``RouterController/body-swift.property`` computed
2221
/// property to provide the content for your custom controller.
@@ -31,6 +30,32 @@
3130
///
3231
/// Assemble the controller's body by combining one or more of the built-in controllers or middleware.
3332
/// provided by Hummingbird, plus other custom controllers that you define, into a hierarchy of controllers.
34-
public protocol RouterController<Context>: MiddlewareController where Body: RouterMiddleware<Context> {
33+
public protocol RouterController<Context> {
3534
associatedtype Context
35+
associatedtype Body: RouterMiddleware<Context>
36+
@MiddlewareFixedTypeBuilder<Request, Response, Context> var body: Body { get }
37+
}
38+
39+
40+
// MARK: MiddlewareFixedTypeBuilder + RouterController Builders
41+
42+
extension MiddlewareFixedTypeBuilder {
43+
public static func buildExpression<C0: RouterController>(_ c0: C0) -> C0.Body where C0.Body.Input == Input, C0.Body.Output == Output, C0.Body.Context == Context {
44+
return c0.body
45+
}
46+
47+
public static func buildBlock<C0: RouterController>(_ c0: C0) -> C0.Body {
48+
return c0.body
49+
}
50+
51+
public static func buildPartialBlock<C0: RouterController>(first: C0) -> C0.Body {
52+
first.body
53+
}
54+
55+
public static func buildPartialBlock<M0: MiddlewareProtocol, C0: RouterController>(
56+
accumulated m0: M0,
57+
next c0: C0
58+
) -> _Middleware2<M0, C0.Body> where M0.Input == C0.Body.Input, M0.Output == C0.Body.Output, M0.Context == C0.Body.Context {
59+
_Middleware2(m0, c0.body)
60+
}
3661
}

Tests/HummingbirdRouterTests/ControllerTests.swift

-33
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,6 @@ import HummingbirdTesting
1818
import XCTest
1919

2020
final class ControllerTests: XCTestCase {
21-
22-
// MARK: MiddlewareController
23-
24-
func testMiddlewareController() async throws {
25-
struct TestController: MiddlewareController {
26-
typealias Input = Request
27-
typealias Output = Response
28-
typealias Context = BasicRouterRequestContext
29-
30-
var body: some MiddlewareProtocol<Input, Output, Context> {
31-
Get("foo") { _,_ in "foo" }
32-
Get("bar") { _,_ in "bar" }
33-
}
34-
}
35-
36-
let router = RouterBuilder(context: BasicRouterRequestContext.self) {
37-
TestController()
38-
}
39-
40-
let app = Application(responder: router)
41-
try await app.test(.router) { client in
42-
try await client.execute(uri: "/foo", method: .get) {
43-
XCTAssertEqual(String(buffer: $0.body), "foo")
44-
}
45-
46-
try await client.execute(uri: "/bar", method: .get) {
47-
XCTAssertEqual(String(buffer: $0.body), "bar")
48-
}
49-
}
50-
}
51-
52-
// MARK: RouterController
53-
5421
func testRouterController() async throws {
5522
struct TestController: RouterController {
5623
typealias Context = BasicRouterRequestContext

0 commit comments

Comments
 (0)