-
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.
Merge pull request #27 from jundm/feature/post
Feature/post
- Loading branch information
Showing
92 changed files
with
29,474 additions
and
3,079 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
27 changes: 0 additions & 27 deletions
27
backend/accounts/migrations/0002_customuser_date_joined_customuser_updated_on.py
This file was deleted.
Oops, something went wrong.
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
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 +1,128 @@ | ||
from django.contrib.auth import get_user_model | ||
from drf_yasg.utils import swagger_auto_schema | ||
from requests import Response | ||
from rest_framework import serializers, status | ||
from rest_framework.decorators import api_view | ||
from rest_framework.generics import get_object_or_404, CreateAPIView | ||
from rest_framework_simplejwt.views import ( | ||
TokenBlacklistView, | ||
TokenObtainPairView, | ||
TokenRefreshView, | ||
TokenVerifyView, | ||
) | ||
from accounts.serializers import UsernameUniqueCheckSerializer | ||
|
||
# format=None https://www.django-rest-framework.org/tutorial/2-requests-and-responses/#adding-optional-format-suffixes-to-our-urls | ||
class UsernameUniqueCheck(CreateAPIView): | ||
serializer_class = UsernameUniqueCheckSerializer | ||
|
||
def post(self, request, format=None): | ||
print(request, "발발") | ||
serializer = self.get_serializer( | ||
data=request.data, context={"request": request} | ||
) | ||
if serializer.is_valid(): | ||
print(serializer.is_valid(), "성공") | ||
# return Response( | ||
# data={"detail": ["You can use this ID"]}, status=status.HTTP_200_OK | ||
# ) | ||
else: | ||
detail = dict() | ||
detail["detail"] = serializer.errors["username"] | ||
print(serializer.is_valid(), "실패") | ||
# return Response(data=detail, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
@api_view(["POST"]) | ||
def user_follow(request): | ||
username = request.data["username"] | ||
follow_user = get_object_or_404(get_user_model(), username=username, is_active=True) | ||
request.user.following_set.add(follow_user) | ||
follow_user.follower_set.add(request.user) | ||
return Response(status.HTTP_204.NO_CONTENT) | ||
|
||
|
||
@api_view(["POST"]) | ||
def user_unfollow(request): | ||
username = request.data["username"] | ||
follow_user = get_object_or_404(get_user_model(), username=username, is_active=True) | ||
request.user.following_set.remove(follow_user) | ||
follow_user.follower_set.remove(request.user) | ||
return Response(status.HTTP_204.NO_CONTENT) | ||
|
||
|
||
class TokenObtainPairResponseSerializer(serializers.Serializer): | ||
access = serializers.CharField() | ||
refresh = serializers.CharField() | ||
|
||
def create(self, validated_data): | ||
raise NotImplementedError() | ||
|
||
def update(self, instance, validated_data): | ||
raise NotImplementedError() | ||
|
||
|
||
class DecoratedTokenObtainPairView(TokenObtainPairView): | ||
@swagger_auto_schema( | ||
responses={ | ||
status.HTTP_200_OK: TokenObtainPairResponseSerializer, | ||
} | ||
) | ||
def post(self, request, *args, **kwargs): | ||
return super().post(request, *args, **kwargs) | ||
|
||
|
||
class TokenRefreshResponseSerializer(serializers.Serializer): | ||
access = serializers.CharField() | ||
|
||
def create(self, validated_data): | ||
raise NotImplementedError() | ||
|
||
def update(self, instance, validated_data): | ||
raise NotImplementedError() | ||
|
||
|
||
class DecoratedTokenRefreshView(TokenRefreshView): | ||
@swagger_auto_schema( | ||
responses={ | ||
status.HTTP_200_OK: TokenRefreshResponseSerializer, | ||
} | ||
) | ||
def post(self, request, *args, **kwargs): | ||
return super().post(request, *args, **kwargs) | ||
|
||
|
||
class TokenVerifyResponseSerializer(serializers.Serializer): | ||
def create(self, validated_data): | ||
raise NotImplementedError() | ||
|
||
def update(self, instance, validated_data): | ||
raise NotImplementedError() | ||
|
||
|
||
class DecoratedTokenVerifyView(TokenVerifyView): | ||
@swagger_auto_schema( | ||
responses={ | ||
status.HTTP_200_OK: TokenVerifyResponseSerializer, | ||
} | ||
) | ||
def post(self, request, *args, **kwargs): | ||
return super().post(request, *args, **kwargs) | ||
|
||
|
||
class TokenBlacklistResponseSerializer(serializers.Serializer): | ||
def create(self, validated_data): | ||
raise NotImplementedError() | ||
|
||
def update(self, instance, validated_data): | ||
raise NotImplementedError() | ||
|
||
|
||
class DecoratedTokenBlacklistView(TokenBlacklistView): | ||
@swagger_auto_schema( | ||
responses={ | ||
status.HTTP_200_OK: TokenBlacklistResponseSerializer, | ||
} | ||
) | ||
def post(self, request, *args, **kwargs): | ||
return super().post(request, *args, **kwargs) |
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 |
---|---|---|
@@ -1 +1 @@ | ||
from .common import * | ||
from .common import * |
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 |
---|---|---|
@@ -1,22 +1,58 @@ | ||
# 수정 사항 | ||
# search_fields = ["title"] | ||
# | ||
# def short_content(self, post): | ||
# return post.content[:15] | ||
from django.contrib import admin | ||
|
||
from .models import Post | ||
from .models import Post, PostComment, Comment, Tag | ||
|
||
|
||
@admin.register(Post) | ||
class PostAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
"id", | ||
"title", | ||
"short_content", | ||
"content", | ||
"created_at", | ||
"updated_at", | ||
"category", | ||
"author", | ||
) | ||
list_filter = ("created_at", "updated_at", "category", "author") | ||
date_hierarchy = "created_at" | ||
|
||
|
||
@admin.register(PostComment) | ||
class PostCommentAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
"id", | ||
"title", | ||
"content", | ||
"created_at", | ||
"updated_at", | ||
"answer", | ||
"author", | ||
) | ||
list_filter = ("created_at", "updated_at", "answer", "author") | ||
date_hierarchy = "created_at" | ||
|
||
|
||
@admin.register(Comment) | ||
class CommentAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
"id", | ||
"author", | ||
"post", | ||
"content", | ||
"created_at", | ||
"updated_at", | ||
) | ||
list_display_links = ("title", "short_content", "author") | ||
list_filter = ("author", "created_at", "updated_at") | ||
search_fields = ["title"] | ||
list_filter = ("author", "post", "created_at", "updated_at") | ||
date_hierarchy = "created_at" | ||
|
||
def short_content(self, post): | ||
return post.content[:15] | ||
|
||
@admin.register(Tag) | ||
class TagAdmin(admin.ModelAdmin): | ||
list_display = ("id", "name") | ||
search_fields = ("name",) |
Oops, something went wrong.