Compare commits

..

No commits in common. "54cc1b1705b519f53d431094a4ea2d3ae50d4ce8" and "e253631f094e36d172a6ee6b20fb4742599efbb1" have entirely different histories.

8 changed files with 3 additions and 52 deletions

View File

@ -23,7 +23,7 @@ class RegisterView(View):
if User.objects.filter(username=username).exists(): if User.objects.filter(username=username).exists():
return HttpResponse(USERNAME_ALREADY_USED) return HttpResponse(USERNAME_ALREADY_USED)
user: User = User.objects.create_user(username, password=password) user = User.objects.create_user(username, password=password)
user.save() user.save()
return HttpResponse(USER_ADDED) return HttpResponse(USER_ADDED)

View File

@ -1,6 +1,3 @@
from django.contrib import admin from django.contrib import admin
from .models import Profile
# Register your models here. # Register your models here.
admin.site.register(Profile)

View File

@ -1,16 +1,3 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
# Create your models here. # Create your models here.
class Profile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=40)
@receiver(post_save, sender=User)
def on_user_created(sender, instance, created, **kwargs):
if created:
profile: Profile = Profile.objects.create(pk = instance.pk, user = instance)
profile.save()

View File

@ -1 +0,0 @@
PROFILE_NOT_FOUND = "Profile Not Found"

View File

@ -1,17 +1,3 @@
from django.test import TestCase from django.test import TestCase
from django.http import HttpResponse, HttpRequest
from django.contrib.auth.models import User
# Create your tests here. # Create your tests here.
class ProfileTest(TestCase):
def setUp(self):
self.user: User = User.objects.create(username='bozo', password='password')
self.user.save()
self.expected_response = {"username": "bozo",
"title": ""}
def test_profile_create_on_user_created(self):
response: HttpResponse = self.client.get(f"/api/profiles/{self.user.pk}")
response_dict: dict = eval(response.content)
self.assertEqual(self.expected_response, response_dict)

View File

@ -3,5 +3,5 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path("<int:id>", views.ProfilePage.as_view(), name="profile_page"), path("<str:uuid>", views.ProfilePage.as_view(), name="profile_page"),
] ]

View File

@ -1,21 +1,3 @@
from django.shortcuts import render from django.shortcuts import render
from django.views import View
from django.http import HttpResponse, HttpRequest
from django.contrib.auth.models import User
from django.http import JsonResponse
from .status_code import *
from .models import Profile
# Create your views here. # Create your views here.
class ProfilePage(View):
def get(self, request: HttpRequest, id: int):
query: QuerySet = Profile.objects.filter(pk=id)
if (not query.exists()):
return HttpResponse(PROFILE_NOT_FOUND)
profile: Profile = Profile.objects.get(pk=id)
return JsonResponse({'username': profile.user.username,
'title': profile.title})

View File

@ -20,5 +20,5 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api/accounts/', include('accounts.urls')), path('api/accounts/', include('accounts.urls')),
path('api/profiles/', include('profiles.urls')), path('api/profiles/', include('accounts.urls')),
] ]