Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.
Open
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,24 @@ First make sure that you've imported Submissions everywhere it's needed:
import Submissions
```

### Adding the Provider
### Adding the Provider and Middleware

"Submissions" comes with a light-weight provider that we'll need to register in the `configure` function in our `configure.swift` file:

```swift
try services.register(SubmissionsProvider())
```

It also includes a middleware you have to register in your `MiddlewareConfig` (needs to come after `ErrorMiddleware` if present, to avoid the `SubmissionValidationError`s from being transformed into Internal Server errors on the way back up the responder chain)

```swift
config.use(SubmissionsMiddleware.self)
```


This makes sure that fields and errors can be stored on the request using a `FieldCache` service.


## Validating API requests

_TODO_
Expand Down
7 changes: 6 additions & 1 deletion Sources/Submissions/SubmissionsMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import Vapor
/// Note: needs to come after `ErrorMiddleware` (if present) to avoid the
/// `SubmissionValidationError`s from being transformed into Internal Server errors on the way back
/// up the responder chain.
public final class SubmissionsMiddleware: Middleware {
public final class SubmissionsMiddleware: Middleware, ServiceType {

/// See `ServiceType`.
public static func makeService(for container: Container) throws -> SubmissionsMiddleware {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are tabs, please use spaces 🙂 (in the whole function)

return SubmissionsMiddleware()
}

/// Create a new `SubmissionsMiddleware`.
public init() {}

Expand Down
1 change: 1 addition & 0 deletions Sources/Submissions/SubmissionsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public final class SubmissionsProvider: Provider {

/// See `Provider`
public func register(_ services: inout Services) throws {
services.register(SubmissionsMiddleware.self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more tabs that should be spaces 🙂

services.register { _ in FieldCache() }
}

Expand Down