Skip to content

Commit

Permalink
Adicionando metodo para filtrar top perfis e metodos em Post para fil…
Browse files Browse the repository at this point in the history
…trar post dos perfis que o usuário segue
  • Loading branch information
matheus-dev-fullstack committed Dec 21, 2024
1 parent cee6ca0 commit a188d69
Show file tree
Hide file tree
Showing 34 changed files with 36 additions and 12 deletions.
Binary file modified db.sqlite3
Binary file not shown.
Binary file added media/bannerPhoto/2341181-800-auto_2.webp
Binary file not shown.
Binary file added media/bannerPhoto/brasil.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/bannerPhoto/brasil_aIR4wlj.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/bannerPhoto/canela_GNMQxso.webp
Binary file not shown.
Binary file added media/bannerPhoto/canela_VmKolj8.webp
Binary file not shown.
Binary file added media/bannerPhoto/gatinho_HQahNqx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/bannerPhoto/gatinho_IMlebPQ.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/bannerPhoto/neymar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/2341181-800-auto_2.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/brasil.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/canela_1VzaC0a.webp
Binary file not shown.
Binary file added media/perfilPhoto/canela_LZPeamk.webp
Binary file not shown.
Binary file added media/perfilPhoto/canela_LvEM3Jv.webp
Binary file not shown.
Binary file added media/perfilPhoto/canela_MwFqjZP.webp
Binary file not shown.
Binary file added media/perfilPhoto/canela_SPdhAoY.webp
Binary file not shown.
Binary file added media/perfilPhoto/eu.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/eu2.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/gatinho.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/gatinho_5utWHlK.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/gatinho_AjusxpB.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/neymar_WFyr0ZW.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/neymar_gDYwCVN.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/neymar_q6A31ut.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/violao.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/perfilPhoto/violao_hnaART6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/posts_images/canela_9zatFOq.webp
Binary file not shown.
Binary file modified posts/viewsets/__pycache__/post_viewset.cpython-312.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions posts/viewsets/post_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def perform_create(self, serializer):
# imagem = self.request.FILES.get('imagem')
post = serializer.save(author=self.request.user)

@action(detail=False, methods=['get'], url_path='following-posts', permission_classes=[AllowAny])
def following_posts(self, request):
user = request.user

following_users = user.following.all()

posts = Post.objects.filter(author__in=following_users).order_by('-released')

serializer = self.get_serializer(posts, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)

@action(detail=False, methods=['get'], url_path='user-posts/(?P<username>[^/.]+)', permission_classes=[AllowAny])
def user_posts(self, request, username=None):
try:
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion usuarios/serializers/usuario_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def create(self, validated_data):

return perfil
except serializers.ValidationError as e:
print(f"Erro no serializer: {e.detail}") # Log detalhado no console
print(f"Erro no serializer: {e.detail}")
raise e
except Exception as e:
print(f"Erro inesperado: {str(e)}") # Log de erros gerais
Expand Down
Binary file modified usuarios/viewsets/__pycache__/usuario_viewset.cpython-312.pyc
Binary file not shown.
35 changes: 24 additions & 11 deletions usuarios/viewsets/usuario_viewset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from itertools import count
from django.shortcuts import get_object_or_404
from rest_framework import viewsets,status
from posts.models import Usuario
Expand All @@ -10,6 +11,9 @@
from django.contrib.auth import authenticate
from rest_framework.permissions import IsAuthenticated
from usuarios.serializers.usuario_serializers import RegisterSerializer
from rest_framework.parsers import MultiPartParser, FormParser
from rest_framework.decorators import parser_classes
from django.db.models import Count

class PerfilViewSet(viewsets.ModelViewSet):
# permission_classes = [IsAuthenticated]
Expand All @@ -23,13 +27,22 @@ def list(self, request, *args, **kwargs):
return Response(serializer.data)

@action(detail=False, methods=['put', 'patch'], url_path='editar-perfil', permission_classes=[AllowAny])
@parser_classes([MultiPartParser, FormParser])
def editar_perfil(self, request):
user = request.user
serializer = self.get_serializer(user, data=request.data, partial=True)

if serializer.is_valid():
serializer.save()
return Response({"message": "Perfil atualizado com sucesso!", "data": serializer.data}, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
return Response({
"message": "Perfil atualizado com sucesso!",
"data": serializer.data
}, status=status.HTTP_200_OK)

return Response({
"message": "Erro ao atualizar perfil.",
"errors": serializer.errors
}, status=status.HTTP_400_BAD_REQUEST)

@action(detail=False, methods=['get'], url_path='overview/(?P<username>[^/.]+)')
def perfil_overview(self, request, username=None):
Expand Down Expand Up @@ -76,6 +89,15 @@ def following(self, request, pk=None):
following = user.following.all()
serializer = self.get_serializer(following, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)

@action(detail=False, methods=['get'], url_path='top-followed', permission_classes=[AllowAny])
def top_followed(self, request):
top_users = (
Usuario.objects.annotate(followers_count=Count('followers'))
.order_by('-followers_count')[:3]
)
serializer = self.get_serializer(top_users, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)

class RegisterViewSet(viewsets.ModelViewSet):
permission_classes = [AllowAny]
Expand All @@ -94,15 +116,6 @@ def create(self, request, *args, **kwargs):
}, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

# class LoginViewSet(viewsets.ViewSet):

# @action(detail=False, methods=['post'])
# def authenticate(self, request):
# serializer = LoginTokenSerializer(data=request.data)
# if serializer.is_valid():
# user = serializer.validated_data
# return Response({"message": "Login bem-sucedido!", "username": user.username}, status=status.HTTP_200_OK)
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

class LoginViewSet(viewsets.ViewSet):
permission_classes = [AllowAny]
Expand Down

0 comments on commit a188d69

Please sign in to comment.