Skip to content

Commit

Permalink
Melhorei o cleancode do filtro dos tweeks do feed
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaiva31 committed Mar 4, 2023
1 parent cabbaf7 commit 0bec29f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
8 changes: 8 additions & 0 deletions apps/core/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TWEEK_FILTER_RECENTLY = '0'
TWEEK_FILTER_LIKES = '1'
TWEEK_FILTER_SHARES = '2'
TWEEK_FILTER_TYPE = (
(TWEEK_FILTER_RECENTLY, ('Recently')),
(TWEEK_FILTER_LIKES, ('Likes')),
(TWEEK_FILTER_SHARES, ('Shares')),
)
8 changes: 4 additions & 4 deletions apps/feed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ..notification.models import Notification
from .serializers import TweekSerializer
from apps.feed.models import Tweek, Like, Dislike

from apps.core import defaults


@permission_classes((IsAuthenticated, ))
Expand Down Expand Up @@ -187,11 +187,11 @@ def api_get_tweeks(request):
for tweeker in request.user.twikkerprofile.follows.all():
userids.append(tweeker.user.id)
tweeks = Tweek.objects.filter(created_by__id__in=userids)
if request.GET.get('order_by') == '0':
if request.GET.get('order_by') == defaults.TWEEK_FILTER_RECENTLY:
tweeks = tweeks.order_by('-created_at')
elif request.GET.get('order_by') == '1':
elif request.GET.get('order_by') == defaults.TWEEK_FILTER_LIKES:
tweeks = tweeks.order_by('-likes')
elif request.GET.get('order_by') == '2':
elif request.GET.get('order_by') == defaults.TWEEK_FILTER_SHARES:
tweeks = tweeks.annotate(num_retweets=Count('retweek')).order_by('-num_retweets')
paginator = PageNumberPagination()
paginator.page_size = 25
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ services:
# - POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000 && python manage.py migrate && python manage.py migrate feed 0012 --fake && python manage.py migrate && python manage.py migrate twikkerprofile 0006 --fake && python manage.py migrate
command: python manage.py runserver 0.0.0.0:7000 && python manage.py migrate && python manage.py migrate feed 0012 --fake && python manage.py migrate && python manage.py migrate twikkerprofile 0006 --fake && python manage.py migrate
volumes:
- .:/code
ports:
- "8000:8000"
- "7000:7000"
environment:
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
Expand Down
4 changes: 2 additions & 2 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VITE_API_BASE_URL = 'http://localhost:8000'
VITE_SOCKET_HOST = 'localhost:8000'
VITE_API_BASE_URL = 'http://localhost:7000'
VITE_SOCKET_HOST = 'localhost:7000'

0 comments on commit 0bec29f

Please sign in to comment.