Skip to content

Commit

Permalink
feat: Delete TeamForCapella server instances
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzWeber0 committed Sep 11, 2024
1 parent 576bce6 commit 60235ce
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 174 deletions.
8 changes: 8 additions & 0 deletions backend/capellacollab/settings/modelsources/t4c/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ def update_t4c_instance(
db.commit()

return instance


def delete_t4c_instance(
db: orm.Session,
instance: models.DatabaseT4CInstance,
):
db.delete(instance)
db.commit()
13 changes: 13 additions & 0 deletions backend/capellacollab/settings/modelsources/t4c/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ def edit_t4c_instance(
return crud.update_t4c_instance(db, instance, body)


@router.delete(
"/{t4c_instance_id}",
status_code=204,
)
def delete_t4c_instance(
instance: models.DatabaseT4CInstance = fastapi.Depends(
injectables.get_existing_instance
),
db: orm.Session = fastapi.Depends(database.get_db),
):
crud.delete_t4c_instance(db, instance)


@router.get(
"/{t4c_instance_id}/licenses",
response_model=models.GetSessionUsageResponse,
Expand Down
22 changes: 22 additions & 0 deletions backend/tests/settings/teamforcapella/test_t4c_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
from fastapi import status, testclient
from sqlalchemy import orm

from capellacollab.projects.toolmodels.modelsources.t4c import (
crud as models_t4c_crud,
)
from capellacollab.projects.toolmodels.modelsources.t4c import (
models as models_t4c_models,
)
from capellacollab.settings.modelsources.t4c import crud as t4c_crud
from capellacollab.settings.modelsources.t4c import (
exceptions as settings_t4c_exceptions,
Expand Down Expand Up @@ -260,6 +266,22 @@ def test_patch_t4c_instance_already_existing_name(
assert "name already used" in detail["title"]


@pytest.mark.usefixtures("admin")
def test_delete_t4c_instance(
client: testclient.TestClient,
db: orm.Session,
t4c_instance: t4c_models.DatabaseT4CInstance,
t4c_model: models_t4c_models.DatabaseT4CModel,
):
response = client.delete(
f"/api/v1/settings/modelsources/t4c/{t4c_instance.id}",
)

assert response.status_code == 204
assert t4c_crud.get_t4c_instance_by_id(db, t4c_instance.id) is None
assert models_t4c_crud.get_t4c_model_by_id(db, t4c_model.id) is None


def test_injectables_raise_when_archived_instance(
db: orm.Session,
executor_name: str,
Expand Down
71 changes: 71 additions & 0 deletions frontend/src/app/openapi/api/settings-modelsources-t4-c.service.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/app/services/settings/t4c-instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class T4CInstanceWrapperService {
);

loadInstances(): void {
this._t4cInstances.next(undefined);
this.t4cInstanceService.getT4cInstances().subscribe({
next: (instances) => this._t4cInstances.next(instances),
error: () => this._t4cInstances.next(undefined),
Expand Down
Loading

0 comments on commit 60235ce

Please sign in to comment.