-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: API for querying asset field values (#236)
* build: Build CI/CD pipeline using github actions (#228) * fix: Only show assets which are not deleted * fix: Fix Pagination bug * build: Dockerize backend and frontend services * build: Add production deployment script * chore: Remove environment files from git tracking * Feat charts (#230) * feat:charts * feat: Add new chart to view individual asset type count * fix: changed namings * feat: Add test to backend assetype and assetview * feat: added new chart * feat: Add new chart cards for improved dashboard user experience * Add bar chart component which feature individual asset count and card components that show various data for enhanced ux experience * fix: fixes to some code lines * fix: Fix dashboard ui padding and margin * fixes * fix: AssetView fix * fix: ui * fix: code structure * feat: new ui design for charts * feat:making chart responsive * fix charts * feat-charts * feat-charts * Feat charts (#231) * feat:charts * feat: Add new chart to view individual asset type count * fix: changed namings * feat: Add test to backend assetype and assetview * feat: added new chart * feat: Add new chart cards for improved dashboard user experience * Add bar chart component which feature individual asset count and card components that show various data for enhanced ux experience * fix: fixes to some code lines * fix: Fix dashboard ui padding and margin * fixes * fix: AssetView fix * fix: ui * fix: code structure * feat: new ui design for charts * feat:making chart responsive * fix charts * feat-charts * feat-charts * revert: reverted back to old files due to crashing * fix * Feat charts (#233) * feat:charts * feat: Add new chart to view individual asset type count * fix: changed namings * feat: Add test to backend assetype and assetview * feat: added new chart * feat: Add new chart cards for improved dashboard user experience * Add bar chart component which feature individual asset count and card components that show various data for enhanced ux experience * fix: fixes to some code lines * fix: Fix dashboard ui padding and margin * fixes * fix: AssetView fix * fix: ui * fix: code structure * feat: new ui design for charts * feat:making chart responsive * fix charts * feat-charts * feat-charts * revert: reverted back to old files due to crashing * fix * fix: responsiveness of dashboard * feat:Add new UI display to charts when no data is found * feat: Create API for getting unique values of different fields in the asset table (#234) * fix: Only show assets which are not deleted * fix: Fix Pagination bug * build: Dockerize backend and frontend services * feat: Create API for getting unique values of different fields in asset table * fix: Change sidebar tooltip message (#235) * fix: Only show assets which are not deleted * fix: Fix Pagination bug * build: Dockerize backend and frontend services * fix: Change tooltip message in download menu item in sidebar --------- Co-authored-by: Aidrin Varghese <[email protected]>
- Loading branch information
1 parent
14828c1
commit 76c7da3
Showing
25 changed files
with
397 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
DJANGO_SECRET_KEY=1)e@l)h^ipetx7m9e)2agttg@vn4kwn%$4mlwf#m^3o)r@amkz | ||
|
||
DB_NAME=asset_management_db | ||
DB_USER=root | ||
DB_PORT=3306 | ||
|
||
DB_PASSWORD=experion@123 | ||
DB_HOST=mysql-db-service | ||
|
||
ALLOWED_HOSTS=localhost,127.0.0.1 | ||
|
||
EMAIL_HOST_USER=[email protected] | ||
EMAIL_HOST_PASSWORD=ovbh xecf yztb wopx | ||
EMAIL_PORT=587 | ||
EMAIL_USE_TLS=True |
114 changes: 114 additions & 0 deletions
114
exam_django/asset/service/asset_crud_service/asset_field_value_query_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import json | ||
from rest_framework import status | ||
from django.db.models import Q | ||
from rest_framework.pagination import LimitOffsetPagination | ||
|
||
from asset.service.asset_crud_service.asset_query_abstract import AssetQueryAbstract | ||
from asset.models.asset import Asset | ||
from asset.serializers.asset_serializer import AssetReadSerializer | ||
from utils.table_util import TableUtil | ||
from exceptions import NotAcceptableOperationException, NotFoundException | ||
from messages import ( | ||
ASSET_FIELD_NOT_FILTERABLE, | ||
ASSET_FIELD_NOT_FOUND, | ||
ASSET_FIELD_VALUE_LIST_SUCCESSFULLY_RETRIEVED, | ||
ASSET_FIELD_VALUE_QUERY_PARAM_NOT_FOUND, | ||
) | ||
|
||
|
||
class AssetFieldValueQueryService(AssetQueryAbstract): | ||
|
||
# Used for autocomplete functionality | ||
def get_asset_details(self, serializer, request): | ||
|
||
self.pagination = LimitOffsetPagination() | ||
queryset = Asset.objects.all() | ||
|
||
unfilterable_fields = [ | ||
"asset_uuid", | ||
"version", | ||
"asset_category", | ||
"date_of_purchase", | ||
"status", | ||
"notes", | ||
"approval_status_message", | ||
"warranty_period", | ||
"asset_detail_status", | ||
"assign_status", | ||
"created_at", | ||
"updated_at", | ||
] | ||
|
||
foreign_fields = [ | ||
"asset_type", | ||
"custodian", | ||
"location", | ||
"invoice_location", | ||
"business_unit", | ||
"memory", | ||
"approved_by", | ||
"requester", | ||
] | ||
|
||
asset_field_value_filter = request.query_params.get("asset_field_value_filter") | ||
if asset_field_value_filter: | ||
asset_field_object = json.loads(asset_field_value_filter) | ||
asset_field_name = list(asset_field_object.keys())[0] | ||
asset_field_value = asset_field_object.get(asset_field_name) | ||
|
||
if ( | ||
asset_field_name in unfilterable_fields | ||
or asset_field_name in foreign_fields | ||
): | ||
raise NotAcceptableOperationException( | ||
{}, | ||
ASSET_FIELD_NOT_FILTERABLE, | ||
status.HTTP_406_NOT_ACCEPTABLE, | ||
) | ||
|
||
if TableUtil.field_exists_in_table(Asset, asset_field_name): | ||
filterConditionQObject = Q( | ||
**{asset_field_name + "__icontains": asset_field_value} | ||
) | ||
queryset = queryset.filter(filterConditionQObject) | ||
else: | ||
raise NotFoundException( | ||
{}, | ||
ASSET_FIELD_NOT_FOUND, | ||
status.HTTP_406_NOT_ACCEPTABLE, | ||
) | ||
|
||
fields_to_select = [asset_field_name] | ||
queryset = queryset.distinct() | ||
queryset = queryset.values(*fields_to_select) | ||
|
||
serializer_class = type( | ||
"DynamicSerializer", | ||
(AssetReadSerializer,), | ||
{ | ||
"Meta": type( | ||
"Meta", (), {"model": Asset, "fields": fields_to_select} | ||
) | ||
}, | ||
) | ||
|
||
page = self.pagination.paginate_queryset(queryset, request) | ||
if page is not None: | ||
serializer = serializer_class(page, many=True) | ||
serializer = self.pagination.get_paginated_response(serializer.data) | ||
|
||
else: | ||
serializer = serializer_class(queryset, many=True) | ||
|
||
return ( | ||
serializer.data, | ||
ASSET_FIELD_VALUE_LIST_SUCCESSFULLY_RETRIEVED, | ||
status.HTTP_200_OK, | ||
) | ||
|
||
else: | ||
raise NotFoundException( | ||
{}, | ||
ASSET_FIELD_VALUE_QUERY_PARAM_NOT_FOUND, | ||
status.HTTP_406_NOT_ACCEPTABLE, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.