Skip to content

Commit

Permalink
[Feat] Add blocked friends
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarm committed May 6, 2024
1 parent 8f12361 commit 066eb9c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
21 changes: 14 additions & 7 deletions app/back-end/dashboards/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ def get_friends(self, obj):

class BlockedFriendshipSerializer(serializers.ModelSerializer):
user = serializers.SerializerMethodField()
blocked = serializers.SerializerMethodField()
is_user_from = serializers.SerializerMethodField()
class Meta:
model = Friendship
fields = ('user', 'is_accepted')
fields = ('user', 'is_accepted', 'blocked', 'is_user_from')

def get_user(self, obj):
if obj.user_from.id == self.context['id']:
Expand All @@ -117,11 +119,16 @@ def get_user(self, obj):
serializer = UserSerializer(user_data)
return serializer.data

# def get_blocked(self, obj):
# if obj.user_from.id == self.context['id']:
# blocked = Friendship.objects.get(user_from = )
# else:
# user_data = User.objects.get(id=obj.user_from.id)
def get_blocked(self, obj):
if obj.user_from.id == self.context['id']:
blocked = obj.u_one_is_blocked_u_two
else:
blocked = obj.u_two_is_blocked_u_one
return blocked

def get_is_user_from(self, obj):
return obj.user_from.id == self.context['id']


class BlockedFriendsSerializer(serializers.ModelSerializer):
friends = serializers.SerializerMethodField()
Expand All @@ -131,5 +138,5 @@ class Meta:

def get_friends(self, obj):
friends_data = Friendship.objects.filter(Q(user_from = obj)| Q(user_to= obj))
serializer = FriendshipSerializer(friends_data, many=True, context = {'id': obj.id})
serializer = BlockedFriendshipSerializer(friends_data, many=True, context = {'id': obj.id})
return serializer.data
5 changes: 4 additions & 1 deletion app/back-end/dashboards/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
AcceptFriendshipView,
AddFriendshipView,
BlockFriendshipView,
UnblockFriendshipView
UnblockFriendshipView,
BlockedFriendsView
)

urlpatterns = [
Expand All @@ -22,4 +23,6 @@
path('friends-add', AddFriendshipView.as_view(), name="friends-add"),
path('friends-block', BlockFriendshipView.as_view(), name="friends-block"),
path('friends-unblock', UnblockFriendshipView.as_view(), name="friends-unblock"),
path('blocked-friends', BlockedFriendsView.as_view(), name="friends-unblock"),

]
11 changes: 10 additions & 1 deletion app/back-end/dashboards/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from .serializer import (MainDashboardSerializer,
ProfileSerializer,
FriendsSerializer,
UserSerializer)
UserSerializer,
BlockedFriendsSerializer)
from .models import Friendship
from authentication.models import User
from rest_framework import status
Expand Down Expand Up @@ -199,3 +200,11 @@ def post(self, request):
except Friendship.DoesNotExist:
return Response({'error': 'Friendship does not exist'}, status=status.HTTP_400_BAD_REQUEST)

class BlockedFriendsView(APIView):
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated]

def get(self, request):
user = request.user
serializer = BlockedFriendsSerializer(instance=user)
return Response(serializer.data)
2 changes: 1 addition & 1 deletion app/front-end/src/app/profile/[username]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export default function ({ params }: { params: { username: string } })
</InputGroup>
<InputGroup hasValidation className='mb-3'>
<InputGroup.Text style={{backgroundColor: '#2C3143'}}><MdRoundaboutRight color='#FFEBEB'/></InputGroup.Text>
<Form.Control className={`${styles.form_control}`} required as="textarea" placeholder='Intro' aria-label='Intro' defaultValue={parag} style={{backgroundColor: '#2C3143'}}/>
<Form.Control className={`${styles.form_control}`} required type="textarea" placeholder='Intro' aria-label='Intro' defaultValue={parag} style={{backgroundColor: '#2C3143'}}/>
<Form.Control.Feedback type="invalid">
Please talk about yourslef.
</Form.Control.Feedback>
Expand Down
2 changes: 1 addition & 1 deletion app/front-end/src/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export default function ()
</InputGroup>
<InputGroup hasValidation className='mb-3'>
<InputGroup.Text style={{backgroundColor: '#2C3143'}}><MdRoundaboutRight color='#FFEBEB'/></InputGroup.Text>
<Form.Control className={`${styles.form_control}`} required as="textarea" placeholder='Intro' aria-label='Intro' defaultValue={parag} style={{backgroundColor: '#2C3143'}}/>
<Form.Control className={`${styles.form_control}`} required type="textarea" placeholder='Intro' aria-label='Intro' defaultValue={parag} style={{backgroundColor: '#2C3143'}}/>
<Form.Control.Feedback type="invalid">
Please talk about yourslef.
</Form.Control.Feedback>
Expand Down

0 comments on commit 066eb9c

Please sign in to comment.