From f073235372cc8905b2f476c00884f5b1ae5889e1 Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Sat, 27 Jan 2024 00:07:29 +0200 Subject: [PATCH 1/3] Start work on user list view in the frontend --- backend/api/serializers.py | 22 ++++++++++++++++------ backend/api/views.py | 2 +- backend/chitchat/settings.py | 9 ++++++++- frontend/src/App.jsx | 2 ++ frontend/src/pages/UsersList.jsx | 25 +++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 frontend/src/pages/UsersList.jsx diff --git a/backend/api/serializers.py b/backend/api/serializers.py index 3c41dc0..0b560f2 100644 --- a/backend/api/serializers.py +++ b/backend/api/serializers.py @@ -19,17 +19,27 @@ class Meta: ] +class FollowerSerializer(serializers.ModelSerializer): + url = serializers.HyperlinkedIdentityField( + view_name="api:profile-detail", lookup_field="pk" + ) + username = serializers.SerializerMethodField() + + def get_username(self, obj): + return f"{obj.user.username}" + + class Meta: + model = Profile + fields = ["username", "url"] + + class ProfileSerializer(serializers.ModelSerializer): url = serializers.HyperlinkedIdentityField( view_name="api:profile-detail", lookup_field="pk" ) user = serializers.SerializerMethodField() - follows = serializers.HyperlinkedIdentityField( - view_name="api:profile-detail", lookup_field="pk", many=True - ) - followers = serializers.HyperlinkedIdentityField( - view_name="api:profile-detail", lookup_field="pk", many=True - ) + follows = FollowerSerializer(many=True, read_only=True) + followers = FollowerSerializer(many=True, read_only=True) def get_user(self, obj): return obj.user.username diff --git a/backend/api/views.py b/backend/api/views.py index aa07165..8d2971c 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -58,7 +58,7 @@ class ProfileList(generics.ListAPIView): queryset = Profile.objects.all() serializer_class = ProfileSerializer - permission_classes = [permissions.IsAuthenticated] + # permission_classes = [permissions.IsAuthenticated] class ProfileDetail(generics.RetrieveAPIView): diff --git a/backend/chitchat/settings.py b/backend/chitchat/settings.py index f0aff5a..804c188 100644 --- a/backend/chitchat/settings.py +++ b/backend/chitchat/settings.py @@ -42,6 +42,7 @@ "django.contrib.staticfiles", # Third Party apps "rest_framework", + "corsheaders", # Local apps "api", "accounts", @@ -51,6 +52,7 @@ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", + "corsheaders.middleware.CorsMiddleware", # CORS "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", @@ -139,6 +141,11 @@ # Use Django's standard `django.contrib.auth` permissions, # or allow read-only access for unauthenticated users. "DEFAULT_PERMISSION_CLASSES": [ - "rest_framework.permissions.IsAuthenticated", + # "rest_framework.permissions.IsAuthenticated", ] } + + +CORS_ALLOWED_ORIGINS = [ + "http://localhost:5173", +] diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index a99d674..74f0482 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,10 +1,12 @@ import Login from "./pages/auth"; +import UsersList from "./pages/UsersList"; import { Routes, Route } from "react-router-dom"; function App() { return ( } />; + } /> ); } diff --git a/frontend/src/pages/UsersList.jsx b/frontend/src/pages/UsersList.jsx new file mode 100644 index 0000000..e81c3ce --- /dev/null +++ b/frontend/src/pages/UsersList.jsx @@ -0,0 +1,25 @@ +import React, { useEffect, useState } from "react"; + +function UsersList() { + const [users, setUsers] = useState([]); + + useEffect(() => { + fetch('http://127.0.0.1:9000/api/profiles/') + .then(response => response.json()) + .then(data => setUsers(data)); + + }, []); + + return ( +
+

Users

+ +
+ ); +} + +export default UsersList; \ No newline at end of file From f1ac37d5bc045347ca3ab97e25894950112eeb51 Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Sat, 27 Jan 2024 00:09:50 +0200 Subject: [PATCH 2/3] add dummy db --- backend/db.sqlite3.bak | Bin 0 -> 155648 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 backend/db.sqlite3.bak diff --git a/backend/db.sqlite3.bak b/backend/db.sqlite3.bak new file mode 100644 index 0000000000000000000000000000000000000000..0bb7db1dc04e27503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8#OSPvKQ?M~#>^KxF*pE-hL$&=sVL^Y2ejEKX`XQ7+6X@QV zOuzsL00AHX1b_e#00KY&2mk>f00e-*^Ge{=Q!@4eHpJjr5M3UOa+VZF(QT&K_fcj86<(f80_!f@az$=Iav!{`Okqv2VV5wg4h1D;n2piti@%s;;*cY!J(Cm|2xrFEa-pI zHvs-6`ZK)x|5u*941ppb00e*l5C8%|00;m9AOHk_01yBIK;R?+`l3Jj0ze0S0id0} z0MJ%l{h#b)>HGhzWc@#cKEa^BMgI%^1^Nbh7r*uIx6nK2=h4rge}R4ieF1$HeFA;_ zf00e*l5C8%|00;m9AOHk_01$X`0#2O7am{977^l;L$fupPd+?{rZg<-( z_~0#Gfv!#okXoaqFK%v#i5LKdp9_M6(Vn z*|giq_&;s`llFeC?O*K)Ag%wu#jXD@;P(F~o;*L00tf&BAOHk_01yBIKmZ5;0U!Vb zfB+CUNr1Hfoi>Iv|F6+cJBu7P#>Ln@4x0wCE&1F=zRWbB(x(M zdTgwVag(5rY+HLt=(tM1yJ*-$!|F2t{p34Kp8;U;dH`fX010dD|4%dMyZE{P-$efg zKmY$7^cD20_*sB=(PwZU!0(|yK%YjR{=Vi1oB;tK00e*l5C8%|00;m9AOHk_01yBI q9SPW*dH`5Nn*AQyyl?aX*qeF)ShEL!*f}jEZ0Z28HWmS}TmK)jX3m-b literal 0 HcmV?d00001 From 274f8fe1c1c3544c9bc136ba7b65025b9acd829d Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Sat, 27 Jan 2024 14:16:39 +0200 Subject: [PATCH 3/3] Added sign up view --- Contributors.md | 3 + README.md | 13 ++++ backend/accounts/admin.py | 1 + .../migrations/0003_alter_profile_follows.py | 19 ++++++ backend/accounts/models.py | 3 + backend/api/serializers.py | 16 +---- backend/api/urls.py | 1 + backend/api/views.py | 15 +++++ frontend/src/App.jsx | 2 + frontend/src/components/auth/index.jsx | 14 ++++- .../src/components/registration/index.jsx | 59 ++++++++++++++++++- frontend/src/pages/Signup/index.jsx | 6 ++ 12 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 Contributors.md create mode 100644 backend/accounts/migrations/0003_alter_profile_follows.py create mode 100644 frontend/src/pages/Signup/index.jsx diff --git a/Contributors.md b/Contributors.md new file mode 100644 index 0000000..302b67f --- /dev/null +++ b/Contributors.md @@ -0,0 +1,3 @@ +# Contributors + +## This project is a result of the hard work of the following volunteers diff --git a/README.md b/README.md index fb9a0bc..91fa6f8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ ChitChat is a Python-powered Social Network. ## Installation +### Backend + 1. cd into backend folder ```cd backend``` @@ -38,6 +40,17 @@ To run this project do the following: ```python manage.py runserver``` +### FrontEnd +1. cd into the frontend folder +```cd frontend``` + +2. Install dependencies +```npm install``` + +3. Run the development server +```npm run dev``` + + ## Contributing diff --git a/backend/accounts/admin.py b/backend/accounts/admin.py index b989fff..8a2651f 100644 --- a/backend/accounts/admin.py +++ b/backend/accounts/admin.py @@ -21,3 +21,4 @@ class CustomUserAdmin(UserAdmin): admin.site.register(CustomUser, CustomUserAdmin) admin.site.unregister(Group) +admin.site.register(Profile) diff --git a/backend/accounts/migrations/0003_alter_profile_follows.py b/backend/accounts/migrations/0003_alter_profile_follows.py new file mode 100644 index 0000000..f11234c --- /dev/null +++ b/backend/accounts/migrations/0003_alter_profile_follows.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.4 on 2024-01-26 20:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("accounts", "0002_profile"), + ] + + operations = [ + migrations.AlterField( + model_name="profile", + name="follows", + field=models.ManyToManyField( + blank=True, related_name="followers", to="accounts.profile" + ), + ), + ] diff --git a/backend/accounts/models.py b/backend/accounts/models.py index e298736..57f0d88 100644 --- a/backend/accounts/models.py +++ b/backend/accounts/models.py @@ -17,3 +17,6 @@ class Profile(models.Model): def __str__(self): return f" {self.user.username} - Profile" + + class Meta: + ordering = ["-pk"] diff --git a/backend/api/serializers.py b/backend/api/serializers.py index 0b560f2..479e2f5 100644 --- a/backend/api/serializers.py +++ b/backend/api/serializers.py @@ -2,21 +2,11 @@ from rest_framework import serializers -class UserSerializer(serializers.HyperlinkedModelSerializer): - url = serializers.HyperlinkedIdentityField( - view_name="api:user-detail", - lookup_field="pk", - ) - +class UserSerializer(serializers.ModelSerializer): class Meta: model = CustomUser - lookup_field = "pk" - fields = [ - "username", - "email", - "pk", - "url", - ] + # lookup_field = "pk" + exclude = ["password", "groups", "user_permissions", "is_staff", "is_active"] class FollowerSerializer(serializers.ModelSerializer): diff --git a/backend/api/urls.py b/backend/api/urls.py index 5e67e03..2f808bb 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -10,6 +10,7 @@ path("api/users/", views.CustomUserList.as_view(), name="users"), path("api/users//", views.CustomUserDetail.as_view(), name="user-detail"), path("api/profiles/", views.ProfileList.as_view(), name="profiles"), + path("api/signup", views.SignUpView.as_view(), name="signup-view"), path( "api/profiles//", views.ProfileDetail.as_view(), name="profile-detail" ), diff --git a/backend/api/views.py b/backend/api/views.py index 8d2971c..41d5782 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -116,3 +116,18 @@ def post(self, request, username): {"message": f"you're no longer following {profile.user.username}"}, status=200, ) + + +class SignUpView(APIView): + """ + username: str + email: str + password: str + """ + + def post(self, request): + serializer = UserSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=201) + return Response(serializer.errors, status=400) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 74f0482..dfae9d2 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,4 +1,5 @@ import Login from "./pages/auth"; +import SignUpView from "./pages/Signup"; import UsersList from "./pages/UsersList"; import { Routes, Route } from "react-router-dom"; @@ -7,6 +8,7 @@ function App() { } />; } /> + } /> ); } diff --git a/frontend/src/components/auth/index.jsx b/frontend/src/components/auth/index.jsx index 633ec01..7259a9d 100644 --- a/frontend/src/components/auth/index.jsx +++ b/frontend/src/components/auth/index.jsx @@ -1,14 +1,23 @@ import { Button, Card, TextInput, Avatar } from "flowbite-react"; +import { useState } from "react"; export default function Login() { - return ( + const [data, setData] = useState({ + email: "", + password: "" + }) + + const onChange = (e) => { + setData({ ...data, [e.target.id]: e.target.value }) + } + return (<>

Welcome to Chit-Chat

- +
+ ); } diff --git a/frontend/src/components/registration/index.jsx b/frontend/src/components/registration/index.jsx index 1ad3195..2c065d6 100644 --- a/frontend/src/components/registration/index.jsx +++ b/frontend/src/components/registration/index.jsx @@ -1,3 +1,60 @@ +import { Button, Card, TextInput, Avatar } from "flowbite-react"; +import { useState } from "react"; +import axios from "axios" + export default function Registration() { - return
Registration
; + const [data, setData] = useState({ + email: "", + password: "", + first_name: "", + last_name: "", + username: "", + }) + + const onChange = (e) => { + setData({ ...data, [e.target.id]: e.target.value }) + } + + const onSubmit = () => { + if (data.email === "" || data.password === "" || data.first_name === "" || data.last_name === "" || data.username === "") ( + alert("All fields are required") + ) + axios.post("http://localhost:8000/api/signup", data).then((res) => { + alert("Successfully signed up") + }).catch((err) => { + alert("Failed to submit") + }) + } + + return
+ + +

Welcome to Chit-Chat

+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + + +
+
} diff --git a/frontend/src/pages/Signup/index.jsx b/frontend/src/pages/Signup/index.jsx new file mode 100644 index 0000000..ced247a --- /dev/null +++ b/frontend/src/pages/Signup/index.jsx @@ -0,0 +1,6 @@ +import Registration from "../../components/registration"; + + +export default function SignUpView() { + return +} \ No newline at end of file