Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
YouweiPeng committed Dec 9, 2023
2 parents ab39c18 + 485cc6e commit ace1f51
Show file tree
Hide file tree
Showing 76 changed files with 1,460 additions and 160 deletions.
Binary file modified backend/comment/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified backend/comment/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file modified backend/comment/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file modified backend/comment/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified backend/comment/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file modified backend/comment/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified backend/comment/__pycache__/views.cpython-310.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion backend/comment/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from .models import Comment
from .models import Comment, remoteComment

admin.site.register(Comment)
admin.site.register(remoteComment)
# Register your models here.
Binary file not shown.
Binary file modified backend/comment/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions backend/comment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,16 @@ class Comment(models.Model):
published=models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.comment + " by " + self.author.displayName

class remoteComment(models.Model):
type=models.CharField(default="comment",max_length=1024)
id=models.AutoField(primary_key=True)
author=models.CharField(max_length=1024)
displayName=models.CharField(max_length=1024,default="unknown")
post=models.ForeignKey(Post,on_delete=models.CASCADE)
comment=models.TextField()
contentType=models.CharField(max_length=1024, default="text/plain")
published=models.DateTimeField(auto_now_add=True)
server=models.CharField(max_length=1024,default="unknown")
def __str__(self):
return self.comment + " by " + self.displayName
9 changes: 7 additions & 2 deletions backend/comment/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from rest_framework import serializers
from .models import Comment
from .models import Comment,remoteComment

class CommentSerializer(serializers.ModelSerializer):
class Meta:
model=Comment
fields=["id","author","post","comment","contentType","published"]
fields=["id","author","post","comment","contentType","published"]

class remoteCommentSerializer(serializers.ModelSerializer):
class Meta:
model=remoteComment
fields="__all__"
3 changes: 2 additions & 1 deletion backend/comment/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ def test_post_comment(self):
response = self.client.post(url, comment_data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Comment.objects.count(), 2)



2 changes: 1 addition & 1 deletion backend/comment/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

urlpatterns = [
path('authors/<str:pk>/posts/<str:postID>/comments', views.comment_on_post, name='comment_on_post'),

path('remote/posts/<str:postID>/comments', views.remote_comment_on_post, name='remote_comment_on_post'),
]
28 changes: 25 additions & 3 deletions backend/comment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.decorators import api_view
from .models import Comment
from .serializers import CommentSerializer
from .models import Comment,remoteComment
from .serializers import CommentSerializer, remoteCommentSerializer
from user.models import User
from post.models import Post
from drf_yasg import openapi
Expand All @@ -27,6 +27,8 @@ def comment_on_post(request,pk,postID):
if request.method=='GET':
comments=Comment.objects.filter(post=postID)
serializer=CommentSerializer(comments,many=True)
remote_comments=remoteComment.objects.filter(post=postID)
remote_serializer=remoteCommentSerializer(remote_comments,many=True)
for comment in serializer.data:
comment["author"]={
"id":comment["author"],
Expand All @@ -36,7 +38,10 @@ def comment_on_post(request,pk,postID):
"github":User.objects.get(pk=comment["author"]).github,
"profileImage":User.objects.get(pk=comment["author"]).profileImage
}
return Response(serializer.data,status=status.HTTP_200_OK)
print(remote_serializer.data)
print(serializer.data)
response=serializer.data+remote_serializer.data
return Response(response,status=status.HTTP_200_OK)
elif request.method=='POST':
serializer=CommentSerializer(data=request.data)
if serializer.is_valid():
Expand All @@ -46,3 +51,20 @@ def comment_on_post(request,pk,postID):
post.save()
return Response(serializer.data,status=status.HTTP_201_CREATED)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)

@api_view(['GET', 'POST'])
def remote_comment_on_post(request,postID):
if request.method=='GET':
comments=remoteComment.objects.filter(post=postID)
serializer=remoteCommentSerializer(comments,many=True)
return Response(serializer.data,status=status.HTTP_200_OK)
elif request.method=='POST':
post_obj=Post.objects.get(pk=postID)
request.data["post"]=postID
serializer=remoteCommentSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
post_obj.count+=1
post_obj.save()
return Response(serializer.data,status=status.HTTP_201_CREATED)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
Binary file modified backend/db.sqlite3
Binary file not shown.
Binary file modified backend/friendship/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified backend/friendship/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file modified backend/friendship/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file modified backend/friendship/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified backend/friendship/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file modified backend/friendship/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified backend/friendship/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
33 changes: 26 additions & 7 deletions backend/friendship/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ def remote_friend_request_methods(request,pk,fk):
except remoteFriendRequest.DoesNotExist:
return Response({"message":{f"Friend request does not exist "}},status=status.HTTP_404_NOT_FOUND)
friend_request.delete()
user_ids=list(User.objects.values_list('id', flat=True))
user_ids_str = [str(user_id) for user_id in user_ids]
if fk in user_ids_str:
inbox_object=Inbox.objects.get(author=fk)
inbox_object.items["friendrequests"]=[]
inbox_object.save()
if remoteFriendship.objects.filter(from_user=pk,to_user=fk).exists():
remote_friendship=remoteFriendship.objects.get(from_user=pk,to_user=fk)
remote_friendship.delete()
return Response({"message":"friend request deleted"},status=status.HTTP_200_OK)
elif request.method=='POST':
friend_request=remoteFriendRequest.objects.filter(from_user=pk,to_user=fk)
Expand All @@ -263,13 +272,17 @@ def remote_friend_request_methods(request,pk,fk):
serializer=remoteFriendRequestSerializer(data={"from_user":pk,"to_user":fk, "server": request.data["server"]})
if serializer.is_valid():
serializer.save()
# inbox_object=Inbox.objects.get(author=fk)
# message=serializer.data
# message["from_user_name"]=pk
# message["to_user_name"]=User.objects.get(id=fk).displayName
# message["summary"]=f"{message['from_user_name']} sent you a friend request"
# inbox_object.items["friendrequests"].append(message)
# inbox_object.save()
user_ids=list(User.objects.values_list('id', flat=True))
user_ids_str = [str(user_id) for user_id in user_ids]
if fk in user_ids_str:
inbox_object=Inbox.objects.get(author=fk)
message=serializer.data
message["from_user_name"]=request.data["displayName"]
message["to_user_name"]=User.objects.get(id=fk).displayName
message["summary"]=f"{message['from_user_name']} sent you a friend request"
message["server"]=request.data["server"]
inbox_object.items["friendrequests"].append(message)
inbox_object.save()
return Response(serializer.data,status=status.HTTP_201_CREATED)
elif request.method=='PUT':
try:
Expand All @@ -281,6 +294,12 @@ def remote_friend_request_methods(request,pk,fk):
friend_request.save()
remote_friendship=remoteFriendship.objects.create(from_user=pk,to_user=fk, server=request.data["server"])
remote_friendship.save()
user_ids=list(User.objects.values_list('id', flat=True))
user_ids_str = [str(user_id) for user_id in user_ids]
if fk in user_ids_str:
inbox_object=Inbox.objects.get(author=fk)
inbox_object.items["friendrequests"]=request.data["friendrequests"]
inbox_object.save()
return Response({"message":"friend request status changed"},status=status.HTTP_200_OK)
else:
return Response({"message":{f"Friend request is not pending"}},status=status.HTTP_400_BAD_REQUEST)
Expand Down
Binary file added backend/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified backend/post/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified backend/post/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file modified backend/post/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file modified backend/post/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified backend/post/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file modified backend/post/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified backend/post/__pycache__/views.cpython-310.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion backend/post/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from .models import Post
from .models import Post,Image
admin.site.register(Post)
admin.site.register(Image)
# Register your models here.
13 changes: 13 additions & 0 deletions backend/post/beeg-yoshi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "beeg-yoshi",
"private_key_id": "d488d007cc41a940b7e29d2de4d3a5b3c753745a",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDIAvj5RCAN76vt\nV38QU33xL58xw65GazwBaEy/0DKn7pn9XPCbeziW82ELMLUuNjAZ5u7qtDBc2KPU\nIwQgzQvFrWfzYSlKpyKDUeEDQ/0HwV1ftXb70/XOrpKqrxianoaYxCQwDW5vhC4Q\naxHzsFqsVb/YN1yNZQ8wYvHxCnCNuU3l+rGelnqbkFspEo/jtfzO8jfooz8t14XU\n1VPszgydNN4phgHpCVpwg6neJjb9Q9bnJSHtF5oBLcqIQeEsMIkfnlmV4Kcn/C95\nDUO1LodHF9cv4RysoIxBy5yggvqtZpi5fi/DHs9uYXl6fCt/Cgw9HGwYXECJe4oE\nt0jT7KBTAgMBAAECggEAYozQZ2WxU5yRvpa7lWxGJGY+DtOnlav1u43ML0DjDMqs\nlmHKbhnHVt1hphVgWH47si+O7hdNsxnNk1OTj6PoloSsMQfhRBbZExJvh9/il4Un\nwGZV05xrQ+TRgIdY3KqakEAowoKDtS/QUKepB0UQUFTJ+7u/fy3Zz5IZOxbVQYa7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\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "107045459258425906515",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/beeg-yoshi-upload%40beeg-yoshi.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}
Binary file modified backend/post/migrations/__pycache__/0001_initial.cpython-310.pyc
Binary file not shown.
Binary file modified backend/post/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
16 changes: 11 additions & 5 deletions backend/post/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class Post(models.Model):
type=models.CharField(default="post",max_length=1024)
title=models.CharField(max_length=512)
id=models.AutoField(primary_key=True)
source=models.CharField(max_length=1024)
origin=models.CharField(max_length=1024)
description=models.CharField(max_length=1024)
contentType=models.CharField(max_length=1024)
content=models.TextField()
source=models.CharField(max_length=1024, blank=True)
origin=models.CharField(max_length=1024, blank=True)
description=models.CharField(max_length=1024, blank=True)
contentType=models.CharField(max_length=1024, default="text/plain")
content=models.TextField(blank=True)
author=models.ForeignKey(User,on_delete=models.CASCADE)
categories=models.JSONField(blank=True,null=True)
count=models.PositiveIntegerField(default=0)
Expand All @@ -26,3 +26,9 @@ class Visibility(models.TextChoices):
unlisted = models.BooleanField(default=False)
def __str__(self):
return self.content

class Image(models.Model):
post=models.ForeignKey(Post,on_delete=models.CASCADE)
image=models.URLField()
def __str__(self):
return self.post.title
6 changes: 5 additions & 1 deletion backend/post/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from rest_framework import serializers
from .models import Post
from .models import Post,Image

class PostSerializer(serializers.ModelSerializer):
class Meta:
model=Post
# fields=["type","title","id","author","source","origin","description","contentType","content"]
fields="__all__"
class ImageSerializer(serializers.ModelSerializer):
class Meta:
model=Image
fields="__all__"
4 changes: 3 additions & 1 deletion backend/post/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def setUp(self):
source="Test source1",
origin="Test origin1",
description="Test description1",
contentType="text/plain",
contentType="text/plain",
categories= ['test1', 'test2']
)
self.private_post = Post.objects.create(
title='Private Post',
Expand All @@ -43,6 +44,7 @@ def setUp(self):
origin="Test origin1",
description="Test description1",
contentType="text/plain",
categories= ['test1', 'test2']
)
self.client = APIClient()

Expand Down
4 changes: 3 additions & 1 deletion backend/post/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from django.urls import path
urlpatterns = [
path('authors/<str:pk>/posts/', views.create_post, name='create_post'),
path('authors/<str:pk>/posts/<str:postID>', views.post_method, name='post_method'),
path('authors/<str:pk>/posts/<str:postID>/', views.post_method, name='post_method'),
path('authors/get/<str:pk>/posts/', views.get_public_and_friends_posts, name='get_public_and_friends_posts'),
path('get/public/posts/', views.get_public_posts, name='get_public_posts'),
path('authors/<str:pk>/posts/<str:postID>/image', views.image_method, name='image_method'),
path('get/all/images/', views.get_all_images, name='get_all_images'),
]
Loading

0 comments on commit ace1f51

Please sign in to comment.