mirror of
https://github.com/enso-org/enso.git
synced 2024-11-26 08:52:58 +03:00
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:
parent
077b86f98c
commit
0ab9fe7875
@ -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`
|
||||
|
||||
|
@ -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 =>
|
||||
|
@ -31,4 +31,5 @@ class ProjectFileRepositoryFactory[
|
||||
gen
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,4 +6,5 @@ trait ProjectRepositoryFactory[F[+_, +_]] {
|
||||
def getProjectRepository(
|
||||
projectsDirectory: Option[File]
|
||||
): ProjectRepository[F]
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user