mirror of
https://github.com/vapor/template-fluent-postgres.git
synced 2025-04-20 09:27:08 +08:00
Autogenerated from git://github.com/vapor/template.git@73d303c7595ab8a8f48ce0eed69deb24ac681149
This commit is contained in:
parent
81a886e0fe
commit
36cac2fc94
@ -17,7 +17,7 @@ WORKDIR /build
|
||||
# as long as your Package.swift/Package.resolved
|
||||
# files do not change.
|
||||
COPY ./Package.* ./
|
||||
RUN swift package resolve --skip-update \
|
||||
RUN swift package resolve \
|
||||
$([ -f ./Package.resolved ] && echo "--force-resolved-versions" || true)
|
||||
|
||||
# Copy entire repo into container
|
||||
|
@ -5,17 +5,19 @@ struct TodoController: RouteCollection {
|
||||
func boot(routes: RoutesBuilder) throws {
|
||||
let todos = routes.grouped("todos")
|
||||
|
||||
todos.get(use: { try await self.index(req: $0) })
|
||||
todos.post(use: { try await self.create(req: $0) })
|
||||
todos.get(use: self.index)
|
||||
todos.post(use: self.create)
|
||||
todos.group(":todoID") { todo in
|
||||
todo.delete(use: { try await self.delete(req: $0) })
|
||||
todo.delete(use: self.delete)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Sendable
|
||||
func index(req: Request) async throws -> [TodoDTO] {
|
||||
try await Todo.query(on: req.db).all().map { $0.toDTO() }
|
||||
}
|
||||
|
||||
@Sendable
|
||||
func create(req: Request) async throws -> TodoDTO {
|
||||
let todo = try req.content.decode(TodoDTO.self).toModel()
|
||||
|
||||
@ -23,6 +25,7 @@ struct TodoController: RouteCollection {
|
||||
return todo.toDTO()
|
||||
}
|
||||
|
||||
@Sendable
|
||||
func delete(req: Request) async throws -> HTTPStatus {
|
||||
guard let todo = try await Todo.find(req.parameters.get("todoID"), on: req.db) else {
|
||||
throw Abort(.notFound)
|
||||
|
Loading…
x
Reference in New Issue
Block a user