Commit b38aa85f authored by Manuel Herold's avatar Manuel Herold

[businessLogic] finished enum-support

parent 6796bbfc
......@@ -509,6 +509,8 @@ paths:
security:
- JwtRegular: []
operationId: "routes.enum.put_new"
tags:
- "Enums"
summary: "Updates an existing Enum with a new value."
description: "Updates an existing Enum with a new value."
parameters:
......@@ -527,11 +529,11 @@ paths:
description: "Name of the Enum"
required: true
type: "string"
- in: query
name: value
schema:
type: string
- name: value
in: query
description: Value of the Enum.
required: true
type: string
responses:
'200':
description: "Successful Request"
......
......@@ -34,14 +34,11 @@ class EnumRepository(MongoRepositoryBase):
return [Enum.from_serializable_dict(row) for row in list(result)]
def one(self, name: str, use_case: str, table: str) -> Enum:
def all_instances(self, name: str, use_case: str, table: str) -> Enum:
result = list(super().get_entries(self._enum_collection, selection={
"name": name, "use_case": use_case, "table": table}))
if len(result) == 1:
return Enum.from_serializable_dict(result[0])
return None
return [Enum.from_serializable_dict(row) for row in result]
def delete_all(self):
collection = self._database[self._enum_collection]
......
......@@ -13,9 +13,11 @@ import connexion
from security import swagger_util
from env_info import is_running_locally, get_resources_path
from flask import request
from flask_cors import CORS
from flask import redirect
app = connexion.App(__name__, specification_dir='configs/')
CORS(app.app)
from db.entities.layer_adapter import LayerAdapter
......
......@@ -11,6 +11,7 @@ connexion==2.7.0
coverage==5.3.1
cryptography==3.1
Flask==1.1.2
Flask-Cors==3.0.10
idna==2.10
importlib-metadata==1.7.0
inflection==0.5.0
......
......@@ -48,10 +48,17 @@ def put_new(use_case: str, table: str, name: str, value: str):
table - Required : unique identifier of the Table the Enum belongs to
name - Required : unique identifier for the Enum
'''
existing_enum = enum_repository.one(name, use_case, table)
existing_enums = enum_repository.all_instances(name, use_case, table)
enum_target = None
if existing_enum == None:
return Response(status=404, response=f"Enum with name '{name}' does not exist!")
found = False
for enum in existing_enums:
if enum.value == value:
enum_target = enum
break
if enum_target == None:
enum_target = Enum(use_case, table, name, value, len(existing_enums))
enum_repository.add(enum_target)
# todo
return Response(status=200, response=json.dumps(existing_enum.to_serializable_dict()))
\ No newline at end of file
return Response(status=200, response=json.dumps(enum_target.to_serializable_dict()))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment