-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'created smoke-signals-postgresql from template https://github.com/va…
- Loading branch information
Shaun Hubbard
committed
Apr 1, 2018
0 parents
commit af49aa7
Showing
21 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# Created by https://www.gitignore.io/api/vapor | ||
|
||
### Vapor ### | ||
Config/secrets | ||
|
||
### Vapor Patch ### | ||
Packages | ||
.build | ||
xcuserdata | ||
*.xcodeproj | ||
DerivedData/ | ||
.DS_Store | ||
|
||
# End of https://www.gitignore.io/api/vapor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
included: | ||
- Sources | ||
- Tests | ||
|
||
nesting: | ||
type_level: 2 | ||
|
||
opt_in_rules: | ||
- closure_end_indentation | ||
- literal_expression_end_indentation | ||
|
||
identifier_name: | ||
excluded: | ||
- id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "Console", | ||
"repositoryURL": "https://github.com/vapor/console.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "273cf2ed1f4daba88a452494c342020171d8c7b8", | ||
"version": "3.0.0-rc.2.2" | ||
} | ||
}, | ||
{ | ||
"package": "Core", | ||
"repositoryURL": "https://github.com/vapor/core.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "6d3da8dc3f84cb082f0c587948edc038fcc13255", | ||
"version": "3.0.0-rc.2.4" | ||
} | ||
}, | ||
{ | ||
"package": "Crypto", | ||
"repositoryURL": "https://github.com/vapor/crypto.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "4c7acb4fbf1720682275f0ef543474c951d84a09", | ||
"version": "3.0.0-rc.3" | ||
} | ||
}, | ||
{ | ||
"package": "DatabaseKit", | ||
"repositoryURL": "https://github.com/vapor/database-kit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "ce82abe73051388dcadbf34873b29a75df58cabc", | ||
"version": "1.0.0-rc.2.1.1" | ||
} | ||
}, | ||
{ | ||
"package": "Engine", | ||
"repositoryURL": "https://github.com/vapor/engine.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "cd6756a971caba5f14a861b446fe682a15d2ae28", | ||
"version": "3.0.0-rc.2.1" | ||
} | ||
}, | ||
{ | ||
"package": "Fluent", | ||
"repositoryURL": "https://github.com/vapor/fluent.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "55c0a9698ef7aa2b08d5f3063ed7511eb223a402", | ||
"version": "3.0.0-rc.2.3" | ||
} | ||
}, | ||
{ | ||
"package": "FluentSQLite", | ||
"repositoryURL": "https://github.com/vapor/fluent-sqlite.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "218d7af5201ee769a5479fbae32a4a1ca4f25c8e", | ||
"version": "3.0.0-rc.2" | ||
} | ||
}, | ||
{ | ||
"package": "Routing", | ||
"repositoryURL": "https://github.com/vapor/routing.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "2fc1d4de22a54848b35ad17b3e7f7816f19ebf90", | ||
"version": "3.0.0-rc.2" | ||
} | ||
}, | ||
{ | ||
"package": "Service", | ||
"repositoryURL": "https://github.com/vapor/service.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "02205a16a3f4714a08836529f5a868c2ce256719", | ||
"version": "1.0.0-rc.2.2" | ||
} | ||
}, | ||
{ | ||
"package": "SQLite", | ||
"repositoryURL": "https://github.com/vapor/sqlite.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "f25c4b44c98c7de5e25e6ec32dbb1d9cb7a68d3d", | ||
"version": "3.0.0-rc.2.1.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio", | ||
"repositoryURL": "https://github.com/apple/swift-nio.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "a0b7f646fba61402da384b3202f54c27debb5e13", | ||
"version": "1.3.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-ssl", | ||
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "ea006b6368dbd9dbfd297deb6ddb3f070b72d043", | ||
"version": "1.0.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-ssl-support", | ||
"repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "c02eec4e0e6d351cd092938cf44195a8e669f555", | ||
"version": "1.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-zlib-support", | ||
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd", | ||
"version": "1.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "TemplateKit", | ||
"repositoryURL": "https://github.com/vapor/template-kit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "61ed3d3b0df4c181d6b88e06b418f425978ac2af", | ||
"version": "1.0.0-rc.2.0.3" | ||
} | ||
}, | ||
{ | ||
"package": "Validation", | ||
"repositoryURL": "https://github.com/vapor/validation.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "1ce87fc2d18a8f15a491805825063c8db493a51e", | ||
"version": "2.0.0-rc.2.1.1" | ||
} | ||
}, | ||
{ | ||
"package": "Vapor", | ||
"repositoryURL": "https://github.com/vapor/vapor.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "5e59691ef575597aa640da76ccb9fc5ee638f2c1", | ||
"version": "3.0.0-rc.2.2.1" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// swift-tools-version:4.0 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "smoke-signals-postgresql", | ||
dependencies: [ | ||
// 💧 A server-side Swift web framework. | ||
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc.2"), | ||
|
||
// 🔵 Swift ORM (queries, models, relations, etc) built on SQLite 3. | ||
.package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0-rc.2") | ||
], | ||
targets: [ | ||
.target(name: "App", dependencies: ["FluentSQLite", "Vapor"]), | ||
.target(name: "Run", dependencies: ["App"]), | ||
.testTarget(name: "AppTests", dependencies: ["App"]) | ||
] | ||
) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<p align="center"> | ||
<img src="https://user-images.githubusercontent.com/1342803/36623515-7293b4ec-18d3-11e8-85ab-4e2f8fb38fbd.png" width="320" alt="API Template"> | ||
<br> | ||
<br> | ||
<a href="http://docs.vapor.codes/3.0/"> | ||
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation"> | ||
</a> | ||
<a href="http://vapor.team"> | ||
<img src="http://vapor.team/badge.svg" alt="Slack Team"> | ||
</a> | ||
<a href="LICENSE"> | ||
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License"> | ||
</a> | ||
<a href="https://circleci.com/gh/vapor/api-template"> | ||
<img src="https://circleci.com/gh/vapor/api-template.svg?style=shield" alt="Continuous Integration"> | ||
</a> | ||
<a href="https://swift.org"> | ||
<img src="http://img.shields.io/badge/swift-4.1-brightgreen.svg" alt="Swift 4.1"> | ||
</a> | ||
</center> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Vapor | ||
|
||
/// Controlers basic CRUD operations on `Todo`s. | ||
final class TodoController { | ||
/// Returns a list of all `Todo`s. | ||
func index(_ req: Request) throws -> Future<[Todo]> { | ||
return Todo.query(on: req).all() | ||
} | ||
|
||
/// Saves a decoded `Todo` to the database. | ||
func create(_ req: Request) throws -> Future<Todo> { | ||
return try req.content.decode(Todo.self).flatMap(to: Todo.self) { todo in | ||
return todo.save(on: req) | ||
} | ||
} | ||
|
||
/// Deletes a parameterized `Todo`. | ||
func delete(_ req: Request) throws -> Future<HTTPStatus> { | ||
return try req.parameter(Todo.self).flatMap(to: Void.self) { todo in | ||
return todo.delete(on: req) | ||
}.transform(to: .ok) | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import FluentSQLite | ||
import Vapor | ||
|
||
/// A single entry of a Todo list. | ||
final class Todo: SQLiteModel { | ||
/// The unique identifier for this `Todo`. | ||
var id: Int? | ||
|
||
/// A title describing what this `Todo` entails. | ||
var title: String | ||
|
||
/// Creates a new `Todo`. | ||
init(id: Int? = nil, title: String) { | ||
self.id = id | ||
self.title = title | ||
} | ||
} | ||
|
||
/// Allows `Todo` to be used as a dynamic migration. | ||
extension Todo: Migration { } | ||
|
||
/// Allows `Todo` to be encoded to and decoded from HTTP messages. | ||
extension Todo: Content { } | ||
|
||
/// Allows `Todo` to be used as a dynamic parameter in route definitions. | ||
extension Todo: Parameter { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Routing | ||
import Vapor | ||
|
||
/// Called after your application has initialized. | ||
/// | ||
/// [Learn More →](https://docs.vapor.codes/3.0/getting-started/structure/#bootswift) | ||
public func boot(_ app: Application) throws { | ||
// your code here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import FluentSQLite | ||
import Vapor | ||
|
||
/// Called before your application initializes. | ||
/// | ||
/// https://docs.vapor.codes/3.0/getting-started/structure/#configureswift | ||
public func configure( | ||
_ config: inout Config, | ||
_ env: inout Environment, | ||
_ services: inout Services | ||
) throws { | ||
/// Register providers first | ||
try services.register(FluentSQLiteProvider()) | ||
|
||
/// Register routes to the router | ||
let router = EngineRouter.default() | ||
try routes(router) | ||
services.register(router, as: Router.self) | ||
|
||
/// Register middleware | ||
var middlewares = MiddlewareConfig() // Create _empty_ middleware config | ||
/// middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory | ||
middlewares.use(DateMiddleware.self) // Adds `Date` header to responses | ||
middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response | ||
services.register(middlewares) | ||
|
||
// Configure a SQLite database | ||
let sqlite: SQLiteDatabase | ||
if env.isRelease { | ||
/// Create file-based SQLite db using $SQLITE_PATH from process env | ||
sqlite = try SQLiteDatabase(storage: .file(path: Environment.get("SQLITE_PATH")!)) | ||
} else { | ||
/// Create an in-memory SQLite database | ||
sqlite = try SQLiteDatabase(storage: .memory) | ||
} | ||
|
||
/// Register the configured SQLite database to the database config. | ||
var databases = DatabaseConfig() | ||
databases.add(database: sqlite, as: .sqlite) | ||
services.register(databases) | ||
|
||
/// Configure migrations | ||
var migrations = MigrationConfig() | ||
migrations.add(model: Todo.self, database: .sqlite) | ||
services.register(migrations) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Routing | ||
import Vapor | ||
|
||
/// Register your application's routes here. | ||
/// | ||
/// [Learn More →](https://docs.vapor.codes/3.0/getting-started/structure/#routesswift) | ||
public func routes(_ router: Router) throws { | ||
// Basic "Hello, world!" example | ||
router.get("hello") { req in | ||
return "Hello, world!" | ||
} | ||
|
||
// Example of creating a Service and using it. | ||
router.get("hash", String.parameter) { req -> String in | ||
// Create a BCryptHasher using the Request's Container | ||
let hasher = try req.make(BCryptHasher.self) | ||
|
||
// Fetch the String parameter (as described in the route) | ||
let string = try req.parameter(String.self) | ||
|
||
// Return the hashed string! | ||
return try hasher.make(string) | ||
} | ||
|
||
// Example of configuring a controller | ||
let todoController = TodoController() | ||
router.get("todos", use: todoController.index) | ||
router.post("todos", use: todoController.create) | ||
router.delete("todos", Todo.parameter, use: todoController.delete) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import App | ||
import Service | ||
import Vapor | ||
import Foundation | ||
|
||
// The contents of main are wrapped in a do/catch block because any errors that get raised to the top level will crash Xcode | ||
do { | ||
var config = Config.default() | ||
var env = try Environment.detect() | ||
var services = Services.default() | ||
|
||
try App.configure(&config, &env, &services) | ||
|
||
let app = try Application( | ||
config: config, | ||
environment: env, | ||
services: services | ||
) | ||
|
||
try App.boot(app) | ||
|
||
try app.run() | ||
} catch { | ||
print(error) | ||
exit(1) | ||
} |
Empty file.
Oops, something went wrong.