init
This commit is contained in:
@@ -3,10 +3,10 @@ import Vapor
|
||||
|
||||
struct TodoController: RouteCollection {
|
||||
func boot(routes: RoutesBuilder) throws {
|
||||
let todos = routes.grouped("todos")
|
||||
let todos = routes.grouped("match")
|
||||
todos.get(use: index)
|
||||
todos.post(use: create)
|
||||
todos.group(":todoID") { todo in
|
||||
todos.group(":matchID") { todo in
|
||||
todo.delete(use: delete)
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ struct TodoController: RouteCollection {
|
||||
}
|
||||
|
||||
func delete(req: Request) throws -> EventLoopFuture<HTTPStatus> {
|
||||
return Todo.find(req.parameters.get("todoID"), on: req.db)
|
||||
return Todo.find(req.parameters.get("matchID"), on: req.db)
|
||||
.unwrap(or: Abort(.notFound))
|
||||
.flatMap { $0.delete(on: req.db) }
|
||||
.transform(to: .ok)
|
||||
|
||||
19
Sources/App/Migrations/CreateMatch.swift
Normal file
19
Sources/App/Migrations/CreateMatch.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
import Fluent
|
||||
|
||||
struct CreateMatch: Migration {
|
||||
func prepare(on database: Database) -> EventLoopFuture<Void> {
|
||||
return database.schema("match")
|
||||
.id()
|
||||
.field("map", .string)
|
||||
.field("win", .bool)
|
||||
.field("date", .bool)
|
||||
.field("roundsWon", .int)
|
||||
.field("roundsLost", .int)
|
||||
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: Database) -> EventLoopFuture<Void> {
|
||||
return database.schema("matches").delete()
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import Fluent
|
||||
|
||||
struct CreateTodo: Migration {
|
||||
func prepare(on database: Database) -> EventLoopFuture<Void> {
|
||||
return database.schema("todos")
|
||||
.id()
|
||||
.field("title", .string, .required)
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: Database) -> EventLoopFuture<Void> {
|
||||
return database.schema("todos").delete()
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,12 @@ public func configure(_ app: Application) throws {
|
||||
|
||||
app.databases.use(.postgres(
|
||||
hostname: Environment.get("DATABASE_HOST") ?? "localhost",
|
||||
username: Environment.get("DATABASE_USERNAME") ?? "vapor_username",
|
||||
password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
|
||||
database: Environment.get("DATABASE_NAME") ?? "vapor_database"
|
||||
username: Environment.get("DATABASE_USERNAME") ?? "fanosphere",
|
||||
password: Environment.get("DATABASE_PASSWORD") ?? "pw4fanosphere",
|
||||
database: Environment.get("DATABASE_NAME") ?? "codmw"
|
||||
), as: .psql)
|
||||
|
||||
app.migrations.add(CreateTodo())
|
||||
app.migrations.add(CreateMatch())
|
||||
|
||||
// register routes
|
||||
try routes(app)
|
||||
|
||||
Reference in New Issue
Block a user