This commit is contained in:
Michael Simard
2020-05-25 23:32:28 -05:00
parent ba9bfd5e6a
commit 676a55d2df
4 changed files with 27 additions and 22 deletions

View File

@@ -3,10 +3,10 @@ import Vapor
struct TodoController: RouteCollection { struct TodoController: RouteCollection {
func boot(routes: RoutesBuilder) throws { func boot(routes: RoutesBuilder) throws {
let todos = routes.grouped("todos") let todos = routes.grouped("match")
todos.get(use: index) todos.get(use: index)
todos.post(use: create) todos.post(use: create)
todos.group(":todoID") { todo in todos.group(":matchID") { todo in
todo.delete(use: delete) todo.delete(use: delete)
} }
} }
@@ -21,7 +21,7 @@ struct TodoController: RouteCollection {
} }
func delete(req: Request) throws -> EventLoopFuture<HTTPStatus> { 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)) .unwrap(or: Abort(.notFound))
.flatMap { $0.delete(on: req.db) } .flatMap { $0.delete(on: req.db) }
.transform(to: .ok) .transform(to: .ok)

View 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()
}
}

View File

@@ -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()
}
}

View File

@@ -9,12 +9,12 @@ public func configure(_ app: Application) throws {
app.databases.use(.postgres( app.databases.use(.postgres(
hostname: Environment.get("DATABASE_HOST") ?? "localhost", hostname: Environment.get("DATABASE_HOST") ?? "localhost",
username: Environment.get("DATABASE_USERNAME") ?? "vapor_username", username: Environment.get("DATABASE_USERNAME") ?? "fanosphere",
password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password", password: Environment.get("DATABASE_PASSWORD") ?? "pw4fanosphere",
database: Environment.get("DATABASE_NAME") ?? "vapor_database" database: Environment.get("DATABASE_NAME") ?? "codmw"
), as: .psql) ), as: .psql)
app.migrations.add(CreateTodo()) app.migrations.add(CreateMatch())
// register routes // register routes
try routes(app) try routes(app)