Skip to content

Commit

Permalink
apps moved to core folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bugraahmetcaglar committed Apr 18, 2024
1 parent ea7456f commit fb9de7c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
Empty file added core/__init__.py
Empty file.
12 changes: 8 additions & 4 deletions core/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.db import models

from skillforge.models import BaseModel, BaseCategory, BasePost, BaseComment
from skillforge.models import BaseTag, BaseCategory, BasePost, BaseComment
from skillforge.utils import NullableCharField
from ckeditor.fields import RichTextField

Expand All @@ -11,22 +11,26 @@ class BlogCategory(BaseCategory):
pass


class BlogTag(BaseTag):
pass


class Blog(BasePost):
# media = models.FileField(null=True, blank=True, storage=ArticleMediaStorage(), default="no-image-available.png")
category = models.ForeignKey(
BlogCategory, related_name="blog_categories", on_delete=models.SET_NULL, blank=False, null=True
)
introduction = models.NullableCharField(max_length=1000)
introduction = NullableCharField(max_length=1000)
is_private = models.BooleanField(default=False)

def __str__(self):
return self.title


class ArticleComment(BaseComment):
class BlogComment(BaseComment):
article = models.ForeignKey(
Blog, related_name="blog_comments", on_delete=models.DO_NOTHING, null=False, blank=False
)

class Meta:
ordering = ["-created_at"]
ordering = ["-created_at"]
35 changes: 14 additions & 21 deletions core/user/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

from skillforge.generics import StandardResultsSetPagination
from rest_framework import status
from rest_framework.permissions import (AllowAny, IsAuthenticated)
from rest_framework.generics import (
CreateAPIView, RetrieveAPIView, ListAPIView
)
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.generics import CreateAPIView, RetrieveAPIView, ListAPIView
from rest_framework_jwt.settings import api_settings

from skillforge.constants import BaseResponse
from core.user.models import User
from core.user.v1.serializers import (
UserLoginSerializer, UserRegisterSerializer,
UserLogoutSerializer, UserListSerializer
UserLoginSerializer,
UserRegisterSerializer,
UserLogoutSerializer,
UserListSerializer,
)
from skillforge.utils import BaseResponse


JWT_PAYLOAD_HANDLER = api_settings.JWT_PAYLOAD_HANDLER
JWT_ENCODE_HANDLER = api_settings.JWT_ENCODE_HANDLER
Expand All @@ -28,7 +29,7 @@ class UserLoginAPIView(CreateAPIView):
def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
return BaseResponse(data=serializer.data, status_code=status.HTTP_200_OK).success_with_data()
return BaseResponse(data=serializer.data, status_code=status.HTTP_200_OK).success_data()


class UserRegistrationAPIView(CreateAPIView):
Expand All @@ -40,17 +41,14 @@ def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
return BaseResponse(
message="User created successfully.",
status_code=status.HTTP_201_CREATED
).success()
return BaseResponse(message="User created successfully.", status_code=status.HTTP_201_CREATED).success()


class UserDetailAPIView(RetrieveAPIView):
permission_classes = [AllowAny]
serializer_class = UserListSerializer
queryset = User.objects.all()
lookup_field = 'id'
lookup_field = "id"


class UserLogoutAPIView(CreateAPIView):
Expand All @@ -62,21 +60,16 @@ def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
return BaseResponse(
message="Successfully logged out.", status_code=status.HTTP_200_OK
).success()
return BaseResponse(message="Successfully logged out.", status_code=status.HTTP_200_OK).success()


class UserListAPIView(ListAPIView):
permission_classes = [AllowAny]
serializer_class = UserListSerializer
pagination_class = StandardResultsSetPagination
queryset = User.objects.filter(is_active=True)
lookup_field = 'id'
lookup_field = "id"

def list(self, request, *args, **kwargs):
serializer_data = self.serializer_class(self.queryset, many=True).data
return BaseResponse(
data=serializer_data,
status_code=status.HTTP_200_OK
).success_with_data()
return BaseResponse(data=serializer_data, status_code=status.HTTP_200_OK).success_data()
6 changes: 3 additions & 3 deletions core/user/v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
from rest_framework_jwt.settings import api_settings

from skillforge.constants import BaseResponse
from skillforge.utils import BaseResponse
from core.user.models import User
from core.user.v1.serializers import (
UserLoginSerializer, UserRegisterSerializer,
Expand All @@ -28,7 +28,7 @@ class UserLoginAPIView(CreateAPIView):
def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
return BaseResponse(data=serializer.data, status_code=status.HTTP_200_OK).success_with_data()
return BaseResponse(data=serializer.data, status_code=status.HTTP_200_OK).success_data()


class UserRegistrationAPIView(CreateAPIView):
Expand Down Expand Up @@ -79,4 +79,4 @@ def list(self, request, *args, **kwargs):
return BaseResponse(
data=serializer_data,
status_code=status.HTTP_200_OK
).success_with_data()
).success_data()

0 comments on commit fb9de7c

Please sign in to comment.