Skip to content

Commit

Permalink
Triet: adapt some requests based on their API (#171)
Browse files Browse the repository at this point in the history
### Changes
- add another pathing for checking if an author is a follower of another
author
- Their team used int id instead of uuid, so we need to adapt to it (I
ALREADY TESTED THIS ON PROD)
- cleanup: there were console logs that made it a bit hard to debug so
removed it
- They requested to add slashes on id fields, source, and origin
- conditionally check if the request is coming from them. If yes, add
slash
  - Check connect server for more details and screenshots
  • Loading branch information
rmgutierrez authored Dec 2, 2023
2 parents 623694e + 00afa60 commit ac45cec
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
1 change: 0 additions & 1 deletion client/src/components/post/GitHubEventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ const GitHubEventsList = ({ githubUrl }: { githubUrl: string }) => {
const renderEventContent = (event: GitHubEvent) => {
switch (event.type) {
case "PushEvent":
console.log(event.payload.size);
return (
<>
<Typography>
Expand Down
2 changes: 2 additions & 0 deletions server/socialdistribution/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

# additional API endpoints
path(f"{SERVICE}authors/<uuid:author_id>/follows/<uuid:requester_id>/", FollowView.as_view(), name="follow"),
# adding this because one of the teams doesn't use uuid, so we have to receive str
path(f"{SERVICE}authors/<uuid:author_id>/followers/<str:follower_id>/", FollowerView.as_view(), name="follower_id"),

# login and signup endpoints
path(f"{SERVICE}login/", LoginView.as_view(), name="login"),
Expand Down
4 changes: 3 additions & 1 deletion server/socialdistribution/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
"http://localhost:3000/",
"https://distributed-network-37d054f03cf4.herokuapp.com/",
"http://127.0.0.1:8000/"
]
]

TRIET = "https://fakebook-frontend-f922a5dc4574.herokuapp.com/"
30 changes: 25 additions & 5 deletions server/socialdistribution/utils/serializers_utils.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
from .constants import SERVICE
from .constants import SERVICE, TRIET
from rest_framework import serializers


def build_default_author_uri(obj, request, source):
uri = request.build_absolute_uri("/")
author_id = obj.id if source == "author" else obj.author.id
return f"{uri}{SERVICE}authors/{author_id}"
referer = request.META.get("HTTP_REFERER")

if referer and referer.startswith(TRIET):
return f"{uri}{SERVICE}authors/{author_id}/"
else:
return f"{uri}{SERVICE}authors/{author_id}"

def build_default_post_uri(obj, request):
uri = request.build_absolute_uri("/")
return f"{uri}{SERVICE}authors/{obj.author.id}/posts/{obj.id}"
referer = request.META.get("HTTP_REFERER")

if referer and referer.startswith(TRIET):
return f"{uri}{SERVICE}authors/{obj.author.id}/posts/{obj.id}/"
else:
return f"{uri}{SERVICE}authors/{obj.author.id}/posts/{obj.id}"


def build_default_comment_uri(obj, request):
uri = request.build_absolute_uri("/")
return f"{uri}{SERVICE}authors/{obj.post.author.id}/posts/{obj.post.id}/comments/{obj.id}"
referer = request.META.get("HTTP_REFERER")

if referer and referer.startswith(TRIET):
return f"{uri}{SERVICE}authors/{obj.post.author.id}/posts/{obj.post.id}/comments/{obj.id}/"
else:
return f"{uri}{SERVICE}authors/{obj.post.author.id}/posts/{obj.post.id}/comments/{obj.id}"


def build_default_comments_uri(obj, request):
uri = request.build_absolute_uri("/")
return f"{uri}{SERVICE}authors/{obj.author.id}/posts/{obj.id}/comments"

referer = request.META.get("HTTP_REFERER")

if referer and referer.startswith(TRIET):
return f"{uri}{SERVICE}authors/{obj.author.id}/posts/{obj.id}/comments/"
else:
return f"{uri}{SERVICE}authors/{obj.author.id}/posts/{obj.id}/comments"


def customize_like_representation(serializer_instance, instance):
Expand Down

0 comments on commit ac45cec

Please sign in to comment.