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 4 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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,23 @@ 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 include a middleware you have to register in your `MiddlewareConfig` :
Copy link
Contributor

Choose a reason for hiding this comment

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

*includes


```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`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use spaces here instead of tabs :)

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