diff --git a/api/dashboard/dynamic_management/dynamic_management_serializer.py b/api/dashboard/dynamic_management/dynamic_management_serializer.py index cc7cbe94..5cadaa1e 100644 --- a/api/dashboard/dynamic_management/dynamic_management_serializer.py +++ b/api/dashboard/dynamic_management/dynamic_management_serializer.py @@ -7,6 +7,7 @@ from utils.utils import DateTimeUtils from utils.types import ManagementType + class DynamicRoleCreateSerializer(serializers.ModelSerializer): type = serializers.CharField(required=True, error_messages={ 'required': 'type field must not be left blank.' @@ -43,7 +44,8 @@ def validate_type(self, value): if value not in [type for type in ManagementType.get_all_values()]: raise serializers.ValidationError("Enter a valid type") return value - + + class DynamicRoleListSerializer(serializers.ModelSerializer): roles = serializers.SerializerMethodField() @@ -56,6 +58,7 @@ class Meta: model = DynamicRole fields = ["type", "roles"] + class DynamicRoleUpdateSerializer(serializers.ModelSerializer): new_role = serializers.CharField(required=True, error_messages={ 'required': 'new_role field must not be left blank.' @@ -83,6 +86,7 @@ def validate_new_role(self, value): def destroy(self, obj): obj.delete() + class DynamicUserCreateSerializer(serializers.ModelSerializer): type = serializers.CharField(required=True, error_messages={ 'required': 'type field must not be left blank.' @@ -119,7 +123,8 @@ def validate_type(self, value): if value not in [type for type in ManagementType.get_all_values()]: raise serializers.ValidationError("Enter a valid type") return value - + + class DynamicUserListSerializer(serializers.ModelSerializer): users = serializers.SerializerMethodField() @@ -137,6 +142,7 @@ class Meta: model = DynamicUser fields = ["type", "users"] + class DynamicUserUpdateSerializer(serializers.ModelSerializer): new_user = serializers.CharField(required=True, error_messages={ 'required': 'new_user field must not be left blank.' @@ -165,6 +171,7 @@ def validate_new_user(self, value): def destroy(self, obj): obj.delete() + class RoleDropDownSerializer(serializers.ModelSerializer): class Meta: model = Role diff --git a/api/dashboard/ig/dash_ig_serializer.py b/api/dashboard/ig/dash_ig_serializer.py index 9b9098dc..9978072e 100644 --- a/api/dashboard/ig/dash_ig_serializer.py +++ b/api/dashboard/ig/dash_ig_serializer.py @@ -1,5 +1,3 @@ -import uuid - from rest_framework import serializers from db.task import InterestGroup diff --git a/api/integrations/kkem/kkem_views.py b/api/integrations/kkem/kkem_views.py index 5ee8b28f..aa1a8902 100644 --- a/api/integrations/kkem/kkem_views.py +++ b/api/integrations/kkem/kkem_views.py @@ -1,5 +1,6 @@ from datetime import datetime +import logging import requests from django.db.models import F, Prefetch from rest_framework.views import APIView @@ -15,6 +16,8 @@ from . import kkem_helper from .kkem_serializer import KKEMAuthorization, KKEMUserSerializer +logger = logging.getLogger(__name__) + class KKEMBulkKarmaAPI(APIView): @integrations_helper.token_required(IntegrationType.KKEM.value) @@ -119,8 +122,16 @@ def post(self, request): general_message="We've set up your authorization! Please check your email for further instructions." ).get_success_response() + except ValueError as e: + return CustomResponse( + general_message=str(e) + ).get_failure_response() + except Exception as e: - return CustomResponse(general_message=str(e)).get_failure_response() + logger.exception("An error occurred: %s", str(e)) + return CustomResponse( + general_message="Somthing went wrong" + ).get_failure_response() def patch(self, request, token): try: @@ -145,8 +156,16 @@ def patch(self, request, token): general_message="Invalid or missing Token" ).get_failure_response() + except ValueError as e: + return CustomResponse( + general_message=str(e) + ).get_failure_response() + except Exception as e: - return CustomResponse(general_message=str(e)).get_failure_response() + logger.exception("An error occurred: %s", str(e)) + return CustomResponse( + general_message="Somthing went wrong" + ).get_failure_response() class KKEMIntegrationLogin(APIView): @@ -178,11 +197,20 @@ def post(self, request): response["data"] = serialized_set.data return CustomResponse( - general_message=general_message, response=response + general_message=general_message, + response=response ).get_success_response() + except ValueError as e: + return CustomResponse( + general_message=str(e) + ).get_failure_response() + except Exception as e: - return CustomResponse(general_message=str(e)).get_failure_response() + logger.exception("An error occurred: %s", str(e)) + return CustomResponse( + general_message="Somthing went wrong" + ).get_failure_response() class KKEMdetailsFetchAPI(APIView): @@ -215,8 +243,16 @@ def get(self, request, encrypted_data): return CustomResponse(response=result_data).get_success_response() + except ValueError as e: + return CustomResponse( + general_message=str(e) + ).get_failure_response() + except Exception as e: - return CustomResponse(general_message=str(e)).get_failure_response() + logger.exception("An error occurred: %s", str(e)) + return CustomResponse( + general_message="Somthing went wrong" + ).get_failure_response() class KKEMUserStatusAPI(APIView): @@ -227,5 +263,13 @@ def get(self, request, encrypted_data): response={"muid": details["mu_id"][0] if "mu_id" in details else None} ).get_success_response() + except ValueError as e: + return CustomResponse( + general_message=str(e) + ).get_failure_response() + except Exception as e: - return CustomResponse(general_message=str(e)).get_failure_response() + logger.exception("An error occurred: %s", str(e)) + return CustomResponse( + general_message="Somthing went wrong" + ).get_failure_response() diff --git a/api/top100_coders/top100_serializer.py b/api/top100_coders/top100_serializer.py index a164ade4..d96faef5 100644 --- a/api/top100_coders/top100_serializer.py +++ b/api/top100_coders/top100_serializer.py @@ -1,5 +1,6 @@ from rest_framework import serializers + class Top100CodersSerializer(serializers.Serializer): rank = serializers.IntegerField() first_name = serializers.CharField(source='user__first_name')