Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Backend/carrito2 #61

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,63 @@ jobs:

- name: Check if all commits comply with the specification
uses: webiny/action-conventional-commits@v1.2.0

run_backend:
name: Run backend 🏃‍♂️
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend

steps:
- name: Checkout ⬇️
uses: actions/checkout@v4.1.1
with:
show-progress: false

- name: Setup Python 🐍
uses: actions/setup-python@v5.0.0
with:
python-version: '3.x'
check-latest: true

- name: Install dependencies 📦
run: pip install -r requirements.txt

- name: Perform migrations 🗃️
run: python ./manage.py migrate

- name: Run Django Server 🏃‍♂️
run: |
python manage.py runserver &
sleep 10 # Espera a que el servidor esté listo

- name: Check server 🩺
run: |
curl -I http://127.0.0.1:8000/
sudo pkill python

test_backend:
name: Test backend 🔍
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend

steps:
- name: Checkout ⬇️
uses: actions/checkout@v4.1.1
with:
show-progress: false

- name: Setup Python 🐍
uses: actions/setup-python@v5.0.0
with:
python-version: '3.x'
check-latest: true

- name: Install dependencies 📦
run: pip install -r requirements.txt

- name: Perform tests ⚒️
run: python ./manage.py test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ dmypy.json
# Cython debug symbols
cython_debug/

# SQLite Database files
*db*

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
Expand Down
Binary file added backend/TraineerBook.db
Binary file not shown.
Binary file added backend/TraineerBook.db-journal
Binary file not shown.
64 changes: 64 additions & 0 deletions backend/TraineerBook.db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "Activity" (
"id" INTEGER NOT NULL,
"image" TEXT,
"description" TEXT,
"teacher" TEXT,
"class_space" TEXT,
FOREIGN KEY("class_space") REFERENCES "ClassRoom"("name"),
FOREIGN KEY("teacher") REFERENCES "Teacher"("name"),
PRIMARY KEY("id")
);
CREATE TABLE IF NOT EXISTS "ClassRoom" (
"id" INTEGER NOT NULL,
"name" TEXT,
PRIMARY KEY("id")
);
CREATE TABLE IF NOT EXISTS "Comment" (
"id" INTEGER NOT NULL,
"user" TEXT,
"content" TEXT,
FOREIGN KEY("user") REFERENCES "User"("email"),
PRIMARY KEY("id")
);
CREATE TABLE IF NOT EXISTS "Incident" (
"id" INTEGER NOT NULL,
"user" TEXT,
"reservation" TEXT,
"content" TEXT,
FOREIGN KEY("user") REFERENCES "User"("email"),
FOREIGN KEY("reservation") REFERENCES "Reservation"("product"),
PRIMARY KEY("id")
);
CREATE TABLE IF NOT EXISTS "Product" (
"id" INTEGER NOT NULL,
"product_hour_init" TEXT,
"product_hour_fin" TEXT,
"quantity" INTEGER,
"price" INTEGER,
"activity" TEXT,
FOREIGN KEY("activity") REFERENCES "Activity"("description"),
PRIMARY KEY("id")
);
CREATE TABLE IF NOT EXISTS "Reservation" (
"id" INTEGER NOT NULL,
"user" TEXT,
"product" TEXT,
"buy_date" TEXT,
"buy_method" TEXT,
FOREIGN KEY("product") REFERENCES "Product"("activity"),
FOREIGN KEY("user") REFERENCES "User"("email"),
PRIMARY KEY("id")
);
CREATE TABLE IF NOT EXISTS "Teacher" (
"id" INTEGER NOT NULL,
"name" TEXT,
PRIMARY KEY("id")
);
CREATE TABLE IF NOT EXISTS "User" (
"id" INTEGER NOT NULL,
"email" TEXT NOT NULL,
"password" TEXT NOT NULL,
PRIMARY KEY("id")
);
COMMIT;
Empty file.
9 changes: 9 additions & 0 deletions backend/TraineerbookApp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin
from .models import *

# Register your models here.

admin.site.register(Product)
admin.site.register(Activity)
admin.site.register(Teacher)
admin.site.register(ClassRoom)
6 changes: 6 additions & 0 deletions backend/TraineerbookApp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TraineerbookappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'TraineerbookApp'
89 changes: 89 additions & 0 deletions backend/TraineerbookApp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Generated by Django 4.1.6 on 2023-12-03 16:42

from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Activity',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.URLField(max_length=1000, null=True)),
('description', models.TextField()),
],
),
migrations.CreateModel(
name='ClassRoom',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('product_hour_init', models.DateTimeField(blank=True, null=True)),
('product_hour_fin', models.DateTimeField(blank=True, null=True)),
('quantity', models.IntegerField(validators=[django.core.validators.MinValueValidator(0)])),
('price', models.IntegerField(validators=[django.core.validators.MinValueValidator(0)])),
('activity', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', to='TraineerbookApp.activity')),
],
),
migrations.CreateModel(
name='Teacher',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Reservation',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('buy_date', models.DateField(blank=True, null=True)),
('buy_method', models.CharField(choices=[('online', 'Online Payment'), ('payback', 'Payback')], max_length=10)),
('product', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reservations', to='TraineerbookApp.product')),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reservations', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Incident',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('reservation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='incidents', to='TraineerbookApp.reservation')),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='incidents', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('activity', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='TraineerbookApp.activity')),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='comments', to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='activity',
name='class_space',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='activities', to='TraineerbookApp.classroom'),
),
migrations.AddField(
model_name='activity',
name='teacher',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='activities', to='TraineerbookApp.teacher'),
),
]
Empty file.
45 changes: 45 additions & 0 deletions backend/TraineerbookApp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.db import models
from django.core.validators import MinValueValidator
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model

PAY_METHOD = [
('online', 'Online Payment'),
('payback', 'Payback'),
]

class ClassRoom (models.Model):
name = models.CharField(max_length=100, null = False, blank=False)

class Teacher (models.Model):
name = models.CharField(max_length=100, null = False, blank=False)

class Activity(models.Model):
image = models.URLField(max_length=1000, null=True, blank=False)
description = models.TextField(blank=False)
teacher = models.ForeignKey(Teacher,on_delete=models.CASCADE, related_name='activities')
class_space = models.ForeignKey(ClassRoom,on_delete=models.CASCADE, related_name='activities')

class Product(models.Model):
product_hour_init = models.DateTimeField(null=True, blank=True)
product_hour_fin = models.DateTimeField(null=True, blank=True)
quantity = models.IntegerField(validators=[MinValueValidator(0)])
price = models.IntegerField(validators=[MinValueValidator(0)])
activity = models.ForeignKey(Activity, on_delete=models.CASCADE, related_name='products')

class Reservation(models.Model):
user = models.ForeignKey(User, on_delete = models.CASCADE, related_name='reservations',null=True)
product = models.ForeignKey(Product, on_delete = models.CASCADE, related_name='reservations', null=True)
buy_date = models.DateField(null=True, blank=True)
buy_method = models.CharField(max_length=10, choices=PAY_METHOD)

class Comment(models.Model):
user = models.ForeignKey(get_user_model(), on_delete = models.CASCADE, related_name='comments',null=True)
activity = models.ForeignKey(Activity, on_delete=models.CASCADE, related_name='comments')
content = models.TextField(blank=False)

class Incident(models.Model):
user = models.ForeignKey(User, on_delete = models.CASCADE, related_name='incidents',null=True)
reservation = models.ForeignKey(Reservation, on_delete=models.CASCADE, related_name='incidents')
content = models.TextField(blank=False)

52 changes: 52 additions & 0 deletions backend/TraineerbookApp/serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from rest_framework import serializers
from TraineerbookApp.models import *
from rest_framework.serializers import ModelSerializer
from TraineerbookApp.serializer import *

class ActivitySerializer(ModelSerializer):
class Meta:
model = Activity
fields = '__all__'

class TeacherSerializer(ModelSerializer):
class Meta:
model = Teacher
fields = '__all__'

class ClassRoomSerializer(ModelSerializer):
class Meta:
model = ClassRoom
fields = '__all__'

class GetProductSerializer(ModelSerializer):
activity = ActivitySerializer()
teacher = TeacherSerializer(source='activity.teacher')
class_space = ClassRoomSerializer(source='activity.class_space')

class Meta:
model = Product
fields = '__all__'

class GetProductSerializer2(ModelSerializer):

class Meta:
model = Product
fields = '__all__'

class CartProductSerializer(serializers.Serializer):
product_id = serializers.IntegerField(required = True)
quantity = serializers.IntegerField(required = True)

class GetProductSerializer(serializers.Serializer):
activity_description = serializers.CharField(source='activity.description', required=False)
product_hour_init = serializers.DateTimeField()
product_hour_fin = serializers.DateTimeField()
quantity = serializers.IntegerField()
total_price = serializers.DecimalField(max_digits=10, decimal_places=2)







3 changes: 3 additions & 0 deletions backend/TraineerbookApp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
25 changes: 25 additions & 0 deletions backend/TraineerbookApp/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.urls import path
from TraineerbookApp import views

"""
URL configuration for traineerbook project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
path('admin/', admin.site.urls),
]
Loading