diff --git a/API/Apps/Profile/api/Serializers.py b/API/Apps/Profile/api/Serializers.py index 54e31581..4596c257 100644 --- a/API/Apps/Profile/api/Serializers.py +++ b/API/Apps/Profile/api/Serializers.py @@ -27,7 +27,7 @@ class ProfileFriendsSerializer(serializers.ModelSerializer): class Meta: model = Profile - fields = ['friends', 'nickname', 'user', 'profile_picture'] + fields = ['friends', 'nickname', 'user', 'profile_picture', "id"] class ProfileStatsSerializer(serializers.ModelSerializer): diff --git a/API/Apps/Profile/api/views.py b/API/Apps/Profile/api/views.py index c8bdf47f..e49ea7b3 100644 --- a/API/Apps/Profile/api/views.py +++ b/API/Apps/Profile/api/views.py @@ -165,8 +165,6 @@ def post(self, request): class ProfileBlockedUsersView(APIView): def get(self, request): profile = request.user.profile - if not profile: - return Response({"error": "Profile not found"}, status=404) serializer = ProfileFriendsSerializer(profile.blocked_users, many=True) return Response(serializer.data, status=200) diff --git a/API/static/scripts/profile.js b/API/static/scripts/profile.js index c55315a9..7c198e32 100644 --- a/API/static/scripts/profile.js +++ b/API/static/scripts/profile.js @@ -4,7 +4,6 @@ import { notify } from "../components/Notification.js"; import { request } from "./Request.js"; import {calculateDate, escapeHTML, getActiveUserNickname} from "./utils.js"; - class History extends BaseComponent { constructor(state, parentElement = null) { super(state, parentElement); @@ -46,27 +45,54 @@ class BlockedUsers extends BaseComponent { super(state, parentElement); this.html = this.handleHTML(); } + + async removeBlockedUser(id, index) { + try { + let data = await request('profile/block-users/', { + method: "POST", + body: JSON.stringify({ + profile_id: id + }) + }); + let wrapper = document.getElementById(`${index}-blocked-user-wrapper`) + + wrapper.remove() + return data; + } catch (error) { + console.error('Error:', error); + notify('Error fetching friends', 3, 'error'); + } + } + handleHTML() { return `