-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85cab5c
commit 6ef4825
Showing
29 changed files
with
380 additions
and
18 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CommunityConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'community' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.contrib.auth.models import User | ||
from django.conf import settings | ||
from rest_framework import authentication, exceptions | ||
import jwt | ||
|
||
class JWTAuthentication(authentication.BaseAuthentication): | ||
def authenticate(self, request): | ||
auth_header = authentication.get_authorization_header(request).decode('utf-8') | ||
if not auth_header or not auth_header.startswith('Bearer '): | ||
print("No JWT token found in request headers") | ||
return None | ||
|
||
token = auth_header.split(' ')[1] | ||
try: | ||
payload = jwt.decode(token, settings.SUPABASE_SECRET_KEY, algorithms=['HS256'], audience='authenticated') | ||
user_id = payload['sub'] | ||
email = payload.get('email', '') | ||
first_name = payload.get('user_metadata', {}).get('first_name', '') | ||
last_name = payload.get('user_metadata', {}).get('last_name', '') | ||
|
||
# Check if the user exists and update/create accordingly | ||
user, created = User.objects.get_or_create(username=user_id, defaults={ | ||
'first_name': first_name, | ||
'last_name': last_name, | ||
'email': email | ||
}) | ||
|
||
# If the user was not created (i.e., it already exists), update its details | ||
if not created: | ||
user.first_name = first_name | ||
user.last_name = last_name | ||
user.email = email | ||
user.save() | ||
|
||
if created: | ||
print("\nNew user authenticated and created") | ||
else: | ||
print("User authenticated") | ||
|
||
return (user, token) | ||
|
||
except jwt.ExpiredSignatureError: | ||
raise exceptions.AuthenticationFailed('Token expired, login again') | ||
except jwt.InvalidTokenError: | ||
raise exceptions.AuthenticationFailed('Invalid token') | ||
except Exception as e: | ||
raise exceptions.AuthenticationFailed(f'Unexpected error during authentication: {e}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from supabase import create_client, Client | ||
from django.conf import settings | ||
|
||
def get_supabase_client() -> Client: | ||
url: str = settings.SUPABASE_URL | ||
key: str = settings.SUPABASE_KEY | ||
return create_client(url, key) | ||
|
||
def fetch_post(): | ||
client = get_supabase_client() | ||
data = client.table('posts').select('*').execute() | ||
return data |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
from django.utils import timezone # Import timezone | ||
|
||
class Posts(models.Model): | ||
post_id = models.CharField(max_length=255, unique=True) | ||
post_title = models.CharField(max_length=255) | ||
post_content = models.CharField(max_length=255) | ||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='postList') | ||
likes = models.IntegerField(default=0) | ||
posted_at = models.DateTimeField(default=timezone.now) # Set default to the current time | ||
|
||
def __str__(self): | ||
return self.title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from django.http import JsonResponse | ||
import json | ||
from django.shortcuts import render | ||
from rest_framework.views import APIView | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from django.shortcuts import get_object_or_404 | ||
from .db_GetPostData import fetch_post #HERE DO FUNCTIONS IG. | ||
from .models import Posts | ||
from django.contrib.auth.models import User | ||
|
||
#def post(request): | ||
# all_posts = Posts.objects.all | ||
# return render(request, '../../web/src/components/post.js') | ||
|
||
class TaskListCreate(APIView): | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get(self, request): | ||
user_uuid = request.user.username | ||
|
||
try: | ||
response = fetch_post() | ||
postList = [] | ||
|
||
if response.data: | ||
for post_data in response.data: | ||
user, _ = User.objects.get_or_create(username=post_data['post_id']) | ||
post = Posts.objects.update_or_create( | ||
post_id = post_data['post_id'], | ||
defaults={ | ||
'post_title': post_data['post_title'], | ||
'posted_at': post_data['posted_at'], | ||
'post_content': post_data['post_content'], | ||
'likes':post_data['likes'], | ||
'user': user, | ||
} | ||
) | ||
|
||
postList.append({ | ||
'post_id': post.post_id, | ||
'post_title': post.post_title, | ||
'post_content': post.post_content, | ||
'likes': post.likes, | ||
'posted_at': post.posted_at | ||
}) | ||
|
||
print(len(postList), "tasks found") | ||
|
||
return JsonResponse({'tasks': postList}, safe=False) | ||
|
||
except Exception as e: | ||
print("Error syncing tasks") | ||
print(e) | ||
return JsonResponse({'error': 'Failed to fetch and sync tasks.'}, status=500) |
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
backend/to_do_list/__pycache__/authentication.cpython-310.pyc
Binary file not shown.
Binary file modified
BIN
+359 Bytes
(150%)
backend/to_do_list/__pycache__/db_service.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
backend/to_do_list/migrations/__pycache__/0001_initial.cpython-310.pyc
Binary file not shown.
Binary file added
BIN
+1.03 KB
..._list/migrations/__pycache__/0002_task_task_id_task_title_alter_task_user.cpython-310.pyc
Binary file not shown.
Binary file added
BIN
+723 Bytes
backend/to_do_list/migrations/__pycache__/0003_task_created_at.cpython-310.pyc
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
backend/to_do_list/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,67 @@ | ||
import React from 'react' | ||
import React, {useState, useEffect, useCallback} from "react"; | ||
import "../css/post.css" | ||
function post() { | ||
import UserIcon from "../assets/images/UserIcon.png" | ||
function Post() { | ||
const [postList, setPosts] = useState([]); | ||
|
||
const fetchPosts = useCallback(async () => { | ||
const response = await fetch('/community/postList', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
const data = await response.json(); | ||
if (data && data.postList) { | ||
setPosts(data.postList); | ||
} else { | ||
// Handle any errors or empty responses | ||
console.error('Failed to fetch tasks or no tasks available'); | ||
} | ||
}, ); | ||
useEffect(() => { | ||
fetchPosts(); | ||
}, [fetchPosts]); | ||
|
||
|
||
|
||
const [liked, setLike] = useState(false); | ||
|
||
const handleLike = () => { | ||
setLike(!liked); | ||
}; | ||
|
||
const [flagged, setFlag] = useState(false); | ||
|
||
const handleFlag = () => { | ||
setFlag(!flagged); | ||
}; | ||
return ( | ||
<div> | ||
|
||
<div className="postss"> | ||
<button className="navbar-button" onClick={fetchPosts}>Fetch posts</button> | ||
|
||
{postList.map((postList, index) => ( | ||
<div key={index} className='PostHolder'> | ||
{/*Insert users profile picture here */}<div className="imgHolder"><img src={UserIcon} /></div> | ||
<div className="Postinfo"> | ||
{/*Insert post title here */} <h3 className="PostTitle">{postList.post_title}</h3> | ||
<div className="infoContent"><p>{postList.post_content}</p></div> | ||
</div> | ||
{/*Insert users Name here */} <h3 className="Name">{postList.user}</h3> | ||
<button className={`likeButton ${liked ? 'clicked' : ''}`} onClick={handleLike}> | ||
</button> | ||
<button className={`flag ${flagged ? 'clicked' : ''}`} onClick={handleFlag}> | ||
</button> | ||
{/*Insert date posted here */} <h4 className="PostDate">{postList.posted_at}</h4> | ||
</div> | ||
))} | ||
{/*<div className = "PostHolder"> </div> */} | ||
|
||
|
||
|
||
|
||
</div> | ||
) | ||
} | ||
|
||
export default post | ||
export default Post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useState } from 'react'; | ||
import "../css/post.css" | ||
import UserIcon from "../assets/images/UserIcon.png" | ||
function Post() { | ||
const [liked, setLike] = useState(false); | ||
|
||
const handleLike = () => { | ||
setLike(!liked); | ||
}; | ||
|
||
const [flagged, setFlag] = useState(false); | ||
|
||
const handleFlag = () => { | ||
setFlag(!flagged); | ||
}; | ||
return ( | ||
<div className = "PostHolder"> | ||
{/*Insert users profile picture here */}<div className="imgHolder"><img src={UserIcon} /></div> | ||
<div className="Postinfo"> | ||
{/*Insert post title here */} <h3 className="PostTitle">Happiness</h3> | ||
<div className="infoContent"><p>dgsi fodj sdjfids jiofnioa hg iohparuiogbuah bpaoiidfsn nje fnsjfknsndfj nsk fnsn fdk slnfd kskd fnsanfdknas kdfna dfknasdkf nsdanf ksadn fknas dkfnask nfdksnf kdnsafkl nas;lf nads;n fdas nfksadn fn;asdnf;aldfn;ansfd ndnfasndfla ndfln asnf asnfd ;lasnf d;nasdfk; adfdklasn f;las flk;andsfkl nasdnf kas f;ldnaks nfd;ak nsflkdan s;kfldn aklsdnf ;asdn fl;aks nf u phg iowah nuifp hnaw uibhefubqwu brigf ehrifje hgbrgui bg uihqe ugta ehig prqhuiri hh rp ibaeur buiarh angrjg nabgur aug boib g oa</p></div> | ||
</div> | ||
{/*Insert users Name here */} <h3 className="Name">Jane</h3> | ||
<button className={`likeButton ${liked ? 'clicked' : ''}`} onClick={handleLike}> | ||
</button> | ||
<button className={`flag ${flagged ? 'clicked' : ''}`} onClick={handleFlag}> | ||
</button> | ||
{/*Insert date posted here */} <h4 className="PostDate">01/04/24</h4> | ||
</div> | ||
) | ||
} | ||
|
||
export default Post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
.PostHolder { | ||
border-radius: 33px; | ||
border: 2px solid #FF004F; | ||
background: rgba(255, 255, 255, 0.80); | ||
width: 50vw; | ||
height: 13vh; | ||
margin-top: 2vh; | ||
padding: 10px; | ||
display: flex; | ||
flex-direction: row; | ||
color: black; | ||
} | ||
|
||
.PostHolder .imgHolder { | ||
width: 10vh; /* Make width and height equal for square shape */ | ||
height: 10vh; | ||
border-radius: 4px; | ||
border: 3px solid #FF004F; | ||
background: #D9D9D9; | ||
margin-top: 0.6vh; | ||
margin-left: 0.2vw; | ||
} | ||
|
||
.PostHolder .imgHolder img { | ||
max-width: 100%; /* Make the image fill the container horizontally */ | ||
max-height: 100%; /* Make the image fill the container vertically */ | ||
} | ||
|
||
.PostHolder .Postinfo { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
width: 75%; | ||
word-wrap: break-word; | ||
font-size: 15px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: 114.583%; /* 22.917px */ | ||
margin-top: 1vh; | ||
margin-left: 0.5vw; | ||
|
||
} | ||
|
||
.PostHolder .PostTitle{ | ||
text-shadow: none; | ||
font-size: 40px; | ||
font-style: normal; | ||
font-weight: 500; | ||
letter-spacing: 2.8px; | ||
|
||
text-align: left; | ||
} | ||
.PostHolder .infoContent{ | ||
margin-top: 1vh; | ||
overflow-y: hidden; | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
.PostHolder .likeButton { | ||
background-color: grey; /* Change to your desired color */ | ||
width: 3vh; /* Make width and height equal for square shape */ | ||
height: 3vh; | ||
border-radius: 50px; | ||
margin-top: 8vh; | ||
} | ||
|
||
.PostHolder .likeButton.clicked { | ||
background-color: red; /* Change to your desired color */ | ||
} | ||
|
||
.PostHolder .Name{ | ||
margin-left: -3vw; | ||
font-size: 22px; | ||
} | ||
.PostHolder .flag{ | ||
margin-top: 3.5vh; | ||
background-color: rgb(212, 212, 212); /* Change to your desired color */ | ||
width: 3vh; /* Make width and height equal for square shape */ | ||
height: 3vh; | ||
border-radius: 50px; | ||
} | ||
.PostHolder .flag.clicked { | ||
background-color: rgb(2, 81, 110); /* Change to your desired color */ | ||
} |
Oops, something went wrong.