add/fix: small changes on docs and comment style
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from rest_framework.viewsets import GenericViewSet # type: ignore
|
||||
from rest_framework.generics import GenericAPIView # type: ignore
|
||||
from rest_framework.decorators import action # type: ignore
|
||||
from rest_framework import status # type: ignore
|
||||
from rest_framework.request import HttpRequest # type: ignore
|
||||
@@ -7,8 +7,7 @@ from rest_framework.permissions import ( # type: ignore
|
||||
IsAuthenticated
|
||||
)
|
||||
|
||||
from django_core.mixins import BaseViewSetMixin # type: ignore
|
||||
|
||||
from core.utils.views import BaseApiViewMixin
|
||||
from core.apps.companies.serializers import (
|
||||
RetrieveCompanySerializer,
|
||||
CreateCompanySerializer,
|
||||
@@ -21,50 +20,29 @@ from core.apps.companies.models import (
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
class MeCompanyView(BaseViewSetMixin, GenericViewSet):
|
||||
######################################################################
|
||||
# @api-view | POST, GET - me/companies
|
||||
######################################################################
|
||||
class MeCompanyApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
action_permission_classes = {}
|
||||
action_serializer_class = {
|
||||
"create": CreateCompanySerializer,
|
||||
"list": RetrieveCompanySerializer,
|
||||
method_permission_classes = {}
|
||||
method_serializer_class = {
|
||||
"post": CreateCompanySerializer,
|
||||
"get": RetrieveCompanySerializer,
|
||||
}
|
||||
|
||||
def list(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
|
||||
companies = CompanyModel.objects.filter(
|
||||
accounts__user=request.user
|
||||
)
|
||||
|
||||
return Response(
|
||||
RetrieveCompanySerializer(instance=companies, many=True).data,
|
||||
status=status.HTTP_200_OK
|
||||
)
|
||||
def get(self, request: HttpRequest, *args: object, **kwargs: object) -> Response:
|
||||
companies = CompanyModel.objects.filter(accounts__user=request.user)
|
||||
ser = RetrieveCompanySerializer(instance=companies, many=True)
|
||||
return Response(ser.data, status.HTTP_200_OK)
|
||||
|
||||
def create(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
|
||||
def create(self, request: HttpRequest, *args: object, **kwargs: object) -> Response:
|
||||
with transaction.atomic():
|
||||
serializer = CreateCompanySerializer(data=request.data) # type: ignore
|
||||
serializer.is_valid(raise_exception=True)
|
||||
company = serializer.save() # type: ignore
|
||||
|
||||
account = CompanyAccountModel(
|
||||
company=company,
|
||||
user=request.user
|
||||
)
|
||||
account = CompanyAccountModel(company=company, user=request.user)
|
||||
account.save()
|
||||
|
||||
return Response(
|
||||
data=serializer.data,
|
||||
status=status.HTTP_201_CREATED
|
||||
)
|
||||
return Response(serializer.data, status.HTTP_201_CREATED)
|
||||
Reference in New Issue
Block a user