-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
94 changed files
with
5,720 additions
and
351 deletions.
There are no files selected for viewing
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
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,68 @@ | ||
name: Lint Code | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
- "master" | ||
pull_request: | ||
branches: | ||
- "main" | ||
- "master" | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.8, 3.9] | ||
|
||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install OpenSSL | ||
run: sudo apt-get install -y openssl | ||
|
||
- name: Generate private and public keys | ||
run: | | ||
rm -rf security | ||
mkdir -p security | ||
openssl genpkey -algorithm RSA -out security/private_key.pem -pkeyopt rsa_keygen_bits:2048 | ||
openssl rsa -pubout -in security/private_key.pem -out security/public_key.pem | ||
echo "Private key saved as security/private_key.pem" | ||
echo "Public key saved as security/public_key.pem" | ||
- name: Create .env file | ||
run: | | ||
touch .env | ||
echo PRIVATE_KEY_PATH=$(pwd)/security/private_key.pem >> .env | ||
echo PUBLIC_KEY_PATH=$(pwd)/security/public_key.pem >> .env | ||
DJANGO_SETTINGS_MODULE=core.settings.development >> .env | ||
echo DATABASE_ENVIRON=sqlite3 >> .env | ||
- name: Check if .env has been updated | ||
run: cat .env | ||
|
||
- name: Install Dependencies | ||
run: | | ||
pip install flake8 | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Lint Code | ||
run: flake8 . | ||
|
||
- name: Clean up keys (Optional) | ||
run: | | ||
rm -rf security | ||
echo "Keys removed after use." |
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 |
---|---|---|
|
@@ -140,4 +140,5 @@ GitHub.sublime-settings | |
# private_key.pem | ||
# public_key.pem | ||
|
||
db.sqlite3 | ||
db.sqlite3 | ||
poetry.lock |
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,18 @@ | ||
from rest_framework import routers | ||
|
||
from .blog import ( | ||
PostViewSet, | ||
PostCommentViewSet, | ||
PostCommentLikeViewSet, | ||
PostLikeViewSet, | ||
PostDislikeViewSet, | ||
) | ||
|
||
router = routers.DefaultRouter() | ||
router.register("post", PostViewSet, basename="post") | ||
router.register("post_comment", PostCommentViewSet, basename="post-comment") | ||
router.register( | ||
"post_comment_like", PostCommentLikeViewSet, basename="post-comment-like" | ||
) | ||
router.register("post_like", PostLikeViewSet, basename="post-like") | ||
router.register("post_dislike", PostDislikeViewSet, basename="post-dislike") |
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 @@ | ||
from .views import * # noqa |
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,24 @@ | ||
from rest_framework import serializers | ||
|
||
from apps.blog.models import Post | ||
|
||
|
||
class PostSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Post | ||
fields = [ | ||
"id", | ||
"title", | ||
"get_absolute_url", | ||
"status", | ||
"description", | ||
"publisher_at", | ||
"is_active", | ||
"author", | ||
"like_count", | ||
"dislike_count", | ||
"comment_count", | ||
"watching", | ||
"created_at", | ||
"updated_at", | ||
] |
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,17 @@ | ||
from rest_framework import viewsets, permissions | ||
|
||
from apps.blog.models import Post | ||
from .serializer import PostSerializer | ||
|
||
|
||
class PostViewSet(viewsets.ModelViewSet): | ||
queryset = Post.published.all().order_by("-created_at") | ||
serializer_class = PostSerializer | ||
|
||
def get_permissions(self): | ||
if self.action in ["list", "retrieve"]: | ||
return [permissions.AllowAny()] | ||
return [permissions.IsAuthenticated()] | ||
|
||
|
||
__all__ = ("PostViewSet",) |
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 @@ | ||
from .views import * # noqa |
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,25 @@ | ||
from rest_framework import serializers | ||
|
||
from apps.blog.models import PostComment, Post | ||
from apps.users.models import User | ||
|
||
|
||
class MiniPostCommentUser(serializers.ModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = ["id", "username", "email", "created_at", "updated_at"] | ||
|
||
|
||
class MiniPostCommentPost(serializers.ModelSerializer): | ||
class Meta: | ||
model = Post | ||
fields = ["id", "title", "created_at", "updated_at"] | ||
|
||
|
||
class PostCommentSerializer(serializers.ModelSerializer): | ||
user = MiniPostCommentUser(read_only=True) | ||
comment = MiniPostCommentPost(read_only=True) | ||
|
||
class Meta: | ||
model = PostComment | ||
fields = ["id", "user", "comment", "created_at", "updated_at"] |
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,17 @@ | ||
from rest_framework import viewsets, permissions | ||
|
||
from apps.blog.models import PostComment | ||
from .serializers import PostCommentSerializer | ||
|
||
|
||
class PostCommentViewSet(viewsets.ModelViewSet): | ||
queryset = PostComment.objects.all().order_by("-created_at") | ||
serializer_class = PostCommentSerializer | ||
|
||
def get_permissions(self): | ||
if self.action in ["list", "retrieve"]: | ||
return [permissions.AllowAny()] | ||
return [permissions.IsAuthenticated()] | ||
|
||
|
||
__all__ = ("PostCommentViewSet",) |
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 @@ | ||
from .views import * # noqa |
24 changes: 24 additions & 0 deletions
24
apps/blog/api_endpoints/blog/PostCommentLike/serializers.py
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,24 @@ | ||
from rest_framework import serializers | ||
|
||
from apps.blog.models import PostCommentLike | ||
from apps.users.models import User | ||
|
||
|
||
class MiniPostCommentLikeUserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = ["id", "username", "created_at", "updated_at"] | ||
|
||
|
||
class MiniPostCommentLikePostCommentSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
fields = ["id", "post", "message", "created_at", "updated_at"] | ||
|
||
|
||
class PostCommentLikeSerializer(serializers.ModelSerializer): | ||
user = MiniPostCommentLikeUserSerializer(read_only=True) | ||
comment = MiniPostCommentLikePostCommentSerializer(read_only=True) | ||
|
||
class Meta: | ||
model = PostCommentLike | ||
fields = ["id", "user", "comment"] |
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,13 @@ | ||
from rest_framework import viewsets, permissions | ||
|
||
from apps.blog.models import PostCommentLike | ||
from .serializers import PostCommentLikeSerializer | ||
|
||
|
||
class PostCommentLikeViewSet(viewsets.ModelViewSet): | ||
queryset = PostCommentLike.objects.all().order_by("-id") | ||
serializer_class = PostCommentLikeSerializer | ||
permission_classes = [permissions.IsAuthenticated] | ||
|
||
|
||
__all__ = ("PostCommentLikeViewSet",) |
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 @@ | ||
from .views import * # noqa |
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,9 @@ | ||
from rest_framework import serializers | ||
|
||
from apps.blog.models import PostDislike | ||
|
||
|
||
class PostDislikeSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = PostDislike | ||
fields = ["id", "user", "post"] |
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,34 @@ | ||
from django.shortcuts import get_object_or_404 | ||
|
||
from rest_framework import viewsets, response, status, permissions | ||
|
||
from apps.blog.models import PostDislike, PostLike, Post | ||
from .serializers import PostDislikeSerializer | ||
|
||
|
||
class PostDislikeViewSet(viewsets.ModelViewSet): | ||
queryset = PostDislike.objects.all() | ||
serializer_class = PostDislikeSerializer | ||
permission_classes = [permissions.IsAuthenticated] | ||
|
||
def create(self, request, *args, **kwargs): | ||
post_id = request.data.get("post") | ||
post = get_object_or_404(Post, id=post_id) | ||
user = request.user | ||
|
||
PostLike.objects.filter(post=post, user=user).delete() | ||
|
||
existing_dislike = PostDislike.objects.filter(post=post, user=user) | ||
if existing_dislike.exists(): | ||
existing_dislike.delete() | ||
return response.Response( | ||
{"message": "Dislike removed"}, status=status.HTTP_200_OK | ||
) | ||
|
||
dislike = PostDislike.objects.create(post=post, user=user) | ||
serializer = self.get_serializer(dislike) | ||
|
||
return response.Response(serializer.data, status=status.HTTP_201_CREATED) | ||
|
||
|
||
__all__ = ("PostDislikeViewSet",) |
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 @@ | ||
from .views import * # noqa |
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,9 @@ | ||
from rest_framework import serializers | ||
|
||
from apps.blog.models import PostLike | ||
|
||
|
||
class PostLikeSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = PostLike | ||
fields = ["id", "user", "post"] |
Empty file.
Oops, something went wrong.