Skip to content

Commit

Permalink
Merge pull request #1563 from d34d-5h07/dev
Browse files Browse the repository at this point in the history
fix(lc):Fixed lc notifiction bug
  • Loading branch information
Aashish Vinu authored Nov 16, 2023
2 parents 7d89a4c + 4b7681b commit 4dd9282
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 51 deletions.
59 changes: 11 additions & 48 deletions api/dashboard/lc/dash_lc_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
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
from utils.permission import JWTUtils
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

Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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={
Expand All @@ -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",
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -545,7 +532,7 @@ def post(self, request):
from_mail,
[user.email],
fail_silently=False,
)
)
return CustomResponse(general_message='User Invited').get_success_response()


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


7 changes: 4 additions & 3 deletions api/dashboard/user/dash_user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

BE_DOMAIN_NAME = decouple_config('BE_DOMAIN_NAME')


class UserInfoAPI(APIView):
authentication_classes = [CustomizePermission]

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4dd9282

Please sign in to comment.