Skip to content

Commit

Permalink
Merge pull request #12 from HE-Arc/dev
Browse files Browse the repository at this point in the history
add tag modification for the user
  • Loading branch information
lugopi committed Mar 22, 2024
2 parents 32560ef + e691e4a commit 42f6ca6
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 70 deletions.
2 changes: 1 addition & 1 deletion backend/kodecupid/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SECRET_KEY = 'django-insecure-1s(9a1$*oan-&wjv01x(^$#*0*2x$%8=!=w^wjt2p4!h=7$fqv'

DEBUG = True if os.environ.get('KODECUPID_DEBUG') == 'true' else False
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]', '192.168.1.159', os.environ.get('KODECUPID_BACKEND_HOST')]
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]', os.environ.get('KODECUPID_BACKEND_HOST')]


CORS_ALLOW_CREDENTIALS = True
Expand Down
9 changes: 5 additions & 4 deletions backend/kodecupid/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
from django.contrib import admin
from django.urls import path
from kodecupidapp.views import UserView, TagListView, PictureView, LikeCreateView
from kodecupidapp.views import UserView, TagView, PictureView, LikeView, UserTagView
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
Expand All @@ -28,6 +28,7 @@
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('api/user/', UserView.as_view(), name='user'),
path('api/picture/', PictureView.as_view(), name='picture'),
path('api/tags/', TagListView.as_view(), name='tag-list'),
path('api/like/', LikeCreateView.as_view(), name='like-create')
]
path('api/tags/', TagView.as_view(), name='tag-list'),
path('api/like/', LikeView.as_view(), name='like-create'),
path('api/user/tags', UserTagView.as_view(), name='user-tag')
]
2 changes: 1 addition & 1 deletion backend/kodecupidapp/serializers/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
class TagSerializer(serializers.ModelSerializer):
class Meta:
model = Tag
fields = ['name']
fields = ['id', 'name']
6 changes: 3 additions & 3 deletions backend/kodecupidapp/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .like import LikeCreateView
from .user import UserView
from .tag import TagListView
from .like import LikeView
from .user import UserView, UserTagView
from .tag import TagView
from .picture import PictureView
2 changes: 1 addition & 1 deletion backend/kodecupidapp/views/like.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ..serializers import LikeSerializer
from ..models import Like

class LikeCreateView(APIView):
class LikeView(APIView):

def post(self, request):
serializer = LikeSerializer(data=request.data, context={'request': request})
Expand Down
44 changes: 43 additions & 1 deletion backend/kodecupidapp/views/tag.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from django.shortcuts import get_object_or_404
from rest_framework import status
from ..models import Tag
from ..serializers import TagSerializer
from ..models import User


class TagListView(APIView):
class TagView(APIView):

def get(self, request):
tags = Tag.objects.all()
serializer = TagSerializer(tags, many=True)
return Response(serializer.data)

def post(self, request):

serializer = TagSerializer(data=request.data)

if not serializer.is_valid():
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

user = request.user

tag_name = serializer.validated_data['name']
tag = get_object_or_404(Tag, name=tag_name)

if user in tag.users.all():
return Response({'message': 'User already has tag'}, status=status.HTTP_400_BAD_REQUEST)

tag.users.add(user)

return Response({'message': 'Tag added to user'}, status=status.HTTP_201_CREATED)


def delete(self, request):

serializer = TagSerializer(data=request.data)

if not serializer.is_valid():
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

user = request.user

tag_name = serializer.validated_data['name']
tag = get_object_or_404(Tag, name=tag_name)

if user not in tag.users.all():
return Response({'message': 'User does not have tag'}, status=status.HTTP_400_BAD_REQUEST)

tag.users.remove(user)

return Response({'message': 'Tag removed from user'}, status=status.HTTP_204_NO_CONTENT)
18 changes: 15 additions & 3 deletions backend/kodecupidapp/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from rest_framework.response import Response
from rest_framework import status
from rest_framework.permissions import AllowAny, IsAuthenticated
from ..models import User
from ..serializers import UserSerializer, UserRegistrationSerializer, UserConfigurationSerializer
from ..models import User, Tag
from ..serializers import UserSerializer, UserRegistrationSerializer, UserConfigurationSerializer, TagSerializer

import random

Expand Down Expand Up @@ -69,4 +69,16 @@ def delete(self, request):
user.delete()
return Response({"message": "User successfully deleted."},status=status.HTTP_204_NO_CONTENT)
return Response({"message": "User cannot be deleted."}, status=status.HTTP_403_FORBIDDEN)
return Response({"message": "User not found."}, status=status.HTTP_404_NOT_FOUND)
return Response({"message": "User not found."}, status=status.HTTP_404_NOT_FOUND)


class UserTagView(APIView):

def get(self, request):
user = request.user

tags = Tag.objects.filter(users=user)

serializer = TagSerializer(tags, many=True)

return Response(serializer.data)
20 changes: 18 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,31 @@ export $(cat .env | xargs)
eval "$(ssh-agent -s)"
ssh-add "$1"

systemctl stop gunicorn
systemctl stop nginx

git pull origin main

cd backend

rm -f Pipfile.lock
rm -f requirement.txt
rm -rf static/*

pipenv install --deploy
pipenv run python3 manage.py collectstatic --noinput
pipenv run python3 manage.py migrate
pipenv run python3 manage.py test
pipenv run python3 manage.py import_tags
pipenv run python3 manage.py collectstatic --noinput

pipenv run pip freeze > requirement.txt
pip install -r requirement.txt

cd "$root"
cd frontend

npm install
npm run build
npm run build

systemctl start gunicorn
systemctl start nginx
10 changes: 5 additions & 5 deletions frontend/src/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
<v-icon aria-hidden="false">
mdi-magnify
</v-icon>
<span>Search</span>
<span>Recherche</span>
</v-btn>

<v-btn :to="{ name: 'match' }">
<v-icon aria-hidden="false">
mdi-robot-love
</v-icon>
<span>Match</span>
<span>Matchs</span>
</v-btn>

<v-btn :to="{ name: 'account-show' }">
<v-icon aria-hidden="false">
mdi-account
</v-icon>
<span>Account</span>
<span>Ton compte</span>
</v-btn>

<v-btn @click="logout()" v-if="checkAuth()">
<v-icon aria-hidden="false">
mdi-logout
</v-icon>
<span>Logout</span>
<span>Déconnexion</span>
</v-btn>
<v-btn v-else :to="{ name: 'signin' }">
<v-icon aria-hidden="false">
mdi-login
</v-icon>
<span>Signin</span>
<span>Connexion</span>
</v-btn>
</v-bottom-navigation>

Expand Down
5 changes: 5 additions & 0 deletions frontend/src/configs/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export const API_ROUTES = {
USER_DETAIL: API_SERVER_URL+'/api/user/',

TAG_LIST: API_SERVER_URL+'/api/tags/',

USER_TAG_ADD: API_SERVER_URL+'/api/tags/',
USER_TAG_REMOVE: API_SERVER_URL+'/api/tags/',

USER_TAGS: API_SERVER_URL+'/api/user/tags',

};

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
</v-row>
<v-row>
<v-col class="d-flex justify-center">
<v-btn color="primary" :to="{ name: 'signin' }">Connecte toi</v-btn>
<v-btn color="primary" :to="{ name: 'signin' }">Connecte-toi</v-btn>
</v-col>
<v-col class="d-flex justify-center">
<v-btn color="primary" :to="{ name: 'signup' }">crée un compte</v-btn>
<v-btn color="primary" :to="{ name: 'signup' }">Crée un compte</v-btn>
</v-col>
</v-row>
<v-divider class="my-4"></v-divider>
Expand All @@ -43,13 +43,13 @@
<h1><v-icon color="blue">mdi-shield-crown</v-icon>L'équipe</h1>
<v-list>
<v-list-item>
<p><v-icon color="blue">mdi-shield-sword</v-icon> Lucas Gosteli</p>
<p><v-icon color="blue">mdi-shield-sword</v-icon>Lucas Gosteli</p>
</v-list-item>
<v-list-item>
<p><v-icon color="blue">mdi-shield-sword</v-icon>Danien Tschan</p>
<p><v-icon color="blue">mdi-shield-sword</v-icon>Damien Tschan</p>
</v-list-item>
<v-list-item>
<p><v-icon color="blue">mdi-shield-sword</v-icon>Bruno Tomas</p>
<p><v-icon color="blue">mdi-shield-sword</v-icon>Bruno Thomas</p>
</v-list-item>
</v-list>
</v-col>
Expand Down
Loading

0 comments on commit 42f6ca6

Please sign in to comment.