Skip to content

Commit

Permalink
Merge pull request #1362 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
kkem ig issue
  • Loading branch information
adnankattekaden authored Oct 18, 2023
2 parents f203830 + 5c43884 commit 853b080
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
26 changes: 14 additions & 12 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from collections import defaultdict

from django.db.models import Sum, F, Case, When, Value, CharField, Count, Q
from django.db.models.functions import Coalesce
from rest_framework.views import APIView
Expand All @@ -11,28 +13,28 @@
from utils.types import IntegrationType, OrganizationType
from utils.utils import CommonUtils
from .serializer import StudentInfoSerializer
from collections import defaultdict


class LcDashboardAPI(APIView):

def get(self, request):
date = request.GET.get('date')
if date:
learning_circle_count = LearningCircle.objects.filter(created_at__gt=date).count()
total_no_enrollment = UserCircleLink.objects.filter(accepted=True, created_at__gt=date).count()
circle_count_by_ig = LearningCircle.objects.filter(created_at__gt=date).values(
ig_name=F('ig__name')).annotate(total_circles=Count('id'),
total_users=Count('ig__learningcircle__usercirclelink__user',
distinct=True))
unique_user_count = UserCircleLink.objects.filter(accepted=True, created_at__gt=date).values(
'user').distinct().count()
else:
learning_circle_count = LearningCircle.objects.all().count()
total_no_enrollment = UserCircleLink.objects.filter(accepted=True).count()
circle_count_by_ig = LearningCircle.objects.all().values(ig_name=F('ig__name')).annotate(
total_circles=Count('id'), total_users=Count('ig__learningcircle__usercirclelink__user', distinct=True))

unique_user_count = UserCircleLink.objects.filter(accepted=True).values('user').distinct().count()
total_no_enrollment = UserCircleLink.objects.filter(accepted=True).count()
query = InterestGroup.objects.annotate(
total_circles=Count('learningcircle'),
total_users=Count('learningcircle__usercirclelink__user', distinct=True)
).values('name', 'total_circles', 'total_users')
circle_count_by_ig = query.values('name').order_by('name').annotate(
total_circles=Count('learningcircle', distinct=True),
total_users=Count('learningcircle__usercirclelink__user', distinct=True)
)
unique_user_count = UserCircleLink.objects.filter(accepted=True).values('user').distinct().count()

return CustomResponse(response={'lc_count': learning_circle_count, 'total_enrollment': total_no_enrollment,
'circle_count_by_ig': circle_count_by_ig,
'unique_users': unique_user_count}).get_success_response()
Expand Down
44 changes: 38 additions & 6 deletions api/dashboard/profile/profile_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from utils.utils import DiscordWebhooks
from . import profile_serializer
from .profile_serializer import LinkSocials
import logging




class UserProfileEditView(APIView):
Expand Down Expand Up @@ -56,19 +59,39 @@ class UserIgEditView(APIView):

def get(self, request):
user_id = JWTUtils.fetch_user_id(request)
user_ig = InterestGroup.objects.filter(user_ig_link_ig__user_id=user_id).all()
serializer = profile_serializer.UserIgListSerializer(user_ig, many=True)
return CustomResponse(response=serializer.data).get_success_response()

user_ig = InterestGroup.objects.filter(
user_ig_link_ig__user_id=user_id
).all()

serializer = profile_serializer.UserIgListSerializer(
user_ig,
many=True
)

return CustomResponse(
response=serializer.data
).get_success_response()

def patch(self, request):

logger = logging.getLogger(__name__)

try:
user_id = JWTUtils.fetch_user_id(request)
user = User.objects.get(id=user_id)

serializer = profile_serializer.UserIgEditSerializer(
user, data=request.data, partial=True
user,
data=request.data,
partial=True
)

if not serializer.is_valid():
return CustomResponse(response=serializer.errors).get_failure_response()
return CustomResponse(
response=serializer.errors
).get_failure_response()

serializer.save()
DiscordWebhooks.general_updates(
WebHookCategory.USER.value,
Expand All @@ -78,8 +101,17 @@ def patch(self, request):
return CustomResponse(
general_message="Interest Group edited successfully"
).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 UserProfileAPI(APIView):
Expand Down
4 changes: 1 addition & 3 deletions api/dashboard/task/dash_task_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def post(self, request): # create
return CustomResponse(message=serializer.errors).get_failure_response()

serializer.save()
return CustomResponse(
general_message="Task Created Successfully"
).get_success_response()
return CustomResponse(general_message="Task Created Successfully").get_success_response()


class TaskAPI(APIView):
Expand Down
3 changes: 3 additions & 0 deletions mulearnbackend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import decouple
from decouple import config

import logging


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down

0 comments on commit 853b080

Please sign in to comment.