Skip to content

Commit

Permalink
Fix mapper schema imports + controller path refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PSNAppz committed Mar 28, 2024
1 parent 78fd427 commit 290a0c6
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 47 deletions.
Empty file added src/__init__.py
Empty file.
3 changes: 2 additions & 1 deletion src/openg2p_spar_mapper_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .config import Settings
from openg2p_fastapi_common.app import Initializer as BaseInitializer
from .controllers.g2pconnect import (
from .controllers import (
SyncMapperController,
AsyncMapperController,
)
Expand All @@ -17,6 +17,7 @@
AsyncRequestHelper,
AsyncResponseHelper,
)

_config = Settings.get_config()


Expand Down
6 changes: 3 additions & 3 deletions src/openg2p_spar_mapper_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Settings(BaseSettings):
"""
openapi_version: str = __version__

db_dbname: str = "spar-db"
db_dbname: str = "mapper-db"

default_callback_url: Optional[AnyUrl] = None
default_callback_timeout: int = 10
callback_sender_id: str = "spar.dev.openg2p.net"
callback_sender_id: str = "mapper.dev.openg2p.net"
2 changes: 2 additions & 0 deletions src/openg2p_spar_mapper_api/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .sync_mapper_controller import SyncMapperController
from .async_mapper_controller import AsyncMapperController
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
AsyncResponse,
AsyncCallbackRequest,
)
from openg2p_g2pconnect_common_lib.spar.schemas.link import (
from openg2p_g2pconnect_common_lib.mapper.schemas.link import (
SingleLinkResponse,
)
from ...config import Settings
from ...services import (
from src.openg2p_spar_mapper_api.config import Settings
from src.openg2p_spar_mapper_api.services import (
RequestValidation,
AsyncResponseHelper,
MapperService,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
Request,
SyncResponse,
)
from openg2p_g2pconnect_common_lib.spar.schemas.link import (
from openg2p_g2pconnect_common_lib.mapper.schemas.link import (
SingleLinkResponse,
)
from openg2p_g2pconnect_common_lib.spar.schemas.update import (
from openg2p_g2pconnect_common_lib.mapper.schemas.update import (
SingleUpdateResponse,
)
from openg2p_g2pconnect_common_lib.spar.schemas.resolve import (
from openg2p_g2pconnect_common_lib.mapper.schemas.resolve import (
SingleResolveResponse,
)
from ...services import RequestValidation, SyncResponseHelper, MapperService, RequestValidationException
from src.openg2p_spar_mapper_api.services import (
RequestValidation,
SyncResponseHelper,
MapperService,
RequestValidationException,
)


class SyncMapperController(BaseController):
Expand Down Expand Up @@ -55,8 +60,10 @@ async def link_sync(self, request: Request):
RequestValidation.validate_request(request)
RequestValidation.validate_link_request_header(request)
except RequestValidationException as e:
error_response = SyncResponseHelper.get_component().construct_error_sync_response(
request, e
error_response = (
SyncResponseHelper.get_component().construct_error_sync_response(
request, e
)
)
return error_response

Expand All @@ -74,51 +81,63 @@ async def update_sync(self, request: Request):
RequestValidation.validate_request(request)
RequestValidation.validate_update_request_header(request)
except RequestValidationException as e:
error_response = SyncResponseHelper.get_component().construct_error_sync_response(
request, e
error_response = (
SyncResponseHelper.get_component().construct_error_sync_response(
request, e
)
)
return error_response

single_update_responses: list[SingleUpdateResponse] = (
await self.mapper_service.update(request)
)
return SyncResponseHelper.get_component().construct_success_sync_update_response(
request,
single_update_responses,
return (
SyncResponseHelper.get_component().construct_success_sync_update_response(
request,
single_update_responses,
)
)

async def resolve_sync(self, request: Request):
try:
RequestValidation.validate_request(request)
RequestValidation.validate_resolve_request_header(request)
except RequestValidationException as e:
error_response = SyncResponseHelper.get_component().construct_error_sync_response(
request, e
error_response = (
SyncResponseHelper.get_component().construct_error_sync_response(
request, e
)
)
return error_response

single_resolve_responses: list[SingleResolveResponse] = (
await self.mapper_service.resolve(request)
)
return SyncResponseHelper.get_component().construct_success_sync_resolve_response(
request,
single_resolve_responses,
return (
SyncResponseHelper.get_component().construct_success_sync_resolve_response(
request,
single_resolve_responses,
)
)

async def unlink_sync(self, request: Request):
try:
RequestValidation.validate_request(request)
RequestValidation.validate_unlink_request_header(request)
except RequestValidationException as e:
error_response = SyncResponseHelper.get_component().construct_error_sync_response(
request, e
error_response = (
SyncResponseHelper.get_component().construct_error_sync_response(
request, e
)
)
return error_response

single_unlink_responses: list[SingleResolveResponse] = (
await self.mapper_service.unlink(request)
)
return SyncResponseHelper.get_component().construct_success_sync_unlink_response(
request,
single_unlink_responses,
return (
SyncResponseHelper.get_component().construct_success_sync_unlink_response(
request,
single_unlink_responses,
)
)
9 changes: 7 additions & 2 deletions src/openg2p_spar_mapper_api/services/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from openg2p_g2pconnect_common_lib.common.schemas import StatusEnum
from openg2p_g2pconnect_common_lib.spar.schemas import LinkStatusReasonCode,ResolveStatusReasonCode,UpdateStatusReasonCode,UnlinkStatusReasonCode

from openg2p_g2pconnect_common_lib.mapper.schemas import (
LinkStatusReasonCode,
ResolveStatusReasonCode,
UpdateStatusReasonCode,
UnlinkStatusReasonCode,
)


class LinkValidationException(Exception):
Expand Down Expand Up @@ -34,6 +38,7 @@ def __init__(self, message, status, validation_error_type: UnlinkStatusReasonCod
self.status: StatusEnum = status
self.validation_error_type: UnlinkStatusReasonCode = validation_error_type


class RequestValidationException(Exception):
# TODO : Add code
def __init__(self, code, message):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from openg2p_g2pconnect_common_lib.spar.schemas.resolve import (
from openg2p_g2pconnect_common_lib.mapper.schemas.resolve import (
SingleResolveRequest,
ResolveStatusReasonCode,
)

from openg2p_fastapi_common.service import BaseService
from openg2p_g2pconnect_common_lib.spar.schemas import (
from openg2p_g2pconnect_common_lib.mapper.schemas import (
LinkStatusReasonCode,
SingleUpdateRequest,
UpdateStatusReasonCode,
Expand All @@ -20,7 +20,7 @@
LinkValidationException,
UpdateValidationException,
ResolveValidationException,
UnlinkValidationException
UnlinkValidationException,
)
from ..models import IdFaMapping

Expand Down Expand Up @@ -139,18 +139,18 @@ async def validate_resolve_request(
validation_error_type=ResolveStatusReasonCode.rjct_reference_id_duplicate,
)
return None

@staticmethod
async def validate_unlink_request(
connection, single_unlink_request: SingleUnlinkRequest
) -> None:

if not single_unlink_request.id:
raise UnlinkValidationException(
message="ID is null",
validation_error_type=UnlinkValidationException.rjct_id_invalid,
)

if not single_unlink_request.fa:
raise UnlinkValidationException(
message="FA is null",
Expand All @@ -172,4 +172,4 @@ async def validate_unlink_request(
validation_error_type=UnlinkStatusReasonCode.rjct_reference_id_duplicate,
)

return None
return None
9 changes: 5 additions & 4 deletions src/openg2p_spar_mapper_api/services/mapper.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging
from datetime import datetime

from openg2p_g2pconnect_common_lib.spar.schemas.resolve import (
from openg2p_g2pconnect_common_lib.mapper.schemas.resolve import (
ResolveStatusReasonCode,
ResolveScope,
)

from openg2p_fastapi_common.context import dbengine
from openg2p_fastapi_common.service import BaseService
from openg2p_g2pconnect_common_lib.common.schemas import Request, StatusEnum
from openg2p_g2pconnect_common_lib.spar.schemas import (
from openg2p_g2pconnect_common_lib.mapper.schemas import (
SingleLinkResponse,
SingleUpdateResponse,
SingleResolveResponse,
Expand All @@ -20,7 +20,7 @@
UpdateStatusReasonCode,
UnlinkRequest,
SingleUnlinkResponse,
UnlinkStatusReasonCode
UnlinkStatusReasonCode,
)
from sqlalchemy.ext.asyncio import async_sessionmaker
from sqlalchemy import and_, select
Expand Down Expand Up @@ -413,6 +413,7 @@ def unlink_id_fa_mapping(single_unlink_request):
additional_info=single_unlink_request.additional_info,
active=True,
)

@staticmethod
def construct_single_unlink_response_for_success(single_unlink_request):
return SingleUnlinkResponse(
Expand All @@ -438,4 +439,4 @@ def construct_single_unlink_response_for_failure(single_unlink_request, error):
status_reason_message=error.message,
additional_info=None,
locale=single_unlink_request.locale,
)
)
2 changes: 1 addition & 1 deletion src/openg2p_spar_mapper_api/services/request_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from openg2p_g2pconnect_common_lib.common.schemas import (
Request,
)
from openg2p_g2pconnect_common_lib.spar.schemas.link import (
from openg2p_g2pconnect_common_lib.mapper.schemas.link import (
LinkRequest,
)

Expand Down
6 changes: 3 additions & 3 deletions src/openg2p_spar_mapper_api/services/response_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
AsyncCallbackRequestHeader,
AsyncAck,
)
from openg2p_g2pconnect_common_lib.spar.schemas import (
from openg2p_g2pconnect_common_lib.mapper.schemas import (
LinkResponse,
LinkRequest,
SingleLinkResponse,
Expand All @@ -36,7 +36,7 @@
LinkValidationException,
UpdateValidationException,
ResolveValidationException,
UnlinkValidationException
UnlinkValidationException,
)


Expand Down Expand Up @@ -180,7 +180,7 @@ def construct_success_sync_unlink_response(
request: Request,
single_unlink_responses: list[SingleUnlinkResponse],
) -> SyncResponse:
unlinkRequest: UnlinkRequest = UnlinkRequest.model_validate(request.message)
unlinkRequest: UnlinkRequest = UnlinkRequest.model_validate(request.message)
unlinkResponse: UnlinkResponse = UnlinkResponse(
transaction_id=unlinkRequest.transaction_id,
correlation_id=None,
Expand Down

0 comments on commit 290a0c6

Please sign in to comment.