Skip to content

Commit

Permalink
Mover archivo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Parra committed Oct 27, 2023
1 parent 38fbe03 commit e0407c8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/main/scala/example/controllers/FileController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ class FileController {
}
}

def moverArchivo(id: Int, nuevaRuta: String): Future[Either[String, FileModel]] = {
def moverArchivo(id: Int, nuevaRuta: String, directorio_id: Int): Future[Either[String, FileModel]] = {
Future {
try {
// Realizar la actualización en la base de datos
val resultado = sql"UPDATE archivos SET ruta = $nuevaRuta WHERE id = $id".update()
val resultado =
sql"UPDATE archivos SET ruta = $nuevaRuta, directorio_id= $directorio_id WHERE id = $id".update()

if (resultado > 0) {
// La actualización fue exitosa, llamar a buscarArchivo para obtener el archivo actualizado
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/example/models/FileAllModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ case class FileModel(

case class FileReportModel(usuario_id: Int, tamano: Double)

case class FileMoveModel(id: Int, nuevaRuta: String)
case class FileMoveModel(id: Int, nuevaRuta: String, directorio_id: Int)

case class FileCreateModel(
nombre: String,
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/example/routes/FileRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class FileRoute(fileController: FileController) {
path("move") {
put {
entity(as[FileMoveModel]) { file =>
val result: Future[Either[String, FileModel]] = fileController.moverArchivo(file.id, file.nuevaRuta)
val result: Future[Either[String, FileModel]] =
fileController.moverArchivo(file.id, file.nuevaRuta, file.directorio_id)
onSuccess(result) {
case Right(newFile) => complete(StatusCodes.Created, newFile)
case Left(errorMessage) => complete(HttpResponse(StatusCodes.InternalServerError, entity = errorMessage))
Expand Down

0 comments on commit e0407c8

Please sign in to comment.