Skip to content

Commit 81d8615

Browse files
committed
fix(model-server): return HTTP 204 if repo was deleted and 404 if repo was not found
1 parent 1033e0f commit 81d8615

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

api/model-server.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ paths:
324324
schema:
325325
type: string
326326
responses:
327-
"200":
328-
$ref: '#/components/responses/200'
327+
"204":
328+
$ref: '#/components/responses/204'
329+
"404":
330+
$ref: '#/components/responses/404'
329331
/v2/repositories/{repository}/versions/{versionHash}:
330332
get:
331333
operationId: getRepositoryVersionHash

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class ModelClientV2(
146146
takeFrom(baseUrl)
147147
appendPathSegmentsEncodingSlash("repositories", repository.id, "delete")
148148
}
149-
}.status == HttpStatusCode.OK
149+
}.status == HttpStatusCode.NoContent
150150
}
151151

152152
override suspend fun listBranches(repository: RepositoryId): List<BranchReference> {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,13 @@ class ModelReplicationServer(val repositoriesManager: RepositoriesManager) {
169169
fun ApplicationCall.repositoryId() = RepositoryId(parameters["repository"]!!)
170170
fun PipelineContext<Unit, ApplicationCall>.repositoryId() = call.repositoryId()
171171

172-
repositoriesManager.removeRepository(repositoryId())
173-
call.respond(HttpStatusCode.OK)
172+
val repositoryId = repositoryId()
173+
if (!repositoriesManager.repositoryExists(repositoryId)) {
174+
call.respond(HttpStatusCode.NotFound)
175+
} else {
176+
repositoriesManager.removeRepository(repositoryId)
177+
call.respond(HttpStatusCode.NoContent)
178+
}
174179
}
175180

176181
post<Paths.postRepositoryBranch> {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,23 @@ class RepositoriesManager(val client: LocalModelClient) {
7676
}
7777

7878
fun getRepositories(): Set<RepositoryId> {
79-
return store[REPOSITORIES_LIST_KEY]?.lines()?.map { RepositoryId(it) }?.toSet() ?: emptySet()
79+
val repositoriesList = store[REPOSITORIES_LIST_KEY]
80+
val emptyRepositoriesList = repositoriesList.isNullOrBlank()
81+
return if (emptyRepositoriesList) {
82+
emptySet()
83+
} else {
84+
repositoriesList!!.lines().map { RepositoryId(it) }.toSet()
85+
}
8086
}
8187

88+
fun repositoryExists(repositoryId: RepositoryId) = getRepositories().contains(repositoryId)
89+
8290
fun createRepository(repositoryId: RepositoryId, userName: String?, useRoleIds: Boolean = true): CLVersion {
8391
var initialVersion: CLVersion? = null
8492
store.runTransaction {
8593
val masterBranch = repositoryId.getBranchReference()
94+
if (repositoryExists(repositoryId)) throw RepositoryAlreadyExistsException(repositoryId.id)
8695
val existingRepositories = getRepositories()
87-
if (existingRepositories.contains(repositoryId)) throw RepositoryAlreadyExistsException(repositoryId.id)
8896
store.put(REPOSITORIES_LIST_KEY, (existingRepositories + repositoryId).joinToString("\n") { it.id }, false)
8997
store.put(branchListKey(repositoryId), masterBranch.branchName, false)
9098
initialVersion = CLVersion.createRegularVersion(

0 commit comments

Comments
 (0)