Add projectsDirectory parameter to project endpoint (#10481)

This change adds a possibility to pass an optional parameter describing full path to projects' directory, in addition to the required project id.

Enables GUI to fix #10453.
This commit is contained in:
Hubert Plociniczak 2024-07-11 12:18:43 +02:00 committed by GitHub
parent 077b86f98c
commit 0ab9fe7875
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 13 deletions

View File

@ -17,9 +17,11 @@ JSONRPC protocol.
<!-- /MarkdownTOC -->
## `/projects/{project_id}/enso-project`
## `/projects/{project_id}/enso-project?projectsDirectory={projects_path}`
HTTP endpoint that returns the project structure in `.enso-project` format.
HTTP endpoint that returns the project structure in `.enso-project` format. The
optional `projectsDirectory` parameter allows the user to specify a custom path
to projects' directory (e.g. if it is in a subfolder).
### `GET`

View File

@ -19,8 +19,8 @@ import org.enso.projectmanager.infrastructure.repository.{
ProjectRepositoryFailure
}
import java.io.File
import java.util.UUID
import scala.concurrent.Future
import scala.util.{Failure, Success}
@ -30,23 +30,25 @@ final class ProjectsEndpoint[
extends Endpoint
with LazyLogging {
private val projectRepository =
projectRepositoryFactory.getProjectRepository(None)
/** @inheritdoc */
override def route: Route =
projectsEndpoint
private val projectsEndpoint = {
path("projects" / JavaUUID / "enso-project") { projectId =>
get {
getEnsoProject(projectId)
parameters("projectsDirectory".optional) { directory =>
get {
getEnsoProject(projectId, directory)
}
}
}
}
private def getEnsoProject(projectId: UUID): Route = {
onComplete(buildEnsoArchive(projectId)) {
private def getEnsoProject(
projectId: UUID,
directory: Option[String]
): Route =
onComplete(buildEnsoArchive(projectId, directory)) {
case Failure(err) =>
logger.error(
"Failure when building an enso-project archive [{}].",
@ -71,13 +73,14 @@ final class ProjectsEndpoint[
)
)
}
}
private def buildEnsoArchive(
projectId: UUID
projectId: UUID,
projectsDirectory: Option[String]
): Future[Either[ProjectRepositoryFailure, Option[EnsoProjectArchive]]] =
Exec[F].exec {
projectRepository
projectRepositoryFactory
.getProjectRepository(projectsDirectory.map(new File(_)))
.findById(projectId)
.map(projectOpt =>
projectOpt.map(project =>

View File

@ -6,4 +6,5 @@ trait ProjectRepositoryFactory[F[+_, +_]] {
def getProjectRepository(
projectsDirectory: Option[File]
): ProjectRepository[F]
}