From 18b945a0be83f51044e6abd7807b37a65a9f170f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=20Mohamad=20=E2=8C=98?= Date: Thu, 14 Sep 2023 13:24:01 +0200 Subject: [PATCH] Update Spanish translation doc 877 (#902) Update Spanish translation doc for pr https://github.com/vapor/docs/pull/877 Translation needed in issue https://github.com/vapor/docs/issues/878 @jacostaf10 --- docs/basics/controllers.es.md | 43 +++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/docs/basics/controllers.es.md b/docs/basics/controllers.es.md index b36d39e5..734e99b5 100644 --- a/docs/basics/controllers.es.md +++ b/docs/basics/controllers.es.md @@ -24,41 +24,44 @@ struct TodosController: RouteCollection { } } - func index(req: Request) async throws -> String { - // ... + func index(req: Request) async throws -> [Todo] { + try await Todo.query(on: req.db).all() } - func create(req: Request) throws -> EventLoopFuture { - // ... + func create(req: Request) async throws -> Todo { + let todo = try req.content.decode(Todo.self) + try await todo.save(on: req.db) + return todo } - func show(req: Request) throws -> String { - guard let id = req.parameters.get("id") else { - throw Abort(.internalServerError) + func show(req: Request) async throws -> Todo { + guard let todo = try await Todo.find(req.parameters.get("id"), on: req.db) else { + throw Abort(.notFound) } - // ... + return todo } - func update(req: Request) throws -> String { - guard let id = req.parameters.get("id") else { - throw Abort(.internalServerError) + func update(req: Request) async throws -> Todo { + guard let todo = try await Todo.find(req.parameters.get("id"), on: req.db) else { + throw Abort(.notFound) } - // ... + let updatedTodo = try req.content.decode(Todo.self) + todo.title = updatedTodo.title + try await todo.save(on: req.db) + return todo } - func delete(req: Request) throws -> String { - guard let id = req.parameters.get("id") else { - throw Abort(.internalServerError) + func delete(req: Request) async throws -> HTTPStatus { + guard let todo = try await Todo.find(req.parameters.get("id"), on: req.db) { + throw Abort(.notFound) } - // ... + try await todo.delete(on: req.db) + return .ok } } ``` -Los métodos de un controlador deben aceptar siempre una `Request` (petición) y devolver algo `ResponseEncodable`. Este método puede ser síncrono o asíncrono (o devolver un `EventLoopFuture`). - -!!! note "Nota" - Un [EventLoopFuture](async.md) cuya expectativa es `ResponseEncodable` (por ejemplo, `EventLoopFuture`) es también `ResponseEncodable`. +Los métodos de un controlador deben aceptar siempre una `Request` (petición) y devolver algo `ResponseEncodable`. Este método puede ser síncrono o asíncrono. Finalmente necesitas registrar el controlador en `routes.swift`: