Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
692ca1a
neue Models erstellt
Jun 13, 2024
19f3256
HTTP requests funktionieren, Objekte sind aufrufbar und änderbar
Jun 17, 2024
f237526
API views erstellt für userid und answers
Jun 17, 2024
e016417
user_id Funktion mit uuid hinzugefügt, um zu testen siehe Kommentare …
Jun 18, 2024
90730c6
in settings.py zurück auf postgresql gesetzt bei DATABASES
Jun 19, 2024
efa9f86
Merge pull request #1 from Sabaawi7/djangorestL
JakobSchreiber1 Jun 19, 2024
cc38738
peters datei hinzugefügt
GeorgiosK78 Jun 19, 2024
9c7f6e7
Merge branch 'main' of https://github.com/Sabaawi7/pacoBackEnd
GeorgiosK78 Jun 19, 2024
1964b1b
Merge conflict gelöst
Jun 19, 2024
8a86fc0
user_id automatisch und manuell generierbar bei Klick auf POST
Jun 19, 2024
a9346db
Merge branch 'main' into djangorestL
Jun 19, 2024
71ce96e
user_id methode aus x_data_utils.py erfolgreich eingebunden
Jun 19, 2024
7c878d2
/interviewdetails/{token} returns all data for token
GeorgiosK78 Jun 19, 2024
7ca7e78
/interviwedetais/{userid}/{questionNR} "POST" speichert eine json mit…
GeorgiosK78 Jun 19, 2024
a56b6fb
markdown in requirements.txt dazu getan
Jun 20, 2024
a3065f0
requirements.txt
Jun 20, 2024
11c7b2e
Merge pull request #2 from Sabaawi7/djangorestL
Sabaawi7 Jun 20, 2024
de75459
added tokenAuth
Sabaawi7 Jun 20, 2024
ee8453a
Merge branch 'main' into tokenAuth
Sabaawi7 Jun 20, 2024
062cc91
requirements.txt
Jun 20, 2024
1701d2c
get question data and set selected answers works
GeorgiosK78 Jun 20, 2024
610cef7
Update README.md
Sabaawi7 Jun 20, 2024
5f8192c
Answers api for get and post with token
GeorgiosK78 Jun 20, 2024
6e51820
Merge branch 'answersAPI' of https://github.com/Sabaawi7/pacoBackEnd …
GeorgiosK78 Jun 20, 2024
ceaacfc
Answers api with instructions in comments
GeorgiosK78 Jun 20, 2024
496dba7
added token auth logic for user register, logout, login and view. Als…
Sabaawi7 Jun 20, 2024
a3d1050
Merge pull request #3 from Sabaawi7/Sabaawi7-patch-1
lananhvu28 Jun 20, 2024
61c5a72
falls keine daten vorhanden werden welche erzeugt
GeorgiosK78 Jun 20, 2024
f621f63
Merge branch 'main' into answersAPI
GeorgiosK78 Jun 20, 2024
19d55e3
Merge pull request #5 from Sabaawi7/answersAPI
lananhvu28 Jun 20, 2024
14f3dae
adjusted views.py to be class based
Sabaawi7 Jun 21, 2024
99d542a
Merge branch 'main' into classBasedViews
lananhvu28 Jun 21, 2024
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
This is the finished source code for the tutorial [Deploying Django with Docker Compose](https://londonappdeveloper.com/deploying-django-with-docker-compose/).

In this tutorial, we teach you how to prepare and deploying a Django project to an AWS EC2 instance using Docker Compose.

For Software Samurais:
to use run this BackendApp you need to do the following step:
1. Start the docker desktop app on your device
2. run the command "docker-compose up"
3. After making substantial changes you would need to rebuild the image. Preferrably by deleting the old image from the docker desktop app and running the command again.
4. the backed app is reachable at "localhost:8000"
8 changes: 7 additions & 1 deletion app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'core',
'rest_framework'
]

MIDDLEWARE = [
Expand Down Expand Up @@ -83,11 +85,12 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': os.environ.get('DB_HOST'),
'HOST': os.environ.get('DB_HOST', 'localhost'),
'NAME': os.environ.get('DB_NAME'),
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASS'),
}

}


Expand Down Expand Up @@ -137,3 +140,6 @@
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
3 changes: 2 additions & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('core.urls'))
]

if settings.DEBUG:
Expand Down
7 changes: 5 additions & 2 deletions app/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.contrib import admin

from core.models import Sample
from core.models import UserIDList
from core.models import Answers

admin.site.register(UserIDList)
admin.site.register(Answers)


admin.site.register(Sample)
18 changes: 15 additions & 3 deletions app/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 3.2.3 on 2021-05-17 20:01
# Generated by Django 5.0.6 on 2024-06-17 09:01

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


Expand All @@ -12,10 +13,21 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name='Sample',
name='UserIDList',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('attachment', models.FileField(upload_to='')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('userid', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Answers',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('question_type_id', models.PositiveIntegerField(default=1)),
('data', models.JSONField(blank=True, default=list, null=True)),
('userid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.useridlist')),
],
),
]
43 changes: 43 additions & 0 deletions app/core/migrations/0002_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 3.2.25 on 2024-06-20 06:17

import django.contrib.auth.models
from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
('core', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('name', models.CharField(max_length=255)),
('email', models.EmailField(max_length=254, unique=True)),
('password', models.CharField(max_length=255)),
('username', models.CharField(blank=True, max_length=255, null=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='core_user_set', related_query_name='core_user', to='auth.Group')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='core_user_set', related_query_name='core_user', to='auth.Permission')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
48 changes: 46 additions & 2 deletions app/core/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
from django.db import models
from django.contrib.auth.models import AbstractUser



class User(AbstractUser):
name = models.CharField(max_length=255)
email = models.EmailField(unique=True)
password = models.CharField(max_length=255)
username = models.CharField(max_length=255, blank=True, null=True) # to avoid potential issues

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []

# Add related_name attributes to avoid conflicts
groups = models.ManyToManyField(
'auth.Group',
related_name='core_user_set', # Avoid conflict with auth.User.groups
blank=True,
help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.',
related_query_name='core_user',
)
user_permissions = models.ManyToManyField(
'auth.Permission',
related_name='core_user_set', # Avoid conflict with auth.User.user_permissions
blank=True,
help_text='Specific permissions for this user.',
related_query_name='core_user',
)



class UserIDList(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
userid = models.CharField(max_length=200)
def __str__(self):
return self.userid


class Answers(models.Model):
userid = models.ForeignKey(UserIDList, on_delete=models.CASCADE)
question_type_id = models.PositiveIntegerField(default=1)
data = models.JSONField(default=list,null=True,blank=True)
def __str__(self):
return self.userid.userid



class Sample(models.Model):
attachment = models.FileField()
33 changes: 33 additions & 0 deletions app/core/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from rest_framework import serializers
from core.models import UserIDList
from core.models import Answers
from core.models import *

class UserSerializer(serializers.ModelSerializer):
class Meta:
model=User
fields = ["id", "name", "email", "password"]
extra_kwargs = {
"password": {"write_only":True}
}
def create(self, validated_data):
password = validated_data.pop("password", None)
instance = self.Meta.model(**validated_data)
if password is not None:
instance.set_password(password)
instance.save()
return instance


class UserIDListSerializer(serializers.ModelSerializer):
class Meta:
model=UserIDList
fields= ["created_at", "updated_at", "userid"]


class AnswersSerializer(serializers.ModelSerializer):

class Meta:
model=Answers
fields= ["userid", "question_type_id","data"]

13 changes: 13 additions & 0 deletions app/core/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

from django.urls import path
from core.views import *
urlpatterns = [
path('userid', UserIDListAPIView.as_view()),
path('useriddetail/<int:id>', UserIDListDetailsAPIView.as_view()),
path('answers', AnswersAPIView.as_view()),
path('login', LoginUserAPIView.as_view()),
path('register', RegisterUserAPIView.as_view()),
path('user', UserView.as_view()),
path('logout', LogoutUserAPIView.as_view())

]
Loading