Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trys removed #6

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Sources/CrudRouter/ControllerProtocols/Crudable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public protocol Crudable: ControllerProtocol {
at path: PathComponentsRepresentable...,
parent relation: KeyPath<ChildType, Parent<ChildType, ParentType>>,
_ either: OnlyExceptEither<ParentRouterMethod>,
relationConfiguration: ((CrudParentController<ChildType, ParentType>) throws -> Void)?
) throws where
relationConfiguration: ((CrudParentController<ChildType, ParentType>) -> Void)?
) where
ParentType: Model & Content,
ChildType.Database == ParentType.Database,
ParentType.ID: Parameter
Expand All @@ -18,8 +18,8 @@ public protocol Crudable: ControllerProtocol {
at path: PathComponentsRepresentable...,
children relation: KeyPath<ChildType, Children<ChildType, ChildChildType>>,
_ either: OnlyExceptEither<ChildrenRouterMethod>,
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) throws -> Void)?
) throws where
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) -> Void)?
) where
ChildChildType: Model & Content,
ChildType.Database == ChildChildType.Database,
ChildChildType.ID: Parameter
Expand All @@ -28,8 +28,8 @@ public protocol Crudable: ControllerProtocol {
at path: PathComponentsRepresentable...,
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod>,
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) throws -> Void)?
) throws where
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?
) where
ChildChildType: Content,
ChildType.Database == ThroughType.Database,
ChildChildType.ID: Parameter,
Expand All @@ -43,8 +43,8 @@ public protocol Crudable: ControllerProtocol {
at path: PathComponentsRepresentable...,
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod>,
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) throws -> Void)?
) throws where
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?
) where
ChildChildType: Content,
ChildType.Database == ThroughType.Database,
ChildChildType.ID: Parameter,
Expand All @@ -60,8 +60,8 @@ extension Crudable {
at path: PathComponentsRepresentable...,
parent relation: KeyPath<ChildType, Parent<ChildType, ParentType>>,
_ either: OnlyExceptEither<ParentRouterMethod> = .only([.read, .update]),
relationConfiguration: ((CrudParentController<ChildType, ParentType>) throws -> Void)?=nil
) throws where
relationConfiguration: ((CrudParentController<ChildType, ParentType>) -> Void)?=nil
) where
ParentType: Model & Content,
ChildType.Database == ParentType.Database,
ParentType.ID: Parameter {
Expand All @@ -81,17 +81,17 @@ extension Crudable {
controller = CrudParentController(relation: relation, path: fullPath, router: self.router, activeMethods: allMethods.subtracting(Set(methods)))
}

try controller.boot(router: self.router)
do { try controller.boot(router: self.router) } catch { fatalError("I have no reason to expect boot to throw") }

try relationConfiguration?(controller)
relationConfiguration?(controller)
}

public func crud<ChildChildType>(
at path: PathComponentsRepresentable...,
children relation: KeyPath<ChildType, Children<ChildType, ChildChildType>>,
_ either: OnlyExceptEither<ChildrenRouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) throws -> Void)?=nil
) throws where
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) -> Void)?=nil
) where
ChildChildType: Model & Content,
ChildType.Database == ChildChildType.Database,
ChildChildType.ID: Parameter {
Expand All @@ -110,17 +110,17 @@ extension Crudable {
controller = CrudChildrenController<ChildChildType, ChildType>(childrenRelation: relation, path: fullPath, router: self.router, activeMethods: allMethods.subtracting(Set(methods)))
}

try controller.boot(router: self.router)
do { try controller.boot(router: self.router) } catch { fatalError("I have no reason to expect boot to throw") }

try relationConfiguration?(controller)
relationConfiguration?(controller)
}

public func crud<ChildChildType, ThroughType>(
at path: PathComponentsRepresentable...,
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) throws -> Void)?=nil
) throws where
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?=nil
) where
ChildChildType: Content,
ChildType.Database == ThroughType.Database,
ChildChildType.ID: Parameter,
Expand All @@ -145,17 +145,17 @@ extension Crudable {
controller = CrudSiblingsController<ChildChildType, ChildType, ThroughType>(siblingRelation: relation, path: fullPath, router: self.router, activeMethods: allMethods.subtracting(Set(methods)))
}

try controller.boot(router: self.router)
do { try controller.boot(router: self.router) } catch { fatalError("I have no reason to expect boot to throw") }

try relationConfiguration?(controller)
relationConfiguration?(controller)
}

public func crud<ChildChildType, ThroughType>(
at path: PathComponentsRepresentable...,
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) throws -> Void)?=nil
) throws where
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?=nil
) where
ChildChildType: Content,
ChildType.Database == ThroughType.Database,
ChildChildType.ID: Parameter,
Expand All @@ -179,8 +179,8 @@ extension Crudable {
controller = CrudSiblingsController<ChildChildType, ChildType, ThroughType>(siblingRelation: relation, path: fullPath, router: self.router, activeMethods: allMethods.subtracting(Set(methods)))
}

try controller.boot(router: self.router)
do { try controller.boot(router: self.router) } catch { fatalError("I have no reason to expect boot to throw") }

try relationConfiguration?(controller)
relationConfiguration?(controller)
}
}
8 changes: 4 additions & 4 deletions Sources/CrudRouter/Extensions/Router+CRUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public extension Router {
_ path: PathComponentsRepresentable...,
register type: ModelType.Type,
_ either: OnlyExceptEither<RouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
relationConfiguration: ((CrudController<ModelType>) throws -> ())?=nil
) throws where ModelType.ID: Parameter {
relationConfiguration: ((CrudController<ModelType>) -> ())?=nil
) where ModelType.ID: Parameter {
let allMethods: Set<RouterMethod> = Set([.read, .readAll, .create, .update, .delete])
let controller: CrudController<ModelType>

Expand All @@ -18,8 +18,8 @@ public extension Router {
controller = CrudController<ModelType>(path: path, router: self, activeMethods: allMethods.subtracting(Set(methods)))
}

try controller.boot(router: self)
do { try controller.boot(router: self) } catch { fatalError("I have no reason to expect boot to throw") }

try relationConfiguration?(controller)
relationConfiguration?(controller)
}
}
18 changes: 9 additions & 9 deletions Tests/CrudRouterTests/CrudRouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ func configure(_ config: inout Config, _ env: inout Environment, _ services: ino
}

func routes(_ router: Router) throws {
try router.crud(register: Galaxy.self) { controller in
try controller.crud(children: \.planets)
router.crud(register: Galaxy.self) { controller in
controller.crud(children: \.planets)
}
try router.crud(register: Planet.self) { controller in
try controller.crud(parent: \.galaxy)
try controller.crud(siblings: \.tags)
router.crud(register: Planet.self) { controller in
controller.crud(parent: \.galaxy)
controller.crud(siblings: \.tags)
}
try router.crud(register: Tag.self) { controller in
try controller.crud(siblings: \.planets)
router.crud(register: Tag.self) { controller in
controller.crud(siblings: \.planets)
}
}

Expand Down Expand Up @@ -165,7 +165,7 @@ final class CrudRouterTests: XCTestCase {
func testBaseCrudRegistrationWithRouteName() throws {
let router = EngineRouter.default()

try router.crud("planets", register: Planet.self)
router.crud("planets", register: Planet.self)

XCTAssert(router.routes.isEmpty == false)
XCTAssert(router.routes.count == 5)
Expand All @@ -181,7 +181,7 @@ final class CrudRouterTests: XCTestCase {
func testBaseCrudRegistrationWithDefaultRoute() throws {
let router = EngineRouter.default()

try router.crud(register: Planet.self)
router.crud(register: Planet.self)

XCTAssert(router.routes.isEmpty == false)
XCTAssert(router.routes.count == 5)
Expand Down