Skip to content

Commit 4ab2e10

Browse files
committed
feat(model-server): provide content explorer for latest version
1 parent 9b426a4 commit 4ab2e10

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

model-server-openapi/specifications/model-server-html.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ paths:
3737
examples:
3838
Example#1:
3939
value: "../repos/"
40+
/content/{repository}/{branch}/latest:
41+
get:
42+
operationId: getContentRepositoryBranchLatest
43+
parameters:
44+
- name: repository
45+
in: "path"
46+
required: true
47+
schema:
48+
type: string
49+
- name: branch
50+
in: "path"
51+
required: true
52+
schema:
53+
type: string
54+
responses:
55+
"200":
56+
$ref: '#/components/responses/200'
4057
/content/{versionHash}:
4158
get:
4259
operationId: getVersionHash

model-server/src/main/kotlin/org/modelix/model/server/handlers/ContentExplorer.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ import org.modelix.model.api.ITree
4343
import org.modelix.model.api.PNodeAdapter
4444
import org.modelix.model.api.TreePointer
4545
import org.modelix.model.client.IModelClient
46+
import org.modelix.model.lazy.BranchReference
4647
import org.modelix.model.lazy.CLVersion
48+
import org.modelix.model.lazy.RepositoryId
4749
import org.modelix.model.server.templates.PageWithMenuBar
4850
import kotlin.collections.set
4951

@@ -54,6 +56,26 @@ class ContentExplorer(private val client: IModelClient, private val repoManager:
5456
get<Paths.getContent> {
5557
call.respondRedirect("../repos/")
5658
}
59+
get<Paths.getContentRepositoryBranchLatest> {
60+
val repository = call.parameters["repository"]
61+
val branch = call.parameters["branch"]
62+
if (repository.isNullOrEmpty()) {
63+
call.respondText("repository not found", status = HttpStatusCode.BadRequest)
64+
return@get
65+
}
66+
if (branch.isNullOrEmpty()) {
67+
call.respondText("branch not found", status = HttpStatusCode.BadRequest)
68+
return@get
69+
}
70+
71+
val latestVersion = repoManager.getVersion(BranchReference(RepositoryId(repository), branch))
72+
if (latestVersion == null) {
73+
call.respondText("unable to find latest version", status = HttpStatusCode.InternalServerError)
74+
return@get
75+
} else {
76+
call.respondRedirect("../../../${latestVersion.getContentHash()}/")
77+
}
78+
}
5779
get<Paths.getVersionHash> {
5880
val versionHash = call.parameters["versionHash"]
5981
if (versionHash.isNullOrEmpty()) {

model-server/src/main/kotlin/org/modelix/model/server/handlers/RepositoryOverview.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ class RepositoryOverview(private val repoManager: RepositoriesManager) {
8383
buildHistoryLink(branch.repositoryId.id, branch.branchName)
8484
}
8585
td {
86-
val latestVersion = repoManager.getVersion(branch)
87-
?: throw RuntimeException("Branch not found: $branch")
88-
a("../content/${latestVersion.getContentHash()}/") {
86+
a("../content/$repository/${branch.branchName}/latest/") {
8987
+"Explore Latest Version"
9088
}
9189
}

0 commit comments

Comments
 (0)