Skip to content

Commit

Permalink
Create view VolunteerProfileView
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruzal committed Oct 20, 2023
1 parent 5673ff0 commit 7a211ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
9 changes: 6 additions & 3 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,26 +389,29 @@ class Meta:
)


# в разработке
class VolunteerProfileSerializer(serializers.Serializer):
"""
Сериализатор для личного кабинета.
Сериализатор для личного кабинета волонтера.
"""

volunteer = VolunteerGetSerializer()
user = UserSerializer()
skills = SkillsSerializer(many=True)
participating_projects = ProjectSerializer(many=True)
applied_projects = ProjectSerializer(many=True)
projects = ProjectSerializer(many=True)
participants = ProjectParticipantSerializer(many=True)
project_incomes = ProjectIncomesSerializer(many=True)
phone = serializers.CharField(source='volunteer.phone')

class Meta:
fields = (
'volunteer',
'user',
'phone',
'skills',
'participating_projects',
'applied_projects',
'projects',
'participants',
'project_incomes',
)
3 changes: 1 addition & 2 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
path('feedback/', FeedbackCreateView.as_view()),
path('search/', SearchListView.as_view()),
path(
'volunteer/profile/',
'volunteer/profile/<int:volunteer_id>/',
VolunteerProfileView.as_view(),
name='volunteer-profile',
),
]
13 changes: 8 additions & 5 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ class SearchListView(generics.ListAPIView):
search_fields = ['name', 'description', 'event_purpose']


# в разработке
class VolunteerProfileView(generics.RetrieveAPIView):
queryset = Volunteer.objects.all()
serializer_class = VolunteerProfileSerializer

def get_object(self):
return self.request.user.volunteer
def get(self, request, volunteer_id, format=None):
try:
volunteer = Volunteer.objects.get(id=volunteer_id)
serializer = VolunteerProfileSerializer(volunteer)
return Response(serializer.data)
except Volunteer.DoesNotExist:
return Response({'error': 'Волонтер не найден'}, status=404)

0 comments on commit 7a211ff

Please sign in to comment.