Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ dist/
build/
*.egg-info/

celerybeat-schedule
celerybeat-schedule
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Builder Stage
FROM python:3.12-slim AS builder

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev

COPY requirements.txt .

RUN pip install --upgrade pip
RUN pip install --prefix=/install -r requirements.txt


# Runtime Stage
FROM python:3.12-slim

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN groupadd -r appuser && useradd -r -g appuser appuser

COPY --from=builder /install /usr/local

COPY . .

RUN chown -R appuser:appuser /app

USER appuser

EXPOSE 8001

ENTRYPOINT ["/app/entrypoint.sh"]
9 changes: 3 additions & 6 deletions app/services/file_upload_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ def _parse_csv(text: str) -> list[dict]:


def _build_objects(rows, hs_code_file):
from app.models import Category

objects = []
skipped_blank = 0
category_cache: dict[str, Category] = {}

for row in rows:
hs_code = row.get("hs_code", "").strip()
description = row.get("description", "").strip()
hs_code = row.get("HS CODE", "").strip()
description = row.get("GOODS DESCRIPTION", "").strip()

if not hs_code or not description:
skipped_blank += 1
Expand All @@ -86,4 +83,4 @@ def _build_objects(rows, hs_code_file):
)
)

return objects, skipped_blank
return objects, skipped_blank
5 changes: 4 additions & 1 deletion app/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import path
from .views import HsCodeUploadView, HsCodeSearchView
from .views import HsCodeUploadView, HsCodeSearchView, HealthCheckView

urlpatterns = [
path(
Expand All @@ -8,4 +8,7 @@
name="hs-code-search",
),
path("hs-codes/upload/", HsCodeUploadView.as_view(), name="hscode-upload"),
path("health/",
HealthCheckView.as_view(),
name="health")
]
12 changes: 11 additions & 1 deletion app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def get_queryset(self):
q=q,
count=queryset.count(),
)

logger.info(queryset)

return queryset

Expand All @@ -90,4 +92,12 @@ def get_queryset(self):
q=self.request.query_params.get("q"),
error=str(e),
)
raise
raise


class HealthCheckView(APIView):
authentication_classes = []
permission_classes = []

def get(self, request):
return Response({"status": "healthy"})
Loading