diff --git a/api/dashboard/lc/dash_lc_view.py b/api/dashboard/lc/dash_lc_view.py index 106df27d..b192ce6b 100644 --- a/api/dashboard/lc/dash_lc_view.py +++ b/api/dashboard/lc/dash_lc_view.py @@ -6,7 +6,6 @@ from django.shortcuts import redirect from rest_framework.views import APIView - from api.notification.notifications_utils import NotificationUtils from db.learning_circle import LearningCircle, UserCircleLink, CircleMeetingLog from db.user import User @@ -14,7 +13,7 @@ from utils.response import CustomResponse from utils.utils import send_template_mail, DateTimeUtils from .dash_lc_serializer import LearningCircleSerializer, LearningCircleCreateSerializer, LearningCircleHomeSerializer, \ - LearningCircleUpdateSerializer, LearningCircleJoinSerializer, ScheduleMeetingSerializer, \ + LearningCircleUpdateSerializer, LearningCircleJoinSerializer, LearningCircleCreateEditDeleteSerializer, \ LearningCircleMainSerializer, LearningCircleNoteSerializer, LearningCircleDataSerializer, \ LearningCircleMemberListSerializer, MeetRecordsCreateEditDeleteSerializer @@ -32,6 +31,7 @@ class LearningCircleListApi(APIView): CustomResponse: A custom response containing a list of learning circles associated with the user. """ + def get(self, request): # Lists user's learning circle user_id = JWTUtils.fetch_user_id(request) @@ -177,7 +177,6 @@ def post(self, request, circle_code=None): Q(circle_code=circle_code) | Q(name__icontains=circle_code) ).exists(): - return CustomResponse( general_message='invalid circle code or Circle Name' ).get_failure_response() @@ -205,14 +204,7 @@ class LearningCircleJoinApi(APIView): def post(self, request, circle_id): user_id = JWTUtils.fetch_user_id(request) user = User.objects.filter(id=user_id).first() - full_name = f'{user.fullname}' - - user_learning_circle = UserCircleLink.objects.filter( - circle_id=circle_id, - lead=True - ).first() - serializer = LearningCircleJoinSerializer( data=request.data, context={ @@ -222,12 +214,10 @@ def post(self, request, circle_id): ) if serializer.is_valid(): serializer.save() - user = User.objects.filter( - id=user_learning_circle.user.id - ).first() + lead = UserCircleLink.objects.filter(circle_id=circle_id, lead=True).first().user_id NotificationUtils.insert_notification( - user=user, + user=lead, title="Member Request", description=f"{full_name} has requested to join your learning circle", button="LC", @@ -251,7 +241,6 @@ def get(self, request, circle_id, member_id=None): if not LearningCircle.objects.filter( id=circle_id ).exists(): - return CustomResponse( general_message='Learning Circle not found' ).get_failure_response() @@ -300,7 +289,6 @@ def patch(self, request, member_id, circle_id): ).exists() or not LearningCircle.objects.filter( id=circle_id ).exists(): - return CustomResponse( general_message='Learning Circle Not Available' ).get_failure_response() @@ -368,7 +356,7 @@ def delete(self, request, circle_id): usr_circle_link = UserCircleLink.objects.filter( circle__id=circle_id, user__id=user_id - ).first() + ).first() if not usr_circle_link: return CustomResponse(general_message='User not part of circle').get_failure_response() @@ -377,7 +365,7 @@ def delete(self, request, circle_id): if ( next_lead := UserCircleLink.objects.filter( circle__id=circle_id, accepted=1 - ) + ) .exclude(user__id=user_id) .order_by('accepted_at') .first() @@ -392,7 +380,7 @@ def delete(self, request, circle_id): if not UserCircleLink.objects.filter(circle__id=circle_id).exists(): if learning_circle := LearningCircle.objects.filter( id=circle_id - ).first(): + ).first(): learning_circle.delete() return CustomResponse(general_message='Learning Circle Deleted').get_success_response() @@ -496,7 +484,6 @@ def patch(self, request, circle_id, lead_id): if not LearningCircle.objects.filter( id=circle_id ).exists(): - return CustomResponse( general_message='Learning Circle not found' ).get_failure_response() @@ -545,7 +532,7 @@ def post(self, request): from_mail, [user.email], fail_silently=False, - ) + ) return CustomResponse(general_message='User Invited').get_success_response() @@ -596,12 +583,12 @@ def post(self, request, circle_id, muid): "circle_id": circle_id, "muid": muid, "email": receiver_email, - } + } status = send_template_mail( context=context, subject="MuLearn - Invitation to learning circle", address=html_address, - ) + ) if status == 1: UserCircleLink.objects.create( @@ -611,7 +598,7 @@ def post(self, request, circle_id, muid): is_invited=True, accepted=False, created_at=DateTimeUtils.get_current_utc_time(), - ) + ) return CustomResponse( general_message='User Invited' @@ -664,27 +651,3 @@ def post(self, request, circle_id, muid, status): return CustomResponse( general_message='User rejected invitation' ).get_failure_response() - - -class ScheduleMeetAPI(APIView): - def put(self, request, circle_id): - learning_circle = LearningCircle.objects.filter( - id=circle_id - ).first() - - serializer = ScheduleMeetingSerializer( - learning_circle, - data=request.data - ) - if serializer.is_valid(): - data = serializer.save() - - return CustomResponse( - general_message=f"meet scheduled on {data.meet_time}" - ).get_success_response() - - return CustomResponse( - message=serializer.errors - ).get_failure_response() - - diff --git a/api/dashboard/user/dash_user_views.py b/api/dashboard/user/dash_user_views.py index fe6a7fc9..28968620 100644 --- a/api/dashboard/user/dash_user_views.py +++ b/api/dashboard/user/dash_user_views.py @@ -16,6 +16,7 @@ BE_DOMAIN_NAME = decouple_config('BE_DOMAIN_NAME') + class UserInfoAPI(APIView): authentication_classes = [CustomizePermission] @@ -238,9 +239,9 @@ def post(self, request): email_muid = request.data.get("emailOrMuid") if not ( - user := User.objects.filter( - Q(muid=email_muid) | Q(email=email_muid) - ).first() + user := User.objects.filter( + Q(muid=email_muid) | Q(email=email_muid) + ).first() ): return CustomResponse( general_message="User not exist"