Skip to content

Commit

Permalink
Endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Parra committed Sep 15, 2023
1 parent 228d103 commit 44a4659
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 396 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ lazy val root = (project in file("."))
"com.typesafe.akka" %% "akka-http" % "10.2.4", // Para Akka HTTP
"com.typesafe.akka" %% "akka-http-spray-json" % "10.2.4", // Para manejo de JSON
"com.typesafe.akka" %% "akka-stream" % "2.6.14", // Para manejo de streams
"de.heikoseeberger" %% "akka-http-circe" % "1.37.0"
"de.heikoseeberger" %% "akka-http-circe" % "1.37.0",
)
)
32 changes: 32 additions & 0 deletions src/main/scala/example/DatabaseConfig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package example

import java.sql.Connection
import java.sql.DriverManager
import com.typesafe.config.ConfigFactory


import scalikejdbc.{ConnectionPool}

object DatabaseConfig {

val config = ConfigFactory.load()
val dbMasterUrl = config.getString("db.urlMaestro")
val dbSlaveUrl = config.getString("db.urlEsclavo")
val dbUser = config.getString("db.user")
val dbPassword = config.getString("db.password")

// Método para verificar si el maestro está disponible
def pingMaestro(): Boolean = {
try {
// Intenta establecer una conexión al maestro
ConnectionPool.singleton(dbMasterUrl, dbUser, dbPassword)
true
} catch {
case _: Exception => false


}
}


}
24 changes: 0 additions & 24 deletions src/main/scala/example/DatabaseConnectionManager.scala

This file was deleted.

296 changes: 0 additions & 296 deletions src/main/scala/example/DatabaseQueries.scala

This file was deleted.

28 changes: 27 additions & 1 deletion src/main/scala/example/controllers/DirectoryController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ class DirectoryController {
Left("Error interno del servidor")
}
}
}
}

def guardarSubDirectorio(nombre: String, rutaPadre: String, usuario_id: Int): Future[Either[String, DirectoryModel]] = {
Future {
try {
val nuevaRuta = s"$rutaPadre/$nombre"

val result = sql"INSERT INTO directorios (nombre, ruta, usuario_id) VALUES ($nombre, $nuevaRuta, $usuario_id)"
.update()

if (result > 0) {
// Recupera el ID generado por la base de datos
val generatedId: Long = sql"SELECT LAST_INSERT_ID()".map(rs => rs.long(1)).single().getOrElse(0L)

// Crea una instancia de DirectoryModel con el ID real
val directorio = DirectoryModel(generatedId.toInt, nombre, nuevaRuta, usuario_id)
Right(directorio)
} else {
Left("No se pudo agregar el sub directorio")
}
} catch {
case e: Exception =>
println(s"Error interno del servidor: ${e.getMessage}")
Left("Error interno del servidor")
}
}
}

}
Loading

0 comments on commit 44a4659

Please sign in to comment.