Django REST API Endpoints
Relevant source files
The following files were used as context for generating this wiki page:
Django REST API endpoints provide a structured interface for the Angular frontend to access the products and solutions catalog. The system uses the Django REST Framework (DRF) to serve hardware data, including CCTV, EPABX, and biometric systems, while supporting administrative bulk imports via JSON.
The backend architecture facilitates a transition from mock assets to a dynamic API. The frontend ProductService consumes these endpoints to populate the catalog and detail pages, ensuring consistent data flow across the application.
Sources: implementation_plan.md:92-105, sunrise-backend/config/settings.py:115-124
REST Framework Configuration
The API operates under a specific configuration defined in the project settings. It uses standard filtering, searching, and ordering backends to manage large datasets.
| Configuration Item | Value / Description |
|---|---|
| Default Filter Backends | DjangoFilterBackend, SearchFilter, OrderingFilter |
| Pagination Class | PageNumberPagination |
| Default Page Size | 50 items per page |
| CORS Origins | http://localhost:4200, http://localhost:4000 |
Sources: sunrise-backend/config/settings.py:115-124, sunrise-backend/config/settings.py:109-113
Data Models and Schema
The API exposes entities structured within the products app. These models define the data contract between the Django backend and the Angular client.
The diagram represents the relational structure of the product catalog managed by the API.
Sources: sunrise-backend/products/models.py:7-123
Key Entity Fields
| Entity | Field | Type | Description |
|---|---|---|---|
| Category | icon_class | CharField | CSS class for frontend icons (e.g., flaticon-camera). |
| Brand | logo | ImageField | Brand identity image stored in brands/. |
| Product | services_offered | JSONField | Array of strings (Sales, Installation, AMC, Repair). |
| ProductSpec | key | CharField | Technical attribute name (e.g., "Resolution"). |
Sources: sunrise-backend/products/models.py:13-120
Bulk Data Integration
The system includes a specialized endpoint for administrative data management. The upload-json/ view allows administrators to bypass manual entry by importing structured JSON files.
JSON Import Workflow
The following sequence describes the process of importing data into the API:
The sequence shows how the administrative interface processes bulk data to populate the API's underlying database.
Sources: sunrise-backend/products/admin.py:86-173, sunrise-backend/products/templates/admin/products/product/upload_json.html:20-55
Frontend Consumption
The Angular ProductService is designed to be "backend-ready." While initial development uses a local JSON asset, the service architecture supports a seamless swap to the Django REST API.
The flowchart illustrates the swappable data source architecture in the Angular frontend.
Sources: implementation_plan.md:92-110, sunrise-angular/src/app/core/services/product.service.ts
Dynamic Endpoint Requirements
The API must support the following frontend query patterns:
- Catalog Fetching: Returning a
ProductCatalogResponsecontaining the fullProduct[]array. - Filtering: Responding to query parameters such as
?category=cctv&brand=cp-plus. - Detail Retrieval: Providing data for a specific product based on a unique slug (e.g.,
/products/:category/:slug).
Sources: implementation_plan.md:65-72, implementation_plan.md:144-156
Summary
The Django REST API Endpoints serve as the backbone for the Sunrise Communication catalog. By combining DRF's filtering capabilities with custom administrative import tools, the system provides a scalable method for managing and delivering technical hardware specifications to the machine-to-machine and user-facing layers of the application.