Merge pull request 'behruz' (#99) from behruz into main
Some checks failed
Deploy to Production / build-and-deploy (push) Failing after 1m0s

Reviewed-on: #99
This commit is contained in:
2026-04-24 12:25:44 +00:00
7 changed files with 235 additions and 22 deletions

View File

@@ -8,7 +8,6 @@ on:
env:
PROJECT_NAME: sifatbaho
permissions:
contents: write
@@ -95,7 +94,6 @@ jobs:
sed -i "s|image: .*/${{ env.PROJECT_NAME }}:.*|image: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ github.run_number }}|g" stack.yaml
sed -i 's/return HttpResponse("OK.*"/return HttpResponse("OK: #${{ github.sha }}"/' config/urls.py
- name: Commit and push updated version
run: |
git config user.name "github-actions[bot]"
@@ -127,7 +125,6 @@ jobs:
rm -rf "$DIR"
cd "$PROJECTS"
git clone "$REPO_URL" "${{ env.PROJECT_NAME }}"
echo "Clone qilindi"
fi
cd "$DIR"
@@ -135,25 +132,18 @@ jobs:
git fetch origin main
git reset --hard origin/main
cp .env.example .env
cat > .env << 'ENVEOF'
DB_HOST=postgres
DB_NAME=sifatbahodb
DB_PORT=5432
DB_USER=${{ secrets.DB_USER }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
REDIS_URL=redis://redis:6379
SECRET_KEY=${{ secrets.SECRET_KEY }}
DIDOX_TOKEN=${{ secrets.DIDOX_TOKEN }}
DEBUG=False
PORT=8085
update_env() {
local env_file=".env"
for kv in "$@"; do
local key="${kv%%=*}"
local value="${kv#*=}"
if grep -q "^$key=" "$env_file"; then
sed -i "s|^$key=.*|$key=$value|" "$env_file"
else
echo "$key=$value" >> "$env_file"
fi
done
}
ENVEOF
update_env \
"DB_HOST=postgres" \
"DB_NAME=sifatbahodb" \
"DB_PORT=5432" \
"DIDOX_TOKEN=${{ secrets.DIDOX_TOKEN }}"
export PORT=8085
docker stack deploy -c stack.yaml ${{ env.PROJECT_NAME }} --with-registry-auth

View File

@@ -0,0 +1,11 @@
from rest_framework import serializers
class AvgCostSerializer(serializers.Serializer):
brand = serializers.CharField(max_length=100)
condition = serializers.CharField(max_length=100)
model = serializers.CharField(max_length=100)
complication = serializers.CharField(max_length=100)
manufacture_date = serializers.DateField()
distance_covered = serializers.IntegerField()
color = serializers.CharField(max_length=100)

View File

@@ -0,0 +1,18 @@
from rest_framework import generics
from rest_framework.response import Response
from rest_framework import permissions
from core.apps.evaluation.serializers.auto.AvgCost import AvgCostSerializer
from core.services.grpc.auto import get_auto_avg_cost
class AvgCostView(generics.GenericAPIView):
serializer_class = AvgCostSerializer
permission_classes = [permissions.IsAuthenticated]
def post(self):
serializer = self.get_serializer(data=self.request.data)
if serializer.is_valid():
avg_cost = get_auto_avg_cost(serializer.validated_data)
return Response(avg_cost, status=200)
return Response(serializer.errors, status=400)

View File

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# NO CHECKED-IN PROTOBUF GENCODE
# source: auto.proto
# Protobuf Python Version: 6.31.1
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(
_runtime_version.Domain.PUBLIC,
6,
31,
1,
'',
'auto.proto'
)
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\nauto.proto\x12\x04\x61uto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xba\x01\n\x12\x41utoAvgCostRequest\x12\r\n\x05\x62rand\x18\x01 \x01(\t\x12\x11\n\tcondition\x18\x02 \x01(\t\x12\r\n\x05model\x18\x03 \x01(\t\x12\x14\n\x0c\x63omplication\x18\x04 \x01(\t\x12\x34\n\x10manufacture_date\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x18\n\x10\x64istance_covered\x18\x06 \x01(\t\x12\r\n\x05\x63olor\x18\x07 \x01(\t\"$\n\x13\x41\x64ImageListResponse\x12\r\n\x05image\x18\x01 \x01(\t\"t\n\x0e\x41\x64ListResponse\x12\n\n\x02id\x18\x01 \x01(\t\x12)\n\x06images\x18\x02 \x03(\x0b\x32\x19.auto.AdImageListResponse\x12\r\n\x05title\x18\x03 \x01(\t\x12\r\n\x05price\x18\x04 \x01(\t\x12\r\n\x05model\x18\x05 \x01(\t\"J\n\x13\x41utoAvgCostResponse\x12\x10\n\x08\x61vg_cost\x18\x01 \x01(\x01\x12!\n\x03\x61\x64s\x18\x02 \x03(\x0b\x32\x14.auto.AdListResponse2X\n\x12\x41utoAvgCostService\x12\x42\n\x0b\x41utoAvgCost\x12\x18.auto.AutoAvgCostRequest\x1a\x19.auto.AutoAvgCostResponseb\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'auto_pb2', _globals)
if not _descriptor._USE_C_DESCRIPTORS:
DESCRIPTOR._loaded_options = None
_globals['_AUTOAVGCOSTREQUEST']._serialized_start=54
_globals['_AUTOAVGCOSTREQUEST']._serialized_end=240
_globals['_ADIMAGELISTRESPONSE']._serialized_start=242
_globals['_ADIMAGELISTRESPONSE']._serialized_end=278
_globals['_ADLISTRESPONSE']._serialized_start=280
_globals['_ADLISTRESPONSE']._serialized_end=396
_globals['_AUTOAVGCOSTRESPONSE']._serialized_start=398
_globals['_AUTOAVGCOSTRESPONSE']._serialized_end=472
_globals['_AUTOAVGCOSTSERVICE']._serialized_start=474
_globals['_AUTOAVGCOSTSERVICE']._serialized_end=562
# @@protoc_insertion_point(module_scope)

View File

@@ -0,0 +1,97 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import warnings
from core.generated import auto_pb2 as auto__pb2
GRPC_GENERATED_VERSION = '1.80.0'
GRPC_VERSION = grpc.__version__
_version_not_supported = False
try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
except ImportError:
_version_not_supported = True
if _version_not_supported:
raise RuntimeError(
f'The grpc package installed is at version {GRPC_VERSION},'
+ ' but the generated code in auto_pb2_grpc.py depends on'
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
)
class AutoAvgCostServiceStub(object):
"""Missing associated documentation comment in .proto file."""
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.AutoAvgCost = channel.unary_unary(
'/auto.AutoAvgCostService/AutoAvgCost',
request_serializer=auto__pb2.AutoAvgCostRequest.SerializeToString,
response_deserializer=auto__pb2.AutoAvgCostResponse.FromString,
_registered_method=True)
class AutoAvgCostServiceServicer(object):
"""Missing associated documentation comment in .proto file."""
def AutoAvgCost(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_AutoAvgCostServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
'AutoAvgCost': grpc.unary_unary_rpc_method_handler(
servicer.AutoAvgCost,
request_deserializer=auto__pb2.AutoAvgCostRequest.FromString,
response_serializer=auto__pb2.AutoAvgCostResponse.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'auto.AutoAvgCostService', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
server.add_registered_method_handlers('auto.AutoAvgCostService', rpc_method_handlers)
# This class is part of an EXPERIMENTAL API.
class AutoAvgCostService(object):
"""Missing associated documentation comment in .proto file."""
@staticmethod
def AutoAvgCost(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/auto.AutoAvgCostService/AutoAvgCost',
auto__pb2.AutoAvgCostRequest.SerializeToString,
auto__pb2.AutoAvgCostResponse.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)

View File

@@ -0,0 +1,48 @@
import grpc
from google.protobuf.timestamp_pb2 import Timestamp
from datetime import datetime
from config.env import env
from core.generated import auto_pb2, auto_pb2_grpc
def get_auto_avg_cost(
brand,
condition,
model,
complication,
manufacture_date: datetime,
distance_covered,
color
):
# url = f"{env.str('RPC_IP')}:{env.str('RPC_PORT')}"
# channel = grpc.insecure_channel(url)
channel = grpc.insecure_channel("192.168.1.120:50051")
stub = auto_pb2_grpc.AutoAvgCostServiceStub(channel)
ts = Timestamp()
ts.FromDatetime(manufacture_date)
response = stub.AutoAvgCost(auto_pb2.AutoAvgCostRequest(
brand=brand,
condition=condition,
model=model,
complication=complication,
manufacture_date=ts,
distance_covered=distance_covered,
color=color,
))
return {
"avg_cost": response.avg_cost,
"ads": [
{
"id": ad.id,
"title": ad.title,
"price": ad.price,
"model": ad.model,
"images": [img.image for img in ad.images],
}
for ad in response.ads
]
}

View File

@@ -46,3 +46,7 @@ boto3
# !NOTE: on-websocket
# websockets
# channels-redis
grpcio>=1.62.0
grpcio-tools>=1.62.0
protobuf>=4.25.0