-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Se añade frontend - Se puede Crear y unirse a salas
- Loading branch information
Showing
29 changed files
with
4,547 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
from django.urls import path, include | ||
from .views import RoomView | ||
from .views import RoomView, CreateRoomView, GetRoom, JoinRoom | ||
|
||
urlpatterns = [ | ||
path('room/', RoomView.as_view()) | ||
path('room', RoomView.as_view()), | ||
path('create-room', CreateRoomView.as_view()), | ||
path('get-room', GetRoom.as_view()), | ||
path('join-room', JoinRoom.as_view()), | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,71 @@ | ||
from django.shortcuts import render | ||
from rest_framework import generics | ||
from rest_framework import generics, status | ||
from .models import Room | ||
from .serializers import RoomSerializer | ||
from .serializers import RoomSerializer, CreateRoomSerializer | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
# Create your views here. | ||
|
||
class RoomView(generics.CreateAPIView): | ||
class RoomView(generics.ListAPIView): | ||
queryset = Room.objects.all() | ||
serializer_class = RoomSerializer | ||
|
||
class CreateRoomView(APIView): | ||
serializer_class = CreateRoomSerializer | ||
|
||
def post(self, request, format=None): | ||
if not self.request.session.exists(self.request.session.session_key): | ||
self.request.session.create() | ||
|
||
serializer = self.serializer_class(data=request.data) | ||
if serializer.is_valid(): | ||
guest_can_pause = serializer.data.get('guest_can_pause') | ||
votes_to_skip = serializer.data.get('votes_to_skip') | ||
host = self.request.session.session_key | ||
queryset = Room.objects.filter(host=host) | ||
if queryset.exists(): | ||
room = queryset[0] | ||
room.guest_can_pause = guest_can_pause | ||
room.votes_to_skip = votes_to_skip | ||
room.save(update_fields=['guest_can_pause', 'votes_to_skip']) | ||
else: | ||
room = Room(host=host, guest_can_pause=guest_can_pause, votes_to_skip=votes_to_skip) | ||
room.save() | ||
|
||
return Response(RoomSerializer(room).data, status=status.HTTP_201_CREATED) | ||
|
||
|
||
class GetRoom(APIView): | ||
serializer_class = RoomSerializer | ||
lookup_url_kwarg = 'code' | ||
|
||
def get(self, request, format=None): | ||
code = request.GET.get(self.lookup_url_kwarg) | ||
if code != None: | ||
room = Room.objects.filter(code=code) | ||
if len(room) > 0: | ||
data = RoomSerializer(room[0]).data | ||
data['is_host'] = self.request.session.session_key == room[0].host | ||
return Response(data, status=status.HTTP_200_OK) | ||
return Response({'Room not found': 'Invalid Room Code.'}, status=status.HTTP_404_NOT_FOUND) | ||
|
||
return Response({'Bad Request': 'Code parameter not found in request'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
class JoinRoom(APIView): | ||
lookup_url_kwarg = 'room_code' | ||
|
||
def post(self, request, format=None): | ||
if not self.request.session.exists(self.request.session.session_key): | ||
self.request.session.create() | ||
|
||
code = request.data.get(self.lookup_url_kwarg) | ||
print(code) | ||
|
||
if code != None: | ||
room_result = Room.objects.filter(code=code) | ||
if len(room_result) > 0: | ||
room = room_result[0] | ||
self.request.session['room_code'] = code | ||
return Response({'Message': 'Room Joined!'}, status=status.HTTP_200_OK) | ||
return Response({'Room not Found': 'Invalid Room Code'}, status=status.HTTP_404_NOT_FOUND) | ||
return Response({'Bad Request' : 'Code parameter not found in request'}, status=status.HTTP_400_BAD_REQUEST) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class FrontendConfig(AppConfig): | ||
name = 'frontend' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "10" | ||
} | ||
} | ||
], | ||
"@babel/preset-react" | ||
], | ||
"plugins": ["@babel/plugin-proposal-class-properties"] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
Oops, something went wrong.