Skip to content

Commit

Permalink
Merge pull request #1370 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
feat:(KKEM Views, User Views):response changed and logger added
  • Loading branch information
Aashish Vinu authored Oct 18, 2023
2 parents 51aee2e + 899bb94 commit 6750551
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -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()

Expand All @@ -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.'
Expand Down Expand Up @@ -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.'
Expand Down Expand Up @@ -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()

Expand All @@ -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.'
Expand Down Expand Up @@ -165,6 +171,7 @@ def validate_new_user(self, value):
def destroy(self, obj):
obj.delete()


class RoleDropDownSerializer(serializers.ModelSerializer):
class Meta:
model = Role
Expand Down
2 changes: 0 additions & 2 deletions api/dashboard/ig/dash_ig_serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from rest_framework import serializers

from db.task import InterestGroup
Expand Down
56 changes: 50 additions & 6 deletions api/integrations/kkem/kkem_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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()
1 change: 1 addition & 0 deletions api/top100_coders/top100_serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import serializers


class Top100CodersSerializer(serializers.Serializer):
rank = serializers.IntegerField()
first_name = serializers.CharField(source='user__first_name')
Expand Down

0 comments on commit 6750551

Please sign in to comment.