change api
This commit is contained in:
@@ -25,6 +25,11 @@ class ContractSideCreateSerializer(serializers.Serializer):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ContractSideListCreateSerializer(serializers.Serializer):
|
||||||
|
contract_side = ContractSideCreateSerializer(many=True)
|
||||||
|
|
||||||
|
|
||||||
class ContractSideListSerializer(serializers.ModelSerializer):
|
class ContractSideListSerializer(serializers.ModelSerializer):
|
||||||
contract_signature = serializers.SerializerMethodField(method_name='get_contract_signature')
|
contract_signature = serializers.SerializerMethodField(method_name='get_contract_signature')
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ urlpatterns = [
|
|||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
path('contract_side/', include([
|
path('contract_side/', include([
|
||||||
path('create/', contract_side_views.ConstartSideCreateApiView.as_view(), name='contract-side-create'),
|
path('create/', contract_side_views.ContractSideCreateApiView.as_view(), name='contract-side-create'),
|
||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
path('contract_signature/', include(
|
path('contract_signature/', include(
|
||||||
|
|||||||
@@ -1,20 +1,41 @@
|
|||||||
|
from django.db import transaction
|
||||||
|
|
||||||
from rest_framework import generics, status, parsers
|
from rest_framework import generics, status, parsers
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from core.apps.contracts.serializers import contract_side as contract_side_serializer
|
from core.apps.contracts.serializers import contract_side as contract_side_serializer
|
||||||
from core.apps.contracts.models.contract import ContractSide
|
from core.apps.contracts.models.contract import ContractSide, Contract
|
||||||
from core.apps.contracts.tasks.contract_side import create_contract_side
|
from core.apps.contracts.tasks.contract_side import create_contract_side
|
||||||
from core.apps.shared.utils.response import error_message, success_message
|
from core.apps.shared.utils.response import error_message, success_message
|
||||||
|
from core.apps.accounts.models import User
|
||||||
|
|
||||||
class ConstartSideCreateApiView(generics.GenericAPIView):
|
class ContractSideCreateApiView(generics.GenericAPIView):
|
||||||
serializer_class = contract_side_serializer.ContractSideCreateSerializer
|
serializer_class = contract_side_serializer.ContractSideListCreateSerializer
|
||||||
queryset = ContractSide.objects.all()
|
queryset = ContractSide.objects.all()
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
serializer = self.serializer_class(data=request.data)
|
serializer = self.serializer_class(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
# TODO: call celery task
|
try:
|
||||||
create_contract_side.delay(serializer.validated_data)
|
with transaction.atomic():
|
||||||
|
for side_data in serializer.validated_data['contract_side']:
|
||||||
|
user = User.objects.get(phone=side_data['phone'])
|
||||||
|
contract = Contract.objects.get(id=side_data['contract_id'])
|
||||||
|
ContractSide.objects.create(
|
||||||
|
full_name=side_data['full_name'],
|
||||||
|
indentification=side_data['indentification'],
|
||||||
|
position=side_data.get('position', ''),
|
||||||
|
has_indentification=side_data['has_indentification'],
|
||||||
|
user_role=side_data['user_role'],
|
||||||
|
# phone=side_data['phone'],
|
||||||
|
contract=contract,
|
||||||
|
user=user
|
||||||
|
)
|
||||||
return success_message("Contract side created", 201)
|
return success_message("Contract side created", 201)
|
||||||
return error_message(serializer.error_messages, 400)
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
transaction.set_rollback(True)
|
||||||
|
return error_message(str(e), 400)
|
||||||
|
|
||||||
|
return error_message(serializer.errors, 400)
|
||||||
@@ -27,7 +27,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./docker/Dockerfile.web
|
dockerfile: ./docker/Dockerfile.web
|
||||||
restart: always
|
# restart: always
|
||||||
command: sh resources/scripts/entrypoint.sh
|
command: sh resources/scripts/entrypoint.sh
|
||||||
environment:
|
environment:
|
||||||
- PYTHONPYCACHEPREFIX=/var/cache/pycache
|
- PYTHONPYCACHEPREFIX=/var/cache/pycache
|
||||||
@@ -54,13 +54,13 @@ services:
|
|||||||
- web
|
- web
|
||||||
networks:
|
networks:
|
||||||
- trustme
|
- trustme
|
||||||
restart: always
|
# restart: always
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:16
|
image: postgres:16
|
||||||
networks:
|
networks:
|
||||||
- trustme
|
- trustme
|
||||||
restart: always
|
# restart: always
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: ${DB_NAME}
|
POSTGRES_DB: ${DB_NAME}
|
||||||
POSTGRES_USER: ${DB_USER}
|
POSTGRES_USER: ${DB_USER}
|
||||||
@@ -76,7 +76,7 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
ports:
|
ports:
|
||||||
- 6379:6379
|
- 6380:6379
|
||||||
|
|
||||||
bot:
|
bot:
|
||||||
build:
|
build:
|
||||||
@@ -84,4 +84,4 @@ services:
|
|||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
volumes:
|
volumes:
|
||||||
- /home/behruz/bots/send-verification-code:/bot
|
- /home/behruz/bots/send-verification-code:/bot
|
||||||
restart: unless-stopped
|
# restart: unless-stopped
|
||||||
|
|||||||
@@ -1,25 +1,13 @@
|
|||||||
FROM python:3.12
|
FROM python:3.12-alpine
|
||||||
|
|
||||||
|
ENV PYTHONPYCACHEPREFIX=/dev/null
|
||||||
|
|
||||||
|
RUN apk update && apk add git gettext
|
||||||
|
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
|
|
||||||
RUN apt-get update && \
|
COPY requirements.txt /code/requirements.txt
|
||||||
apt-get install -y \
|
|
||||||
gdal-bin \
|
|
||||||
libgdal-dev \
|
|
||||||
python3-gdal \
|
|
||||||
libgeos-dev \
|
|
||||||
libproj-dev \
|
|
||||||
g++ \
|
|
||||||
make \
|
|
||||||
wkhtmltopdf && \
|
|
||||||
apt-get clean && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
|
||||||
|
|
||||||
RUN gdalinfo --version
|
CMD ["sh", "./entrypoint.sh"]
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
RUN --mount=type=cache,target=/root/.cache/pip python3 -m pip install -r requirements.txt
|
|
||||||
|
|
||||||
CMD ["sh", "./resources/scripts/entrypoint.sh"]
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
django==5.2
|
django==5.2
|
||||||
gunicorn
|
gunicorn
|
||||||
uvicorn
|
uvicorn
|
||||||
psycopg2
|
psycopg2-binary
|
||||||
django-environ==0.12.0
|
django-environ==0.12.0
|
||||||
pillow
|
pillow
|
||||||
djangorestframework_simplejwt==5.5.0
|
djangorestframework_simplejwt==5.5.0
|
||||||
|
|||||||
Reference in New Issue
Block a user