-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create all machinery to create a dataformat
- Loading branch information
Showing
11 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pydantic import BaseModel | ||
|
||
from server.application.dataformats.validation import CreateDataFormatValidationMixin | ||
|
||
|
||
class DataFormatCreate(CreateDataFormatValidationMixin, BaseModel): | ||
value: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from server.application.dataformats.validation import CreateDataFormatValidationMixin | ||
from server.seedwork.application.commands import Command | ||
|
||
|
||
class CreateDataFormat(CreateDataFormatValidationMixin, Command[int]): | ||
value: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class CannotCreateDataFormat(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
from typing import List | ||
from typing import List, Optional | ||
|
||
from server.application.dataformats.queries import GetAllDataFormat | ||
from server.application.dataformats.commands import CreateDataFormat | ||
from server.application.dataformats.queries import GetAllDataFormat, GetDataFormatById | ||
from server.application.dataformats.views import DataFormatView | ||
from server.config.di import resolve | ||
from server.domain.dataformats.entities import DataFormat | ||
from server.domain.dataformats.repositories import DataFormatRepository | ||
|
||
|
||
async def get_all_dataformats(query: GetAllDataFormat) -> List[DataFormatView]: | ||
repository = resolve(DataFormatRepository) | ||
dataformats = await repository.get_all() | ||
return [DataFormatView(**dataformat.dict()) for dataformat in dataformats] | ||
|
||
|
||
async def create_dataformat(command: CreateDataFormat) -> Optional[int]: | ||
repository = resolve(DataFormatRepository) | ||
return await repository.insert(DataFormat(name=command.value)) | ||
|
||
|
||
async def get_by_id(query: GetDataFormatById) -> Optional[DataFormatView]: | ||
repository = resolve(DataFormatRepository) | ||
dataformat = await repository.get_by_id(id=query.id) | ||
|
||
if dataformat is not None: | ||
return DataFormatView(**dataformat.dict()) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,7 @@ | |
|
||
class GetAllDataFormat(Query[List[DataFormatView]]): | ||
pass | ||
|
||
|
||
class GetDataFormatById(Query[DataFormatView]): | ||
id: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pydantic import BaseModel, validator | ||
|
||
|
||
class CreateDataFormatValidationMixin(BaseModel): | ||
@validator("value", check_fields=False) | ||
def check_value_at_least_one(cls, value: str) -> str: | ||
if not value: | ||
raise ValueError("dataformat must have a value") | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
from server.application.dataformats.handlers import get_all_dataformats | ||
from server.application.dataformats.queries import GetAllDataFormat | ||
from server.application.dataformats.commands import CreateDataFormat | ||
from server.application.dataformats.handlers import ( | ||
create_dataformat, | ||
get_all_dataformats, | ||
get_by_id, | ||
) | ||
from server.application.dataformats.queries import GetAllDataFormat, GetDataFormatById | ||
from server.seedwork.application.modules import Module | ||
|
||
|
||
class DataFormatModule(Module): | ||
query_handlers = {GetAllDataFormat: get_all_dataformats} | ||
query_handlers = { | ||
GetAllDataFormat: get_all_dataformats, | ||
GetDataFormatById: get_by_id, | ||
} | ||
command_handlers = {CreateDataFormat: create_dataformat} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters