Skip to content

Commit

Permalink
chore: move requestHandler to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke committed Nov 26, 2024
1 parent c9be2b6 commit ba803f7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from django.core.management.base import BaseCommand
from django.utils import timezone

from applications.services.ahjo.request_handler import AhjoRequestHandler
from applications.services.ahjo_authentication import AhjoTokenExpiredException
from applications.services.ahjo_integration import AhjoRequestHandler, get_token
from applications.services.ahjo_integration import get_token

LOGGER = logging.getLogger(__name__)

Expand Down
28 changes: 28 additions & 0 deletions backend/benefit/applications/services/ahjo/request_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import List, Union

from applications.enums import AhjoRequestType
from applications.services.ahjo.enums import AhjoSettingName
from applications.services.ahjo.setting_response_handler import AhjoResponseHandler
from applications.services.ahjo_authentication import AhjoToken
from applications.services.ahjo_client import (
AhjoApiClient,
AhjoDecisionMakerRequest,
AhjoRequest,
)


class AhjoRequestHandler:
def __init__(self, ahjo_token: AhjoToken, ahjo_request_type: AhjoRequest):
self.ahjo_token = ahjo_token
self.ahjo_request_type = ahjo_request_type

def handle_request_without_application(self):
if self.ahjo_request_type == AhjoRequestType.GET_DECISION_MAKER:
self.get_decision_maker_from_ahjo()

def get_decision_maker_from_ahjo(self) -> Union[List, None]:
ahjo_client = AhjoApiClient(self.ahjo_token, AhjoDecisionMakerRequest())
_, result = ahjo_client.send_request_to_ahjo()
AhjoResponseHandler.handle_ahjo_query_response(
setting_name=AhjoSettingName.DECISION_MAKER, data=result
)
29 changes: 2 additions & 27 deletions backend/benefit/applications/services/ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
from collections import defaultdict
from dataclasses import dataclass
from io import BytesIO
from typing import Dict, List, Optional, Tuple, Union
from typing import List, Optional, Tuple, Union

import jinja2
import pdfkit
from django.conf import settings
from django.core.exceptions import (
ImproperlyConfigured,
ObjectDoesNotExist,
)
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.core.files.base import ContentFile
from django.db.models import QuerySet
from django.urls import reverse
from lxml import etree
from lxml.etree import XMLSchemaParseError, XMLSyntaxError

from applications.enums import (
AhjoRequestType,
AhjoStatus as AhjoStatusEnum,
ApplicationStatus,
AttachmentType,
Expand All @@ -33,7 +29,6 @@
ApplicationBatch,
Attachment,
)
from applications.services.ahjo.enums import AhjoSettingName
from applications.services.ahjo.exceptions import (
DecisionProposalAlreadyAcceptedError,
DecisionProposalError,
Expand All @@ -43,11 +38,9 @@
AhjoAddRecordsRequest,
AhjoApiClient,
AhjoDecisionDetailsRequest,
AhjoDecisionMakerRequest,
AhjoDecisionProposalRequest,
AhjoDeleteCaseRequest,
AhjoOpenCaseRequest,
AhjoRequest,
AhjoSubscribeDecisionRequest,
AhjoUpdateRecordsRequest,
)
Expand All @@ -68,7 +61,6 @@
)
from companies.models import Company

from applications.services.ahjo.setting_response_handler import AhjoResponseHandler

@dataclass
class ExportFileInfo:
Expand Down Expand Up @@ -664,20 +656,3 @@ def get_decision_details_from_ahjo(
ahjo_request = AhjoDecisionDetailsRequest(application)
ahjo_client = AhjoApiClient(ahjo_token, ahjo_request)
return ahjo_client.send_request_to_ahjo()


class AhjoRequestHandler:
def __init__(self, ahjo_token: AhjoToken, ahjo_request_type: AhjoRequest):
self.ahjo_token = ahjo_token
self.ahjo_request_type = ahjo_request_type

def handle_request_without_application(self):
if self.ahjo_request_type == AhjoRequestType.GET_DECISION_MAKER:
self.get_decision_maker_from_ahjo()

def get_decision_maker_from_ahjo(self) -> Union[List, None]:
ahjo_client = AhjoApiClient(self.ahjo_token, AhjoDecisionMakerRequest())
_, result = ahjo_client.send_request_to_ahjo()
AhjoResponseHandler.handle_ahjo_query_response(
setting_name=AhjoSettingName.DECISION_MAKER, data=result
)

0 comments on commit ba803f7

Please sign in to comment.