mirror of
https://github.com/magnum-opus-tender-hack/backend.git
synced 2024-11-22 01:06:35 +03:00
complete hints
This commit is contained in:
parent
7b3b3391d6
commit
491629f47d
|
@ -7,6 +7,7 @@ from search.api.serializers import HintRequestSerializer
|
||||||
|
|
||||||
from search.api.serializers import SearchSerializer, ResponseSerializer, HintResponseSerializer
|
from search.api.serializers import SearchSerializer, ResponseSerializer, HintResponseSerializer
|
||||||
from search.services.search import process_string
|
from search.services.search import process_string
|
||||||
|
from search.services.hints import get_hints
|
||||||
|
|
||||||
user_response = openapi.Response("search results", ResponseSerializer)
|
user_response = openapi.Response("search results", ResponseSerializer)
|
||||||
hint_response = openapi.Response("hints", HintResponseSerializer)
|
hint_response = openapi.Response("hints", HintResponseSerializer)
|
||||||
|
@ -28,7 +29,7 @@ class HintApi(APIView):
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
{
|
||||||
'type': 'category',
|
'type': get_hints(serializer.data['content']),
|
||||||
'value': serializer.data['content']
|
'value': serializer.data['content']
|
||||||
},
|
},
|
||||||
status=status.HTTP_200_OK
|
status=status.HTTP_200_OK
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
# Generated by Django 4.0.8 on 2022-10-21 20:39
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('search', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Characteristic',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=250, unique=True, verbose_name='Имя')),
|
||||||
|
('value', models.CharField(max_length=250, verbose_name='Значение')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'Characteristic',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UnitCharacteristic',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=250, verbose_name='Имя')),
|
||||||
|
('value', models.CharField(max_length=250, verbose_name='Значение')),
|
||||||
|
('unit', models.CharField(max_length=250, verbose_name='Размерность')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'UnitCharacteristic',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='product',
|
||||||
|
name='characteristic',
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ProductUnitCharacteristic',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('characteristic', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', to='search.unitcharacteristic')),
|
||||||
|
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='unit_characteristics', to='search.product')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'ProductUnitCharacteristic',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ProductCharacteristic',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('characteristic', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', to='search.characteristic')),
|
||||||
|
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='characteristics', to='search.product')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'ProductCharacteristic',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,8 +1,12 @@
|
||||||
from search.models import Product, Category
|
from search.models import Product, Category, Characteristic
|
||||||
|
|
||||||
|
|
||||||
def get_hints(content: str) -> str:
|
def get_hints(content: str) -> str:
|
||||||
category = 'Unknown'
|
category = 'Unknown'
|
||||||
if content in list(map(lambda product: product.name, Product.objects.all())):
|
if content in list(map(lambda product: product.name, Product.objects.all())):
|
||||||
category = 'Name'
|
category = 'Name'
|
||||||
|
elif content in list(map(lambda category: category.name, Category.objects.all())):
|
||||||
|
category = 'Category'
|
||||||
|
elif content in list(map(lambda char: char.value, Characteristic.objects.all())):
|
||||||
|
category = Characteristic.objects.get(value=content).name
|
||||||
return category
|
return category
|
||||||
|
|
Loading…
Reference in New Issue
Block a user