Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #54 from nodes-vapor/feature/request-makeable
Browse files Browse the repository at this point in the history
Replace requestinitializable with -makeable
  • Loading branch information
siemensikkema authored Jun 3, 2020
2 parents e7d478c + 3888849 commit dc034dc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Submissions 📩
[![Swift Version](https://img.shields.io/badge/Swift-4.2-brightgreen.svg)](http://swift.org)
[![Vapor Version](https://img.shields.io/badge/Vapor-3.1-30B6FC.svg)](http://vapor.codes)
[![CircleCI](https://circleci.com/gh/nodes-vapor/submissions/tree/master.svg?style=svg)](https://circleci.com/gh/nodes-vapor/submissions/tree/master)
[![codebeat badge](https://codebeat.co/badges/b9c894d6-8c6a-4a07-bfd5-29db898c8dfe)](https://codebeat.co/projects/github.aaakk.us.kg-nodes-vapor-submissions-master)
[![Swift Version](https://img.shields.io/badge/Swift-5.2-brightgreen.svg)](http://swift.org)
[![Vapor Version](https://img.shields.io/badge/Vapor-4.0-30B6FC.svg)](http://vapor.codes)
[![![codebeat badge](https://codebeat.co/badges/b9c894d6-8c6a-4a07-bfd5-29db898c8dfe)](https://codebeat.co/projects/github.aaakk.us.kg-nodes-vapor-submissions-master)
[![codecov](https://codecov.io/gh/nodes-vapor/submissions/branch/master/graph/badge.svg)](https://codecov.io/gh/nodes-vapor/submissions)
[![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=https://github.com/nodes-vapor/submissions)](http://clayallsopp.github.io/readme-score?url=https://github.com/nodes-vapor/submissions)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nodes-vapor/reset/master/LICENSE)
Expand All @@ -15,7 +14,7 @@ Add `Submissions` to the Package dependencies:
```swift
dependencies: [
...,
.package(url: "https://github.com/nodes-vapor/submissions.git", from: "2.0.0")
.package(url: "https://github.com/nodes-vapor/submissions.git", from: "3.0.0")
]
```

Expand Down
11 changes: 0 additions & 11 deletions Sources/Submissions/RequestInitializable.swift

This file was deleted.

15 changes: 15 additions & 0 deletions Sources/Submissions/RequestMakeable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Vapor

public protocol RequestMakeable {
static func make(from request: Request) -> EventLoopFuture<Self>
}

public extension RequestMakeable where Self: Decodable {
static func make(from request: Request) -> EventLoopFuture<Self> {
do {
return request.eventLoop.future(try request.content.decode(Self.self))
} catch {
return request.eventLoop.future(error: error)
}
}
}
5 changes: 3 additions & 2 deletions Sources/Submissions/ValidatableRequest.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vapor

public protocol ValidatableRequest: RequestInitializable {
public protocol ValidatableRequest: RequestMakeable {
static func validations(on request: Request) -> EventLoopFuture<Validations>
}

Expand All @@ -20,7 +20,8 @@ public extension ValidatableRequest {
static func validated(on request: Request) -> EventLoopFuture<Self> {
validations(on: request).flatMapThrowing { validations in
try validations.validate(request).assert()
return try Self(request: request)
}.flatMap {
make(from: request)
}
}
}

0 comments on commit dc034dc

Please sign in to comment.