Skip to content

Commit

Permalink
Merge pull request #166 from uktrade/feature/fix-document-link
Browse files Browse the repository at this point in the history
remove: Remove TempCacheDataResponseViewSet and Improve JSON Parsing
  • Loading branch information
hareshkainthdbt authored Jan 21, 2025
2 parents 7f04ce3 + 9b285ef commit b60b682
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
23 changes: 12 additions & 11 deletions app/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ def document(request: HttpRequest, id) -> HttpResponse:

# Parse the related_legislation field
related_legislation_str = context["result"].related_legislation
try:
related_legislation_double_quotes = (
related_legislation_str.replace("'", '"')
)
related_legislation_json = json.loads(
related_legislation_double_quotes
)
context["result"].related_legislation = related_legislation_json
except json.JSONDecodeError as e:
logger.error(f"JSON decoding error: {e}")
context["result"].related_legislation = []

if related_legislation_str is not None:
try:
related_legislation_json = json.loads(
related_legislation_str.replace("'", '"')
)
context["result"].related_legislation = (
related_legislation_json
)
except json.JSONDecodeError as e:
logger.error(f"JSON decoding error: {e}")
context["error"] = f"error fetching details: {e}"
context["result"].related_legislation = []
except Exception as e:
logger.error("error fetching details: %s", e)
context["error"] = f"error fetching details: {e}"
Expand Down
25 changes: 0 additions & 25 deletions fbr/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import app.core.views as core_views
import app.search.views as search_views

from app.search.models import DataResponseModel
from app.search.utils.documents import clear_all_documents
from app.search.utils.search import get_publisher_names, search

urls_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -76,34 +74,11 @@ def publishers(self, request, *args, **kwargs):
)


class TempCacheDataResponseViewSet(viewsets.ViewSet):
@action(detail=False, methods=["get"], url_path="cache")
def read_cachetempdata(self, request, *args, **kwargs):
try:
from fbr.tempcache import CACHETEMPDATA

clear_all_documents()

for record in CACHETEMPDATA:
DataResponseModel.objects.create(**record)

return Response(
{"message": "data inserted successfully"},
status=status.HTTP_201_CREATED,
)
except Exception as e:
return Response(
{"message": f"error reading CACHETEMPDATA: {e}"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)


# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()

router.register(r"v1", DataResponseViewSet, basename="search")
router.register(r"v1/retrieve", PublishersViewSet, basename="publishers")
router.register(r"v1/temp", TempCacheDataResponseViewSet, basename="cache")

urlpatterns = [
path("api/", include(router.urls)),
Expand Down

0 comments on commit b60b682

Please sign in to comment.