generated from ensaremirerol/nextjs-fastapi-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1848f97
commit b36359f
Showing
10 changed files
with
474 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
98 changes: 98 additions & 0 deletions
98
server/facades/workspace/mapping/create_mapping_in_workspace_facade.py
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,98 @@ | ||
from uuid import uuid4 | ||
|
||
from kink import inject | ||
|
||
from server.facades import ( | ||
BaseFacade, | ||
FacadeResponse, | ||
) | ||
from server.models.mapping import MappingGraph | ||
from server.models.source import SourceType | ||
from server.service_protocols.mapping_service_protocol import ( | ||
MappingServiceProtocol, | ||
) | ||
from server.services.core.workspace_metadata_service import ( | ||
WorkspaceMetadataServiceProtocol, | ||
) | ||
from server.services.local.local_source_service import ( | ||
SourceServiceProtocol, | ||
) | ||
from server.services.local.local_workspace_service import ( | ||
WorkspaceServiceProtocol, | ||
) | ||
|
||
|
||
@inject | ||
class CreateMappingInWorkspaceFacade(BaseFacade): | ||
def __init__( | ||
self, | ||
workspace_metadata_service: WorkspaceMetadataServiceProtocol, | ||
workspace_service: WorkspaceServiceProtocol, | ||
mapping_service: MappingServiceProtocol, | ||
source_service: SourceServiceProtocol, | ||
): | ||
super().__init__() | ||
self.workspace_metadata_service: WorkspaceMetadataServiceProtocol = workspace_metadata_service | ||
self.workspace_service: WorkspaceServiceProtocol = ( | ||
workspace_service | ||
) | ||
self.mapping_service: MappingServiceProtocol = ( | ||
mapping_service | ||
) | ||
self.source_service: SourceServiceProtocol = ( | ||
source_service | ||
) | ||
|
||
@BaseFacade.error_wrapper | ||
def execute( | ||
self, | ||
workspace_id: str, | ||
name: str, | ||
description: str, | ||
source_content: bytes, | ||
source_type: SourceType, | ||
extra: dict, | ||
) -> FacadeResponse: | ||
self.logger.info( | ||
f"Creating mapping in workspace {workspace_id} with name {name}" | ||
) | ||
self.logger.info( | ||
f"Retrieving workspace {workspace_id}" | ||
) | ||
workspace_metadata = self.workspace_metadata_service.get_workspace_metadata( | ||
workspace_id, | ||
) | ||
workspace = self.workspace_service.get_workspace( | ||
workspace_metadata.location, | ||
) | ||
self.logger.info("Creating source") | ||
source = self.source_service.create_source( | ||
type=source_type, | ||
content=source_content, | ||
extra=extra, | ||
) | ||
self.logger.info("Creating mapping") | ||
mapping_graph_uuid = uuid4().hex | ||
mapping_graph = MappingGraph( | ||
uuid=mapping_graph_uuid, | ||
name=name, | ||
description=description, | ||
source_id=source, | ||
nodes=[], | ||
edges=[], | ||
) | ||
self.mapping_service.create_mapping(mapping_graph) | ||
self.logger.info("Mapping created") | ||
workspace.copy_with( | ||
mappings=workspace.mappings | ||
+ [mapping_graph_uuid], | ||
) | ||
self.workspace_service.update_workspace( | ||
workspace, | ||
) | ||
self.logger.info("Workspace updated") | ||
return FacadeResponse( | ||
status=202, | ||
message="Mapping created", | ||
data=mapping_graph, | ||
) |
111 changes: 111 additions & 0 deletions
111
server/facades/workspace/mapping/delete_mapping_from_workspace_facade.py
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,111 @@ | ||
from kink import inject | ||
|
||
from server.exceptions import ErrCodes | ||
from server.facades import ( | ||
BaseFacade, | ||
FacadeResponse, | ||
ServerException, | ||
) | ||
from server.service_protocols.mapping_service_protocol import ( | ||
MappingServiceProtocol, | ||
) | ||
from server.services.core.workspace_metadata_service import ( | ||
WorkspaceMetadataServiceProtocol, | ||
) | ||
from server.services.local.local_source_service import ( | ||
SourceServiceProtocol, | ||
) | ||
from server.services.local.local_workspace_service import ( | ||
WorkspaceServiceProtocol, | ||
) | ||
|
||
|
||
@inject | ||
class DeleteMappingFromWorkspaceFacade(BaseFacade): | ||
def __init__( | ||
self, | ||
workspace_metadata_service: WorkspaceMetadataServiceProtocol, | ||
workspace_service: WorkspaceServiceProtocol, | ||
mapping_service: MappingServiceProtocol, | ||
source_service: SourceServiceProtocol, | ||
): | ||
super().__init__() | ||
self.workspace_metadata_service: WorkspaceMetadataServiceProtocol = workspace_metadata_service | ||
self.workspace_service: WorkspaceServiceProtocol = ( | ||
workspace_service | ||
) | ||
self.mapping_service: MappingServiceProtocol = ( | ||
mapping_service | ||
) | ||
self.source_service: SourceServiceProtocol = ( | ||
source_service | ||
) | ||
|
||
@BaseFacade.error_wrapper | ||
def execute( | ||
self, | ||
workspace_id: str, | ||
mapping_id: str, | ||
) -> FacadeResponse: | ||
self.logger.info( | ||
f"Dropping mapping {mapping_id} from workspace {workspace_id}" | ||
) | ||
self.logger.info( | ||
f"Retrieving workspace {workspace_id}" | ||
) | ||
workspace_metadata = self.workspace_metadata_service.get_workspace_metadata( | ||
workspace_id, | ||
) | ||
workspace = self.workspace_service.get_workspace( | ||
workspace_metadata.location, | ||
) | ||
|
||
if mapping_id not in workspace.mappings: | ||
self.logger.error( | ||
f"Mapping {mapping_id} not found in workspace {workspace_id}" | ||
) | ||
raise ServerException( | ||
f"Mapping {mapping_id} not found in workspace {workspace_id}", | ||
code=ErrCodes.MAPPING_NOT_FOUND, | ||
) | ||
|
||
self.logger.info(f"Retrieving mapping {mapping_id}") | ||
|
||
mapping = self.mapping_service.get_mapping( | ||
mapping_id, | ||
) | ||
|
||
self.logger.info( | ||
f"Deleting source {mapping.source_id}" | ||
) | ||
|
||
self.source_service.delete_source( | ||
mapping.source_id, | ||
) | ||
|
||
self.logger.info(f"Deleting mapping {mapping_id}") | ||
|
||
self.mapping_service.delete_mapping( | ||
mapping_id, | ||
) | ||
|
||
self.logger.info( | ||
f"Removing mapping {mapping_id} from workspace {workspace_id}" | ||
) | ||
|
||
new_model = workspace.copy_with( | ||
mappings=[ | ||
m | ||
for m in workspace.mappings | ||
if m != mapping_id | ||
], | ||
) | ||
|
||
self.workspace_service.update_workspace( | ||
new_model, | ||
) | ||
|
||
return FacadeResponse( | ||
status=200, | ||
message=f"Mapping {mapping_id} dropped from workspace {workspace_id}", | ||
) |
70 changes: 70 additions & 0 deletions
70
server/facades/workspace/mapping/get_mappings_in_workspace_facade.py
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,70 @@ | ||
from kink import inject | ||
|
||
from server.facades import ( | ||
BaseFacade, | ||
FacadeResponse, | ||
) | ||
from server.service_protocols.mapping_service_protocol import ( | ||
MappingServiceProtocol, | ||
) | ||
from server.services.core.workspace_metadata_service import ( | ||
WorkspaceMetadataServiceProtocol, | ||
) | ||
from server.services.local.local_source_service import ( | ||
SourceServiceProtocol, | ||
) | ||
from server.services.local.local_workspace_service import ( | ||
WorkspaceServiceProtocol, | ||
) | ||
|
||
|
||
@inject | ||
class GetMappingsInWorkspaceFacade(BaseFacade): | ||
def __init__( | ||
self, | ||
workspace_metadata_service: WorkspaceMetadataServiceProtocol, | ||
workspace_service: WorkspaceServiceProtocol, | ||
mapping_service: MappingServiceProtocol, | ||
source_service: SourceServiceProtocol, | ||
): | ||
super().__init__() | ||
self.workspace_metadata_service: WorkspaceMetadataServiceProtocol = workspace_metadata_service | ||
self.workspace_service: WorkspaceServiceProtocol = ( | ||
workspace_service | ||
) | ||
self.mapping_service: MappingServiceProtocol = ( | ||
mapping_service | ||
) | ||
self.source_service: SourceServiceProtocol = ( | ||
source_service | ||
) | ||
|
||
@BaseFacade.error_wrapper | ||
def execute( | ||
self, | ||
workspace_id: str, | ||
) -> FacadeResponse: | ||
self.logger.info( | ||
f"Retrieving mappings in workspace {workspace_id}" | ||
) | ||
self.logger.info( | ||
f"Retrieving workspace {workspace_id}" | ||
) | ||
workspace_metadata = self.workspace_metadata_service.get_workspace_metadata( | ||
workspace_id, | ||
) | ||
workspace = self.workspace_service.get_workspace( | ||
workspace_metadata.location, | ||
) | ||
self.logger.info("Retrieving mappings") | ||
|
||
mappings = [ | ||
self.mapping_service.get_mapping(mapping_id) | ||
for mapping_id in workspace.mappings | ||
] | ||
|
||
return FacadeResponse( | ||
status=200, | ||
message=f"Retrieved mappings in workspace {workspace_id}", | ||
data=mappings, | ||
) |
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,38 @@ | ||
from kink import inject | ||
|
||
from server.facades import ( | ||
BaseFacade, | ||
FacadeResponse, | ||
) | ||
from server.models.mapping import MappingGraph | ||
from server.service_protocols.mapping_service_protocol import ( | ||
MappingServiceProtocol, | ||
) | ||
|
||
|
||
@inject | ||
class UpdateMappingFacade(BaseFacade): | ||
def __init__( | ||
self, | ||
mapping_service: MappingServiceProtocol, | ||
): | ||
super().__init__() | ||
self.mapping_service: MappingServiceProtocol = ( | ||
mapping_service | ||
) | ||
|
||
@BaseFacade.error_wrapper | ||
def execute( | ||
self, | ||
mapping_id: str, | ||
mapping_graph: MappingGraph, | ||
) -> FacadeResponse: | ||
self.logger.info(f"Updating mapping {mapping_id}") | ||
self.mapping_service.update_mapping( | ||
mapping_id, | ||
mapping_graph, | ||
) | ||
return FacadeResponse( | ||
status=200, | ||
message=f"Mapping {mapping_id} updated", | ||
) |
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
Oops, something went wrong.