From b59362ef6289dabf86f0c58cead6033610d21374 Mon Sep 17 00:00:00 2001 From: mandres2015 Date: Tue, 23 Nov 2021 17:46:28 -0500 Subject: [PATCH] fix: TT-418 problems solved --- V2/serverless.yml | 2 +- .../_application/_customers/_create_customer.py | 9 +++++---- V2/time_tracker/customers/_domain/_entities/_customer.py | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/V2/serverless.yml b/V2/serverless.yml index f1f364ca..e5dea8e9 100644 --- a/V2/serverless.yml +++ b/V2/serverless.yml @@ -104,5 +104,5 @@ functions: x-azure-settings: methods: - POST - route: customer/ + route: customers/ authLevel: anonymous diff --git a/V2/time_tracker/customers/_application/_customers/_create_customer.py b/V2/time_tracker/customers/_application/_customers/_create_customer.py index 86349a7c..919c34cb 100644 --- a/V2/time_tracker/customers/_application/_customers/_create_customer.py +++ b/V2/time_tracker/customers/_application/_customers/_create_customer.py @@ -1,5 +1,6 @@ import dataclasses import json +import typing import azure.functions as func @@ -7,8 +8,6 @@ from ... import _infrastructure from time_tracker._infrastructure import DB -DEFAULT_FIELDS = ["id", "deleted", "status"] - def create_customer(req: func.HttpRequest) -> func.HttpResponse: try: @@ -23,7 +22,9 @@ def create_customer(req: func.HttpRequest) -> func.HttpResponse: raise ValueError customer_to_create = _domain.Customer( - **dict.fromkeys(DEFAULT_FIELDS), + id=None, + deleted=None, + status=None, name=str(customer_data["name"]).strip(), description=str(customer_data["description"]), ) @@ -51,6 +52,6 @@ def create_customer(req: func.HttpRequest) -> func.HttpResponse: def _validate_customer(customer_data: dict) -> bool: if [field.name for field in dataclasses.fields(_domain.Customer) - if (field.name not in customer_data) and (field.name not in DEFAULT_FIELDS)]: + if (field.name not in customer_data) and (field.type != typing.Optional[field.type])]: return False return True diff --git a/V2/time_tracker/customers/_domain/_entities/_customer.py b/V2/time_tracker/customers/_domain/_entities/_customer.py index 42c71424..fedc0835 100644 --- a/V2/time_tracker/customers/_domain/_entities/_customer.py +++ b/V2/time_tracker/customers/_domain/_entities/_customer.py @@ -1,10 +1,11 @@ from dataclasses import dataclass +import typing @dataclass(frozen=True) class Customer: - id: int + id: typing.Optional[int] name: str description: str - deleted: bool - status: int + deleted: typing.Optional[bool] + status: typing.Optional[int]