Skip to content

Commit

Permalink
Merge pull request #25 from LaurierCS/pedro/update-group-model-id
Browse files Browse the repository at this point in the history
Pedro/update group model
  • Loading branch information
itsPedro231 authored Nov 5, 2023
2 parents eb78d7c + d67d112 commit 4da0846
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 62 deletions.
26 changes: 6 additions & 20 deletions api/optimeet/groups/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 4.1.12 on 2023-10-23 17:10
# Generated by Django 4.1.12 on 2023-11-03 18:33

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -16,24 +15,11 @@ class Migration(migrations.Migration):
name='Group',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
],
),
migrations.CreateModel(
name='Preferences',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('distance_radius', models.IntegerField(default=5)),
('time', models.TimeField()),
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='groups.group')),
],
),
migrations.CreateModel(
name='Recommendation',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='groups.group')),
('preferences', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='groups.preferences')),
('group_id', models.CharField(default='10', max_length=5, unique=True)),
('name', models.CharField(default='', max_length=30)),
('host_id', models.CharField(default='', max_length=64)),
('max_capacity', models.IntegerField(default=5)),
('status', models.CharField(choices=[('A', 'Active'), ('F', 'Finished')], default='A', max_length=1)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.1.12 on 2023-11-03 20:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('groups', '0001_initial'),
]

operations = [
migrations.RemoveField(
model_name='group',
name='id',
),
migrations.AlterField(
model_name='group',
name='group_id',
field=models.BigAutoField(default=4310021863, primary_key=True, serialize=False),
),
]

This file was deleted.

19 changes: 19 additions & 0 deletions api/optimeet/groups/migrations/0003_alter_group_group_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.1.12 on 2023-11-03 21:18

import builtins
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('groups', '0002_remove_group_id_alter_group_group_id'),
]

operations = [
migrations.AlterField(
model_name='group',
name='group_id',
field=models.CharField(default=builtins.id, max_length=10, primary_key=True, serialize=False),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.1.12 on 2023-11-03 21:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('groups', '0003_alter_group_group_id'),
]

operations = [
migrations.AlterField(
model_name='group',
name='group_id',
field=models.CharField(max_length=10, primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='group',
name='host_id',
field=models.CharField(max_length=64),
),
migrations.AlterField(
model_name='group',
name='name',
field=models.CharField(max_length=30),
),
]
15 changes: 10 additions & 5 deletions api/optimeet/groups/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from typing import Any
from django.db import models

class Group(models.Model):

ACTIVE = "A"
FINISHED = "F"

status_choices = [(ACTIVE, "Active"), (FINISHED, "Finished")]

group_id = models.CharField(max_length=10, primary_key=True, blank=True)

name = models.CharField(max_length = 30)
host_id = models.CharField(max_length=64)
max_capacity = models.IntegerField(default=5)
status = models.CharField(max_length=1, choices=status_choices, default = ACTIVE)

name = models.CharField(max_length = 30, default='')
host_id = models.CharField(max_length=64, default='')
max_capacity = models.IntegerField(default=5)
status = models.CharField(max_length=1, choices=status_choices, default = ACTIVE)
7 changes: 7 additions & 0 deletions api/optimeet/groups/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from rest_framework import serializers
from . import models
from random import randint

def rnd_id(): return randint(1000000000,9999999999)

class GroupSerializer(serializers.ModelSerializer):
class Meta:
model = models.Group
fields = '__all__'

def create(self, validated_data):
validated_data['group_id'] = rnd_id()
return super(GroupSerializer, self).create(validated_data)

9 changes: 5 additions & 4 deletions api/optimeet/groups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
@csrf_exempt
@api_view(['POST'])
def groups(request):

serializer = serializers.GroupSerializer(data = request.data)

if serializer.is_valid():
serializer.save()

return Response(serializer.data, status=status.HTTP_201_CREATED)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

@csrf_exempt
@api_view(['GET'])
def group_detail(request, group_id):

group = models.Group.objects.filter(id=group_id)
group = models.Group.objects.filter(group_id=group_id)

serializer = serializers.GroupSerializer(group, many = True)
return Response(serializer.data)
Expand Down
1 change: 0 additions & 1 deletion api/optimeet/optimeet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

Expand Down

0 comments on commit 4da0846

Please sign in to comment.