Skip to content

Commit

Permalink
Add projectsDirectory parameter to project endpoint (#10481)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hubertp authored Jul 11, 2024
1 parent 077b86f commit 0ab9fe7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
6 changes: 4 additions & 2 deletions docs/language-server/project-manager-http-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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 [{}].",
Expand All @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ class ProjectFileRepositoryFactory[
gen
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ trait ProjectRepositoryFactory[F[+_, +_]] {
def getProjectRepository(
projectsDirectory: Option[File]
): ProjectRepository[F]

}

0 comments on commit 0ab9fe7

Please sign in to comment.