From 6e4452a72eb47daf8d3cedc2392abd23252c56a4 Mon Sep 17 00:00:00 2001 From: jsilinski Date: Wed, 10 Apr 2024 21:23:23 +0200 Subject: [PATCH 1/6] 299 namespace delete first try --- .../io/hamal/api/http/controller/Assembler.kt | 1 + .../namespace/NamespaceDeleteController.kt | 27 ++++++++++ .../core/adapter/namespace_tree/Delete.kt | 31 ++++++++++++ .../handler/namespace/DeleteHandler.kt | 50 +++++++++++++++++++ .../io/hamal/repository/api/Namespace.kt | 7 +++ .../io/hamal/repository/api/NamespaceTree.kt | 9 ++++ .../io/hamal/repository/api/event/Event.kt | 1 + .../hamal/repository/api/event/Namespace.kt | 3 ++ .../record/namespace/ProjectionCurrent.kt | 4 ++ .../memory/record/namespace/Repository.kt | 19 ++++++- .../record/namespace_tree/Repository.kt | 10 ++-- .../repository/record/namespace/Entity.kt | 7 +++ .../repository/record/namespace/Record.kt | 8 ++- .../record/namespace_tree/Entity.kt | 12 +++++ .../record/namespace_tree/Record.kt | 8 +++ .../record/namespace/ProjectionCurrent.kt | 13 +++++ .../sqlite/record/namespace/Repository.kt | 21 ++++++-- .../record/namespace_tree/Repository.kt | 4 ++ .../io/hamal/lib/domain/request/Namespace.kt | 13 +++++ .../io/hamal/lib/domain/request/Requested.kt | 1 + .../kotlin/io/hamal/lib/sdk/api/Namespace.kt | 12 +++++ 21 files changed, 252 insertions(+), 9 deletions(-) create mode 100644 platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/namespace/NamespaceDeleteController.kt create mode 100644 platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace_tree/Delete.kt create mode 100644 platform/backend/core/src/main/kotlin/io/hamal/core/request/handler/namespace/DeleteHandler.kt diff --git a/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/Assembler.kt b/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/Assembler.kt index 7543d0f207..d4d62abcf4 100644 --- a/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/Assembler.kt +++ b/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/Assembler.kt @@ -30,6 +30,7 @@ fun Requested.toApiRequested(): ApiRequested = when (this) { is HookUpdateRequested -> ApiHookUpdateRequested(requestId, requestStatus, id) is NamespaceAppendRequested -> ApiNamespaceAppendRequested(requestId, requestStatus, id, workspaceId) is NamespaceUpdateRequested -> ApiNamespaceUpdateRequested(requestId, requestStatus, id) + is NamespaceDeleteRequested -> ApiNamespaceDeleteRequested(requestId, requestStatus, id) is StateSetRequested -> ApiStateSetRequested(requestId, requestStatus) is TopicAppendEventRequested -> ApiTopicAppendRequested(requestId, requestStatus, id) is TopicCreateRequested -> ApiTopicCreateRequested(requestId, requestStatus, id, workspaceId, namespaceId, type) diff --git a/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/namespace/NamespaceDeleteController.kt b/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/namespace/NamespaceDeleteController.kt new file mode 100644 index 0000000000..fc5986aabc --- /dev/null +++ b/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/namespace/NamespaceDeleteController.kt @@ -0,0 +1,27 @@ +package io.hamal.api.http.controller.namespace + +import io.hamal.api.http.controller.accepted +import io.hamal.core.adapter.namespace_tree.NamespaceDeletePort +import io.hamal.core.component.Retry +import io.hamal.lib.domain.vo.NamespaceId +import io.hamal.lib.sdk.api.ApiNamespaceDeleteRequest +import io.hamal.lib.sdk.api.ApiRequested +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController + +@RestController +internal class NamespaceDeleteController( + private val retry: Retry, + private val deleteNamespace: NamespaceDeletePort +) { + @DeleteMapping("/v1/namespaces/{namespaceId}") + fun delete( + @PathVariable("namespaceId") namespaceId: NamespaceId, + @RequestBody req: ApiNamespaceDeleteRequest, + ): ResponseEntity = retry { + deleteNamespace(namespaceId, req).accepted() + } +} \ No newline at end of file diff --git a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace_tree/Delete.kt b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace_tree/Delete.kt new file mode 100644 index 0000000000..9ee9debc32 --- /dev/null +++ b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace_tree/Delete.kt @@ -0,0 +1,31 @@ +package io.hamal.core.adapter.namespace_tree + +import io.hamal.core.adapter.request.RequestEnqueuePort +import io.hamal.core.security.SecurityContext +import io.hamal.lib.domain.GenerateDomainId +import io.hamal.lib.domain._enum.RequestStatus +import io.hamal.lib.domain.request.NamespaceDeleteRequested +import io.hamal.lib.domain.vo.NamespaceId +import io.hamal.lib.domain.vo.RequestId +import io.hamal.lib.sdk.api.ApiNamespaceDeleteRequest +import org.springframework.stereotype.Component + +fun interface NamespaceDeletePort { + operator fun invoke(namespaceId: NamespaceId, req: ApiNamespaceDeleteRequest): NamespaceDeleteRequested +} + +@Component +class Delete( + private val generateDomainId: GenerateDomainId, + private val requestEnqueue: RequestEnqueuePort +) : NamespaceDeletePort { + override fun invoke(namespaceId: NamespaceId, req: ApiNamespaceDeleteRequest): NamespaceDeleteRequested { + return NamespaceDeleteRequested( + requestId = generateDomainId(::RequestId), + requestedBy = SecurityContext.currentAuthId, + requestStatus = RequestStatus.Submitted, + id = namespaceId, + parentId = req.parentId, + ).also { requestEnqueue::invoke } + } +} \ No newline at end of file diff --git a/platform/backend/core/src/main/kotlin/io/hamal/core/request/handler/namespace/DeleteHandler.kt b/platform/backend/core/src/main/kotlin/io/hamal/core/request/handler/namespace/DeleteHandler.kt new file mode 100644 index 0000000000..ce23aa39c3 --- /dev/null +++ b/platform/backend/core/src/main/kotlin/io/hamal/core/request/handler/namespace/DeleteHandler.kt @@ -0,0 +1,50 @@ +package io.hamal.core.request.handler.namespace + +import io.hamal.core.event.InternalEventEmitter +import io.hamal.core.request.RequestHandler +import io.hamal.core.request.handler.cmdId +import io.hamal.lib.common.domain.CmdId +import io.hamal.lib.domain.request.NamespaceDeleteRequested +import io.hamal.repository.api.Namespace +import io.hamal.repository.api.NamespaceCmdRepository +import io.hamal.repository.api.NamespaceCmdRepository.DeleteCmd +import io.hamal.repository.api.NamespaceTreeCmdRepository +import io.hamal.repository.api.NamespaceTreeCmdRepository.ReduceCmd +import io.hamal.repository.api.NamespaceTreeQueryRepository +import io.hamal.repository.api.event.NamespaceDeletedEvent +import org.springframework.stereotype.Component + +@Component +class DeleteHandler( + private val namespaceCmdRepository: NamespaceCmdRepository, + private val namespaceTreeCmdRepository: NamespaceTreeCmdRepository, + private val namespaceTreeQueryRepository: NamespaceTreeQueryRepository, + private val eventEmitter: InternalEventEmitter +) : RequestHandler(NamespaceDeleteRequested::class) { + override fun invoke(req: NamespaceDeleteRequested) { + TODO("Not yet implemented") + } + + private fun deleteNamespace(req: NamespaceDeleteRequested): Namespace { + return namespaceCmdRepository.delete( + req.id, + DeleteCmd(id = req.cmdId(), namespaceId = req.id) + ) + } + + private fun reduceTree(req: NamespaceDeleteRequested) { + val tree = namespaceTreeQueryRepository.get(req.parentId) + namespaceTreeCmdRepository.reduce( + ReduceCmd( + id = req.cmdId(), + treeId = tree.id, + parentId = req.parentId, + namespaceId = req.id + ) + ) + } + + private fun emitEvent(cmdId: CmdId, namespace: Namespace) { + eventEmitter.emit(cmdId, NamespaceDeletedEvent(namespace)) + } +} \ No newline at end of file diff --git a/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/Namespace.kt b/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/Namespace.kt index 19cefa4eec..344e9565ad 100644 --- a/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/Namespace.kt +++ b/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/Namespace.kt @@ -26,6 +26,8 @@ interface NamespaceCmdRepository : CmdRepository { fun update(namespaceId: NamespaceId, cmd: UpdateCmd): Namespace + fun delete(namespaceId: NamespaceId, cmd: DeleteCmd): Namespace + data class CreateCmd( val id: CmdId, val namespaceId: NamespaceId, @@ -39,6 +41,11 @@ interface NamespaceCmdRepository : CmdRepository { val name: NamespaceName? = null, val features: NamespaceFeatures? = null ) + + data class DeleteCmd( + val id: CmdId, + val namespaceId: NamespaceId, + ) } interface NamespaceQueryRepository { diff --git a/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/NamespaceTree.kt b/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/NamespaceTree.kt index 5a0abcfa70..53d5451993 100644 --- a/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/NamespaceTree.kt +++ b/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/NamespaceTree.kt @@ -32,6 +32,8 @@ interface NamespaceTreeCmdRepository : CmdRepository { fun append(cmd: AppendCmd): NamespaceTree + fun reduce(cmd: ReduceCmd): NamespaceTree + data class CreateCmd( val id: CmdId, val treeId: NamespaceTreeId, @@ -45,6 +47,13 @@ interface NamespaceTreeCmdRepository : CmdRepository { val parentId: NamespaceId, val namespaceId: NamespaceId, ) + + data class ReduceCmd( + val id: CmdId, + val treeId: NamespaceTreeId, + val parentId: NamespaceId, + val namespaceId: NamespaceId, + ) } interface NamespaceTreeQueryRepository { diff --git a/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/event/Event.kt b/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/event/Event.kt index fee7314507..0ff3569845 100644 --- a/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/event/Event.kt +++ b/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/event/Event.kt @@ -29,6 +29,7 @@ val internalEventClasses = listOf( FeedbackCreatedEvent::class, NamespaceAppendedEvent::class, NamespaceUpdatedEvent::class, + NamespaceDeletedEvent::class, FuncCreatedEvent::class, FuncUpdatedEvent::class, FuncDeployedEvent::class, diff --git a/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/event/Namespace.kt b/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/event/Namespace.kt index 23ab6da0a8..f2512ff40c 100644 --- a/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/event/Namespace.kt +++ b/platform/backend/repository/api/src/main/kotlin/io/hamal/repository/api/event/Namespace.kt @@ -11,3 +11,6 @@ data class NamespaceUpdatedEvent( val namespace: Namespace, ) : InternalEvent() +data class NamespaceDeletedEvent( + val namespace: Namespace, +) : InternalEvent() diff --git a/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace/ProjectionCurrent.kt b/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace/ProjectionCurrent.kt index cb132ba3d1..d0332cd86e 100644 --- a/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace/ProjectionCurrent.kt +++ b/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace/ProjectionCurrent.kt @@ -13,6 +13,10 @@ internal class ProjectionCurrent : ProjectionMemory { projection[obj.id] = obj } + fun delete(obj: Namespace) { + projection.remove(obj.id) + } + fun find(namespaceId: NamespaceId): Namespace? = projection[namespaceId] fun find(namespaceName: NamespaceName): Namespace? = projection.values.find { it.name == namespaceName } diff --git a/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace/Repository.kt b/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace/Repository.kt index c9a25eef4e..ab483899ee 100644 --- a/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace/Repository.kt +++ b/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace/Repository.kt @@ -3,8 +3,7 @@ package io.hamal.repository.memory.record.namespace import io.hamal.lib.common.domain.Count import io.hamal.lib.domain.vo.NamespaceId import io.hamal.repository.api.Namespace -import io.hamal.repository.api.NamespaceCmdRepository.CreateCmd -import io.hamal.repository.api.NamespaceCmdRepository.UpdateCmd +import io.hamal.repository.api.NamespaceCmdRepository.* import io.hamal.repository.api.NamespaceQueryRepository.NamespaceQuery import io.hamal.repository.api.NamespaceRepository import io.hamal.repository.memory.record.RecordMemoryRepository @@ -58,6 +57,22 @@ class NamespaceMemoryRepository : RecordMemoryRepository = lock.withLock { currentProjection.list(query) } diff --git a/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace_tree/Repository.kt b/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace_tree/Repository.kt index 7dd3d3192d..1069919fb6 100644 --- a/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace_tree/Repository.kt +++ b/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace_tree/Repository.kt @@ -4,7 +4,7 @@ import io.hamal.lib.common.domain.Count import io.hamal.lib.domain.vo.NamespaceId import io.hamal.lib.domain.vo.NamespaceTreeId import io.hamal.repository.api.NamespaceTree -import io.hamal.repository.api.NamespaceTreeCmdRepository +import io.hamal.repository.api.NamespaceTreeCmdRepository.* import io.hamal.repository.api.NamespaceTreeQueryRepository.NamespaceTreeQuery import io.hamal.repository.api.NamespaceTreeRepository import io.hamal.repository.memory.record.RecordMemoryRepository @@ -19,7 +19,7 @@ class NamespaceTreeMemoryRepository : RecordMemoryRepository copy( + id = rec.entityId, + cmdId = rec.cmdId, + sequence = rec.sequence(), + recordedAt = rec.recordedAt() + ) } } diff --git a/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace/Record.kt b/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace/Record.kt index 8e8e93ebe1..a351f18763 100644 --- a/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace/Record.kt +++ b/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace/Record.kt @@ -19,7 +19,8 @@ sealed class NamespaceRecord( internal object Adapter : RecordAdapter( listOf( Created::class, - Updated::class + Updated::class, + Deleted::class ) ) @@ -37,5 +38,10 @@ sealed class NamespaceRecord( val name: NamespaceName, val features: NamespaceFeatures ) : NamespaceRecord() + + data class Deleted( + override val entityId: NamespaceId, + override val cmdId: CmdId + ) : NamespaceRecord() } diff --git a/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Entity.kt b/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Entity.kt index 5c6e856e35..84f38dc53d 100644 --- a/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Entity.kt +++ b/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Entity.kt @@ -46,6 +46,18 @@ data class NamespaceTreeEntity( recordedAt = rec.recordedAt() ) + is NamespaceTreeRecord.Reduced -> copy( + id = rec.entityId, + cmdId = rec.cmdId, + sequence = rec.sequence(), + root = root!!.mutate().let { rootNode -> + val parent = rootNode.find { it.value == rec.parentId }!! + parent.descendants.clear() + rootNode.toTreeNode() + }, + recordedAt = rec.recordedAt() + ) + } } diff --git a/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Record.kt b/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Record.kt index a580749d8f..a493e65aea 100644 --- a/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Record.kt +++ b/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Record.kt @@ -35,4 +35,12 @@ sealed class NamespaceTreeRecord( val parentId: NamespaceId, val namespaceId: NamespaceId ) : NamespaceTreeRecord() + + data class Reduced( + override val entityId: NamespaceTreeId, + override val cmdId: CmdId, + val parentId: NamespaceId, + ) : NamespaceTreeRecord() + + } diff --git a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/ProjectionCurrent.kt b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/ProjectionCurrent.kt index 3e83bb491a..9448672c9d 100644 --- a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/ProjectionCurrent.kt +++ b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/ProjectionCurrent.kt @@ -97,6 +97,19 @@ internal object ProjectionCurrent : ProjectionSqlite, obj: Namespace) { + tx.execute( + """ + DELETE FROM + current + WHERE + (:id) + """.trimIndent() + ) { + set("id", obj.id) + } + } + override fun setupSchema(connection: Connection) { connection.execute( """ diff --git a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/Repository.kt b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/Repository.kt index ca4a9e873b..9c0fb416af 100644 --- a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/Repository.kt +++ b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/Repository.kt @@ -3,8 +3,7 @@ package io.hamal.repository.sqlite.record.namespace import io.hamal.lib.common.domain.Count import io.hamal.lib.domain.vo.NamespaceId import io.hamal.repository.api.Namespace -import io.hamal.repository.api.NamespaceCmdRepository -import io.hamal.repository.api.NamespaceCmdRepository.CreateCmd +import io.hamal.repository.api.NamespaceCmdRepository.* import io.hamal.repository.api.NamespaceQueryRepository.NamespaceQuery import io.hamal.repository.api.NamespaceRepository import io.hamal.repository.record.CreateDomainObject @@ -67,7 +66,7 @@ class NamespaceSqliteRepository( } } - override fun update(namespaceId: NamespaceId, cmd: NamespaceCmdRepository.UpdateCmd): Namespace { + override fun update(namespaceId: NamespaceId, cmd: UpdateCmd): Namespace { val cmdId = cmd.id return tx { if (commandAlreadyApplied(cmdId, namespaceId)) { @@ -87,6 +86,22 @@ class NamespaceSqliteRepository( } } + override fun delete(namespaceId: NamespaceId, cmd: DeleteCmd): Namespace { + return tx { + if (commandAlreadyApplied(cmd.id, namespaceId)) { + versionOf(namespaceId, cmd.id) + } else { + store( + NamespaceRecord.Deleted( + entityId = namespaceId, + cmdId = cmd.id + ) + ) + currentVersion(namespaceId).also { ProjectionCurrent.delete(this, it) } + } + } + } + override fun find(namespaceId: NamespaceId): Namespace? { return ProjectionCurrent.find(connection, namespaceId) } diff --git a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace_tree/Repository.kt b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace_tree/Repository.kt index 46efd93781..fb85bf0ed6 100644 --- a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace_tree/Repository.kt +++ b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace_tree/Repository.kt @@ -89,6 +89,10 @@ class NamespaceTreeSqliteRepository( } } + override fun reduce(cmd: NamespaceTreeCmdRepository.ReduceCmd): NamespaceTree { + TODO("Not yet implemented") + } + override fun find(namespaceId: NamespaceId): NamespaceTree? = ProjectionCurrent.find(connection, namespaceId) override fun list(query: NamespaceTreeQuery): List = diff --git a/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt b/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt index 4f73610e37..1700e15fb4 100644 --- a/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt +++ b/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt @@ -33,3 +33,16 @@ data class NamespaceUpdateRequested( val name: NamespaceName?, val features: NamespaceFeatures? ) : Requested() + +interface NamespaceDeleteRequest { + val id: NamespaceId + val parentId: NamespaceId +} + +data class NamespaceDeleteRequested( + override val requestId: RequestId, + override val requestedBy: AuthId, + override var requestStatus: RequestStatus, + val id: NamespaceId, + val parentId: NamespaceId, +) : Requested() diff --git a/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Requested.kt b/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Requested.kt index 5fa7d01e68..e5c2576772 100644 --- a/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Requested.kt +++ b/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Requested.kt @@ -62,6 +62,7 @@ sealed class Requested { HookUpdateRequested::class, NamespaceAppendRequested::class, NamespaceUpdateRequested::class, + NamespaceDeleteRequested::class, StateSetRequested::class, TestRequested::class, TopicAppendEventRequested::class, diff --git a/platform/lib/sdk/src/main/kotlin/io/hamal/lib/sdk/api/Namespace.kt b/platform/lib/sdk/src/main/kotlin/io/hamal/lib/sdk/api/Namespace.kt index 4506c4cf34..98c258ae4d 100644 --- a/platform/lib/sdk/src/main/kotlin/io/hamal/lib/sdk/api/Namespace.kt +++ b/platform/lib/sdk/src/main/kotlin/io/hamal/lib/sdk/api/Namespace.kt @@ -2,6 +2,7 @@ package io.hamal.lib.sdk.api import io.hamal.lib.domain._enum.RequestStatus import io.hamal.lib.domain.request.NamespaceAppendRequest +import io.hamal.lib.domain.request.NamespaceDeleteRequest import io.hamal.lib.domain.request.NamespaceUpdateRequest import io.hamal.lib.domain.vo.* import io.hamal.lib.http.HttpTemplate @@ -31,6 +32,17 @@ data class ApiNamespaceUpdateRequested( val id: NamespaceId, ) : ApiRequested() +data class ApiNamespaceDeleteRequest( + override val id: NamespaceId, + override val parentId: NamespaceId +) : NamespaceDeleteRequest + +data class ApiNamespaceDeleteRequested( + override val requestId: RequestId, + override val requestStatus: RequestStatus, + val id: NamespaceId, +) : ApiRequested() + data class ApiNamespaceList( val namespaces: List ) : ApiObject() { From 43fd4ceb7aaca5222891c52c2a76a569d254c822 Mon Sep 17 00:00:00 2001 From: jsilinski Date: Thu, 11 Apr 2024 11:34:51 +0200 Subject: [PATCH 2/6] 299 delete child namespaces in evt handler --- .../namespace/NamespaceDeleteController.kt | 7 ++-- .../{namespace_tree => namespace}/Delete.kt | 8 ++--- .../namespace/NamespaceDeletedHandler.kt | 32 +++++++++++++++++++ .../handler/namespace/DeleteHandler.kt | 31 ++++++++++-------- .../record/namespace_tree/Repository.kt | 17 +++++++++- .../record/namespace_tree/Entity.kt | 4 +-- .../record/namespace_tree/Record.kt | 3 +- .../record/namespace_tree/Repository.kt | 7 ++-- .../io/hamal/lib/domain/request/Namespace.kt | 7 +--- .../kotlin/io/hamal/lib/sdk/api/Namespace.kt | 5 --- 10 files changed, 78 insertions(+), 43 deletions(-) rename platform/backend/core/src/main/kotlin/io/hamal/core/adapter/{namespace_tree => namespace}/Delete.kt (70%) create mode 100644 platform/backend/core/src/main/kotlin/io/hamal/core/event/handler/namespace/NamespaceDeletedHandler.kt diff --git a/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/namespace/NamespaceDeleteController.kt b/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/namespace/NamespaceDeleteController.kt index fc5986aabc..99e4cdf33b 100644 --- a/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/namespace/NamespaceDeleteController.kt +++ b/platform/backend/api/src/main/kotlin/io/hamal/api/http/controller/namespace/NamespaceDeleteController.kt @@ -1,15 +1,13 @@ package io.hamal.api.http.controller.namespace import io.hamal.api.http.controller.accepted -import io.hamal.core.adapter.namespace_tree.NamespaceDeletePort +import io.hamal.core.adapter.namespace.NamespaceDeletePort import io.hamal.core.component.Retry import io.hamal.lib.domain.vo.NamespaceId -import io.hamal.lib.sdk.api.ApiNamespaceDeleteRequest import io.hamal.lib.sdk.api.ApiRequested import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController @RestController @@ -20,8 +18,7 @@ internal class NamespaceDeleteController( @DeleteMapping("/v1/namespaces/{namespaceId}") fun delete( @PathVariable("namespaceId") namespaceId: NamespaceId, - @RequestBody req: ApiNamespaceDeleteRequest, ): ResponseEntity = retry { - deleteNamespace(namespaceId, req).accepted() + deleteNamespace(namespaceId).accepted() } } \ No newline at end of file diff --git a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace_tree/Delete.kt b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt similarity index 70% rename from platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace_tree/Delete.kt rename to platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt index 9ee9debc32..97668e6d34 100644 --- a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace_tree/Delete.kt +++ b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt @@ -1,4 +1,4 @@ -package io.hamal.core.adapter.namespace_tree +package io.hamal.core.adapter.namespace import io.hamal.core.adapter.request.RequestEnqueuePort import io.hamal.core.security.SecurityContext @@ -7,11 +7,10 @@ import io.hamal.lib.domain._enum.RequestStatus import io.hamal.lib.domain.request.NamespaceDeleteRequested import io.hamal.lib.domain.vo.NamespaceId import io.hamal.lib.domain.vo.RequestId -import io.hamal.lib.sdk.api.ApiNamespaceDeleteRequest import org.springframework.stereotype.Component fun interface NamespaceDeletePort { - operator fun invoke(namespaceId: NamespaceId, req: ApiNamespaceDeleteRequest): NamespaceDeleteRequested + operator fun invoke(namespaceId: NamespaceId): NamespaceDeleteRequested } @Component @@ -19,13 +18,12 @@ class Delete( private val generateDomainId: GenerateDomainId, private val requestEnqueue: RequestEnqueuePort ) : NamespaceDeletePort { - override fun invoke(namespaceId: NamespaceId, req: ApiNamespaceDeleteRequest): NamespaceDeleteRequested { + override fun invoke(namespaceId: NamespaceId): NamespaceDeleteRequested { return NamespaceDeleteRequested( requestId = generateDomainId(::RequestId), requestedBy = SecurityContext.currentAuthId, requestStatus = RequestStatus.Submitted, id = namespaceId, - parentId = req.parentId, ).also { requestEnqueue::invoke } } } \ No newline at end of file diff --git a/platform/backend/core/src/main/kotlin/io/hamal/core/event/handler/namespace/NamespaceDeletedHandler.kt b/platform/backend/core/src/main/kotlin/io/hamal/core/event/handler/namespace/NamespaceDeletedHandler.kt new file mode 100644 index 0000000000..65a44ffe4f --- /dev/null +++ b/platform/backend/core/src/main/kotlin/io/hamal/core/event/handler/namespace/NamespaceDeletedHandler.kt @@ -0,0 +1,32 @@ +package io.hamal.core.event.handler.namespace + +import io.hamal.core.adapter.namespace.NamespaceDeletePort +import io.hamal.core.adapter.namespace_tree.NamespaceTreeGetSubTreePort +import io.hamal.core.event.InternalEventHandler +import io.hamal.lib.common.domain.CmdId +import io.hamal.repository.api.NamespaceRepository +import io.hamal.repository.api.NamespaceTree +import io.hamal.repository.api.NamespaceTreeRepository +import io.hamal.repository.api.event.NamespaceDeletedEvent +import org.springframework.stereotype.Component + +@Component +internal class NamespaceDeletedHandler( + private val namespaceRepository: NamespaceRepository, + private val namespaceTreeRepository: NamespaceTreeRepository, + private val getSubTree: NamespaceTreeGetSubTreePort, + private val deleteNamespace: NamespaceDeletePort +) : InternalEventHandler { + + override fun handle(cmdId: CmdId, evt: NamespaceDeletedEvent) { + val tree: NamespaceTree? = namespaceTreeRepository.find(evt.namespace.id) + + val children = getSubTree(evt.namespace.id).values + children.forEach { + deleteNamespace(it) + } + + //Delete Tree Node... + + } +} \ No newline at end of file diff --git a/platform/backend/core/src/main/kotlin/io/hamal/core/request/handler/namespace/DeleteHandler.kt b/platform/backend/core/src/main/kotlin/io/hamal/core/request/handler/namespace/DeleteHandler.kt index ce23aa39c3..fc5005144a 100644 --- a/platform/backend/core/src/main/kotlin/io/hamal/core/request/handler/namespace/DeleteHandler.kt +++ b/platform/backend/core/src/main/kotlin/io/hamal/core/request/handler/namespace/DeleteHandler.kt @@ -7,43 +7,46 @@ import io.hamal.lib.common.domain.CmdId import io.hamal.lib.domain.request.NamespaceDeleteRequested import io.hamal.repository.api.Namespace import io.hamal.repository.api.NamespaceCmdRepository -import io.hamal.repository.api.NamespaceCmdRepository.DeleteCmd import io.hamal.repository.api.NamespaceTreeCmdRepository -import io.hamal.repository.api.NamespaceTreeCmdRepository.ReduceCmd import io.hamal.repository.api.NamespaceTreeQueryRepository import io.hamal.repository.api.event.NamespaceDeletedEvent import org.springframework.stereotype.Component @Component -class DeleteHandler( +class NamespaceDeleteHandler( private val namespaceCmdRepository: NamespaceCmdRepository, private val namespaceTreeCmdRepository: NamespaceTreeCmdRepository, private val namespaceTreeQueryRepository: NamespaceTreeQueryRepository, private val eventEmitter: InternalEventEmitter ) : RequestHandler(NamespaceDeleteRequested::class) { override fun invoke(req: NamespaceDeleteRequested) { - TODO("Not yet implemented") + deleteNamespace(req).also { emitEvent(req.cmdId(), it) } } private fun deleteNamespace(req: NamespaceDeleteRequested): Namespace { return namespaceCmdRepository.delete( req.id, - DeleteCmd(id = req.cmdId(), namespaceId = req.id) - ) - } - - private fun reduceTree(req: NamespaceDeleteRequested) { - val tree = namespaceTreeQueryRepository.get(req.parentId) - namespaceTreeCmdRepository.reduce( - ReduceCmd( + NamespaceCmdRepository.DeleteCmd( id = req.cmdId(), - treeId = tree.id, - parentId = req.parentId, namespaceId = req.id ) ) } + /* + private fun reduceTree(req: NamespaceDeleteRequested) { + val tree = namespaceTreeQueryRepository.get(req.parentId) + namespaceTreeCmdRepository.reduce( + NamespaceTreeCmdRepository.DeleteCmd( + id = req.cmdId(), + treeId = tree.id, + parentId = req.parentId, + namespaceId = req.id + ) + ) + } + */ + private fun emitEvent(cmdId: CmdId, namespace: Namespace) { eventEmitter.emit(cmdId, NamespaceDeletedEvent(namespace)) } diff --git a/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace_tree/Repository.kt b/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace_tree/Repository.kt index 1069919fb6..2724900212 100644 --- a/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace_tree/Repository.kt +++ b/platform/backend/repository/memory/src/main/kotlin/io/hamal/repository/memory/record/namespace_tree/Repository.kt @@ -58,7 +58,22 @@ class NamespaceTreeMemoryRepository : RecordMemoryRepository copy( + is NamespaceTreeRecord.Deleted -> copy( id = rec.entityId, cmdId = rec.cmdId, sequence = rec.sequence(), root = root!!.mutate().let { rootNode -> val parent = rootNode.find { it.value == rec.parentId }!! - parent.descendants.clear() + parent.descendants.removeIf { it.value == rec.namespaceId } rootNode.toTreeNode() }, recordedAt = rec.recordedAt() diff --git a/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Record.kt b/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Record.kt index a493e65aea..7c60642b47 100644 --- a/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Record.kt +++ b/platform/backend/repository/record/src/main/kotlin/io/hamal/repository/record/namespace_tree/Record.kt @@ -36,10 +36,11 @@ sealed class NamespaceTreeRecord( val namespaceId: NamespaceId ) : NamespaceTreeRecord() - data class Reduced( + data class Deleted( override val entityId: NamespaceTreeId, override val cmdId: CmdId, val parentId: NamespaceId, + val namespaceId: NamespaceId ) : NamespaceTreeRecord() diff --git a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace_tree/Repository.kt b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace_tree/Repository.kt index fb85bf0ed6..7cee9a2aa2 100644 --- a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace_tree/Repository.kt +++ b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace_tree/Repository.kt @@ -4,8 +4,7 @@ import io.hamal.lib.common.domain.Count import io.hamal.lib.domain.vo.NamespaceId import io.hamal.lib.domain.vo.NamespaceTreeId import io.hamal.repository.api.NamespaceTree -import io.hamal.repository.api.NamespaceTreeCmdRepository -import io.hamal.repository.api.NamespaceTreeCmdRepository.CreateCmd +import io.hamal.repository.api.NamespaceTreeCmdRepository.* import io.hamal.repository.api.NamespaceTreeQueryRepository.NamespaceTreeQuery import io.hamal.repository.api.NamespaceTreeRepository import io.hamal.repository.record.CreateDomainObject @@ -68,7 +67,7 @@ class NamespaceTreeSqliteRepository( } } - override fun append(cmd: NamespaceTreeCmdRepository.AppendCmd): NamespaceTree { + override fun append(cmd: AppendCmd): NamespaceTree { return tx { val treeId = cmd.treeId if (commandAlreadyApplied(cmd.id, treeId)) { @@ -89,7 +88,7 @@ class NamespaceTreeSqliteRepository( } } - override fun reduce(cmd: NamespaceTreeCmdRepository.ReduceCmd): NamespaceTree { + override fun reduce(cmd: ReduceCmd): NamespaceTree { TODO("Not yet implemented") } diff --git a/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt b/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt index 1700e15fb4..a92f902f73 100644 --- a/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt +++ b/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt @@ -34,15 +34,10 @@ data class NamespaceUpdateRequested( val features: NamespaceFeatures? ) : Requested() -interface NamespaceDeleteRequest { - val id: NamespaceId - val parentId: NamespaceId -} data class NamespaceDeleteRequested( override val requestId: RequestId, override val requestedBy: AuthId, override var requestStatus: RequestStatus, - val id: NamespaceId, - val parentId: NamespaceId, + val id: NamespaceId ) : Requested() diff --git a/platform/lib/sdk/src/main/kotlin/io/hamal/lib/sdk/api/Namespace.kt b/platform/lib/sdk/src/main/kotlin/io/hamal/lib/sdk/api/Namespace.kt index 98c258ae4d..fef6fcbf58 100644 --- a/platform/lib/sdk/src/main/kotlin/io/hamal/lib/sdk/api/Namespace.kt +++ b/platform/lib/sdk/src/main/kotlin/io/hamal/lib/sdk/api/Namespace.kt @@ -2,7 +2,6 @@ package io.hamal.lib.sdk.api import io.hamal.lib.domain._enum.RequestStatus import io.hamal.lib.domain.request.NamespaceAppendRequest -import io.hamal.lib.domain.request.NamespaceDeleteRequest import io.hamal.lib.domain.request.NamespaceUpdateRequest import io.hamal.lib.domain.vo.* import io.hamal.lib.http.HttpTemplate @@ -32,10 +31,6 @@ data class ApiNamespaceUpdateRequested( val id: NamespaceId, ) : ApiRequested() -data class ApiNamespaceDeleteRequest( - override val id: NamespaceId, - override val parentId: NamespaceId -) : NamespaceDeleteRequest data class ApiNamespaceDeleteRequested( override val requestId: RequestId, From da17e1464eeef0243d2de598337965bde5da2f9f Mon Sep 17 00:00:00 2001 From: jsilinski Date: Thu, 11 Apr 2024 19:16:59 +0200 Subject: [PATCH 3/6] 299 fixes adapter --- .../core/request/handler/namespace/DeleteHandlerTest.kt | 4 ---- .../main/kotlin/io/hamal/core/adapter/namespace/Delete.kt | 7 +------ .../main/kotlin/io/hamal/lib/domain/request/Namespace.kt | 3 +-- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/platform/backend/core/src/integrationTest/kotlin/io/hamal/core/request/handler/namespace/DeleteHandlerTest.kt b/platform/backend/core/src/integrationTest/kotlin/io/hamal/core/request/handler/namespace/DeleteHandlerTest.kt index 532ed7b9f0..93d827559f 100644 --- a/platform/backend/core/src/integrationTest/kotlin/io/hamal/core/request/handler/namespace/DeleteHandlerTest.kt +++ b/platform/backend/core/src/integrationTest/kotlin/io/hamal/core/request/handler/namespace/DeleteHandlerTest.kt @@ -63,10 +63,6 @@ internal class DeleteHandlerTest : BaseRequestHandlerTest() { assertThat(name, equalTo(NamespaceName("root"))) assertThat(features, equalTo(NamespaceFeatures.default)) } - - val tree = namespaceTreeRepository.find(NamespaceId.root) - assertThat(tree!!.root.value, equalTo(NamespaceId.root)) - assertThat(tree.root.descendants, hasSize(0)) } @Autowired diff --git a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt index b9302d4b1e..b014321872 100644 --- a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt +++ b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt @@ -1,6 +1,5 @@ package io.hamal.core.adapter.namespace -import io.hamal.core.adapter.namespace_tree.NamespaceTreeGetSubTreePort import io.hamal.core.adapter.request.RequestEnqueuePort import io.hamal.core.security.SecurityContext import io.hamal.lib.domain.GenerateDomainId @@ -17,18 +16,14 @@ fun interface NamespaceDeletePort { @Component class NamespaceDeleteAdapter( private val generateDomainId: GenerateDomainId, - private val getSubTree: NamespaceTreeGetSubTreePort, private val requestEnqueue: RequestEnqueuePort ) : NamespaceDeletePort { override fun invoke(namespaceId: NamespaceId): NamespaceDeleteRequested { - val parent = getSubTree(namespaceId) - return NamespaceDeleteRequested( requestId = generateDomainId(::RequestId), requestedBy = SecurityContext.currentAuthId, requestStatus = RequestStatus.Submitted, id = namespaceId, - parentId = parent.root.value, - ).also { requestEnqueue::invoke } + ).also(requestEnqueue::invoke) } } \ No newline at end of file diff --git a/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt b/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt index e3c97880bf..e1e54b8c09 100644 --- a/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt +++ b/platform/lib/domain/src/main/kotlin/io/hamal/lib/domain/request/Namespace.kt @@ -39,6 +39,5 @@ data class NamespaceDeleteRequested( override val requestId: RequestId, override val requestedBy: AuthId, override var requestStatus: RequestStatus, - val id: NamespaceId, - val parentId: NamespaceId + val id: NamespaceId ) : Requested() \ No newline at end of file From e6392f9e668ddfdbab2d59fa0dc8703636ea882a Mon Sep 17 00:00:00 2001 From: jsilinski Date: Thu, 11 Apr 2024 20:42:27 +0200 Subject: [PATCH 4/6] 299 do not delete root namespace --- .../main/kotlin/io/hamal/core/adapter/namespace/Delete.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt index b014321872..d706f58d65 100644 --- a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt +++ b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt @@ -7,6 +7,7 @@ import io.hamal.lib.domain._enum.RequestStatus import io.hamal.lib.domain.request.NamespaceDeleteRequested import io.hamal.lib.domain.vo.NamespaceId import io.hamal.lib.domain.vo.RequestId +import io.hamal.repository.api.NamespaceTreeQueryRepository import org.springframework.stereotype.Component fun interface NamespaceDeletePort { @@ -16,9 +17,14 @@ fun interface NamespaceDeletePort { @Component class NamespaceDeleteAdapter( private val generateDomainId: GenerateDomainId, - private val requestEnqueue: RequestEnqueuePort + private val requestEnqueue: RequestEnqueuePort, + private val namespaceTreeQueryRepository: NamespaceTreeQueryRepository ) : NamespaceDeletePort { override fun invoke(namespaceId: NamespaceId): NamespaceDeleteRequested { + val root = namespaceTreeQueryRepository.get(namespaceId).root + if (root.value == namespaceId) { + throw IllegalArgumentException("Tried to delete root namespace") + } return NamespaceDeleteRequested( requestId = generateDomainId(::RequestId), requestedBy = SecurityContext.currentAuthId, From 9611d97988a3855de739acfa04fe71ad73884d05 Mon Sep 17 00:00:00 2001 From: jsilinski Date: Thu, 11 Apr 2024 22:32:58 +0200 Subject: [PATCH 5/6] 299 passes secu test --- .../main/kotlin/io/hamal/core/adapter/namespace/Delete.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt index d706f58d65..8c4e06279a 100644 --- a/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt +++ b/platform/backend/core/src/main/kotlin/io/hamal/core/adapter/namespace/Delete.kt @@ -18,13 +18,17 @@ fun interface NamespaceDeletePort { class NamespaceDeleteAdapter( private val generateDomainId: GenerateDomainId, private val requestEnqueue: RequestEnqueuePort, - private val namespaceTreeQueryRepository: NamespaceTreeQueryRepository + private val namespaceTreeQueryRepository: NamespaceTreeQueryRepository, + private val namespaceGetPort: NamespaceGetPort ) : NamespaceDeletePort { override fun invoke(namespaceId: NamespaceId): NamespaceDeleteRequested { + namespaceGetPort(namespaceId) + val root = namespaceTreeQueryRepository.get(namespaceId).root if (root.value == namespaceId) { throw IllegalArgumentException("Tried to delete root namespace") } + return NamespaceDeleteRequested( requestId = generateDomainId(::RequestId), requestedBy = SecurityContext.currentAuthId, From df8cfeb20045f73512ccdafc46ae78256832effb Mon Sep 17 00:00:00 2001 From: jsilinski Date: Thu, 11 Apr 2024 23:03:26 +0200 Subject: [PATCH 6/6] 299 fix sqlite repo --- .../handler/namespace/DeleteHandlerTest.kt | 2 -- .../record/namespace/ProjectionCurrent.kt | 2 +- .../io/hamal/repository/NamespaceTest.kt | 29 +++++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/platform/backend/core/src/integrationTest/kotlin/io/hamal/core/request/handler/namespace/DeleteHandlerTest.kt b/platform/backend/core/src/integrationTest/kotlin/io/hamal/core/request/handler/namespace/DeleteHandlerTest.kt index 93d827559f..133ee043d9 100644 --- a/platform/backend/core/src/integrationTest/kotlin/io/hamal/core/request/handler/namespace/DeleteHandlerTest.kt +++ b/platform/backend/core/src/integrationTest/kotlin/io/hamal/core/request/handler/namespace/DeleteHandlerTest.kt @@ -77,8 +77,6 @@ internal class DeleteHandlerTest : BaseRequestHandlerTest() { requestedBy = AuthId(4), requestStatus = RequestStatus.Submitted, id = NamespaceId(5), - parentId = NamespaceId.root - ) } diff --git a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/ProjectionCurrent.kt b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/ProjectionCurrent.kt index 9448672c9d..db2e0e306a 100644 --- a/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/ProjectionCurrent.kt +++ b/platform/backend/repository/sqlite/src/main/kotlin/io/hamal/repository/sqlite/record/namespace/ProjectionCurrent.kt @@ -103,7 +103,7 @@ internal object ProjectionCurrent : ProjectionSqlite { + get(NamespaceId(5)) + } + assertThat(exception.message, equalTo("Namespace not found")) + + verifyCount(0) + } + @Nested inner class UpdatesNamespaceTest {