diff --git a/back/api.py b/back/api.py index ca359da..815043b 100644 --- a/back/api.py +++ b/back/api.py @@ -87,7 +87,7 @@ def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form()], be temp_ancmt = models.Announcement(user_id=current_user.id, name=name, category=category, best_by=bestBy, address=address, longtitude=longtitude, latitude=latitude, description=description, metro=metro, - trashId=trashId, booked_by=0) + trashId=trashId, src=uploaded_name, booked_by=0) db.add(temp_ancmt) # добавляем в бд db.commit() # сохраняем изменения db.refresh(temp_ancmt) # обновляем состояние объекта @@ -211,8 +211,10 @@ def poems_to_front(db: Annotated[Session, Depends(utils.get_db)]): # db: Annotat @app.get("/api/trashbox", response_model=List[schemas.TrashboxResponse]) def get_trashboxes(data: schemas.TrashboxRequest = Depends()):#крутая функция для работы с api # json, передаваемый стороннему API - head = {'Authorization': 'Bearer {}'.format(service.my_token)} - # Данные пользователя (местоположение, количество мусорок, которое пользователь хочет видеть) + BASE_URL= "https://geointelect2.gate.petersburg.ru" + my_token="eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhU1RaZm42bHpTdURYcUttRkg1SzN5UDFhT0FxUkhTNm9OendMUExaTXhFIn0.eyJleHAiOjE3ODYyMjUzMzMsImlhdCI6MTY5MTUzMDkzMywianRpIjoiYjU0MmU3MTQtYzJkMS00NTY2LWJkY2MtYmQ5NzA0ODY1ZjgzIiwiaXNzIjoiaHR0cHM6Ly9rYy5wZXRlcnNidXJnLnJ1L3JlYWxtcy9lZ3MtYXBpIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6ImJjYjQ2NzljLTU3ZGItNDU5ZC1iNWUxLWRlOGI4Yzg5MTMwMyIsInR5cCI6IkJlYXJlciIsImF6cCI6ImFkbWluLXJlc3QtY2xpZW50Iiwic2Vzc2lvbl9zdGF0ZSI6IjJhOTgwMzUyLTY1M2QtNGZlZC1iMDI1LWQ1N2U0NDRjZmM3NiIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiLyoiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImRlZmF1bHQtcm9sZXMtZWdzLWFwaSIsIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6ImVtYWlsIHByb2ZpbGUiLCJzaWQiOiIyYTk4MDM1Mi02NTNkLTRmZWQtYjAyNS1kNTdlNDQ0Y2ZjNzYiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsIm5hbWUiOiLQktC70LDQtNC40LzQuNGAINCv0LrQvtCy0LvQtdCyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiZTBmYzc2OGRhOTA4MjNiODgwZGQzOGVhMDJjMmQ5NTciLCJnaXZlbl9uYW1lIjoi0JLQu9Cw0LTQuNC80LjRgCIsImZhbWlseV9uYW1lIjoi0K_QutC-0LLQu9C10LIifQ.FTKiC1hpWcOkmSW9QZpC-RY7Ko50jw1mDMfXIWYxlQ-zehLm2CLmOnHvYoOoI39k2OzeCIAB9ZdRrrGZc6G9Z1eFELUjNGEqKxSC1Phj9ATemKgbOKEttk-OGc-rFr9VPA8_SnfvLts6wTI2YK33YBIxCF5nCbnr4Qj3LeEQ0d6Hy8PO4ATrBF5EOeuAZRprvIEjXe_f8N9ONKckCPB-xFB4P2pZlVXGoCNoewGEcY3zXH4khezN6zcVr6tpc6G8dBv9EqT_v92IDSg-aXQk6ysA0cO0-6x5w1-_qU0iHGIAPsLNV9IKBoFbjc0JH6cWabldPRH12NP1trvYfqKDGQ" + head = {'Authorization': 'Bearer {}'.format(my_token)} + my_data={ 'x' : f"{data.Lng}", 'y' : f"{data.Lat}", @@ -223,26 +225,25 @@ def get_trashboxes(data: schemas.TrashboxRequest = Depends()):#крутая фу list_of_category = [] # лист по которому будет отбираться uniq_trashboxes match data.Category: case "PORRIDGE": - list_of_category=["Опасные отходы", "Иное"] + list_of_category = ["Опасные отходы", "Иное"] case "Конспекты": - list_of_category=["Бумага"] + list_of_category = ["Бумага"] case "Молочные продукты": - list_of_category=["Стекло","Тетра Пак", "Иное"] + list_of_category = ["Стекло", "Тетра Пак", "Иное"] case "Хлебобулочные изделия": - list_of_category=["Пластик", "Иное"] + list_of_category = ["Пластик", "Иное"] case "Моющие средства": - list_of_category=["Пластик", "Опасные отходы", "Иное"] + list_of_category = ["Пластик", "Опасные отходы", "Иное"] case "Одежда": - list_of_category=["Одежда"] + list_of_category = ["Одежда"] case "Фрукты и овощи": - list_of_category=["Иное"] + list_of_category = ["Иное"] case "Всякая всячина": - list_of_category=["Металл", "Бумага", "Стекло","Иное", "Тетра Пак", "Батарейки", "Крышечки", "Шины", "Опасные отходы", "Лампочки", "Пластик"] - - - response = requests.post(f"{service.BASE_URL}/nearest_recycling/get", headers=head, data=my_data) + list_of_category = ["Металл", "Бумага", "Стекло", "Иное", "Тетра Пак", "Батарейки", "Крышечки", "Шины", + "Опасные отходы", "Лампочки", "Пластик"] + + response = requests.post(f"{BASE_URL}/nearest_recycling/get", headers=head, data=my_data) infos = response.json() - trashboxes = [] for trashbox in infos["results"]: temp_dict = {} diff --git a/back/service.py b/back/service.py index 61f7201..5b3e572 100644 --- a/back/service.py +++ b/back/service.py @@ -7,7 +7,7 @@ import datetime # Переменные для получения данных о мусорках с внешнего API # url API -BASE_URL='https://geointelect2.gate.petersburg.ru/nearest_recycling/get'#адрес сайта и мой токин +BASE_URL='https://geointelect2.gate.petersburg.ru'#адрес сайта и мой токин # токен для получения данных my_token='eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhU1RaZm42bHpTdURYcUttRkg1SzN5UDFhT0FxUkhTNm9OendMUExaTXhFIn0.eyJleHAiOjE3ODM3ODk4NjgsImlhdCI6MTY4OTA5NTQ2OCwianRpIjo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csavuMjXmqfQQ9SmPwDw-3toO64NuZVv6qVqoUlPPj57sLx4bLtVbB4pdqgyJYcrDHg7sgwz4d1Z3tAeUfSpum9s5ZfELequfpLoZMXn6CaYZhePaoK-CxeU3KPBPTPOVPKZZ19s7QY10VdkxLULknqf9opdvLs4j8NMimtwoIiHNBFlgQz10Cr7bhDKWugfvSRsICouniIiBJo76wrj5T92s-ztf1FShJuqnQcKE_QLd2A' diff --git a/front/src/components/StoriesPreview.tsx b/front/src/components/StoriesPreview.tsx index 4bd6cf6..1c73357 100644 --- a/front/src/components/StoriesPreview.tsx +++ b/front/src/components/StoriesPreview.tsx @@ -1,5 +1,5 @@ import { Link } from 'react-router-dom' -import { CSSProperties, useEffect, useMemo, useRef, useState } from 'react' +import { useEffect, useLayoutEffect, useRef, useState } from 'react' import { Button } from 'react-bootstrap' import { UserCategory, composeUserCategoriesFilters, userCategoriesInfos } from '../assets/userCategories' @@ -9,64 +9,37 @@ import { URLEncodeFilters } from '../utils/filters' import rightAngleIcon from '../assets/rightAngle.svg' +import styles from '../styles/StoriesPreview.module.css' + type StoriesPreviewProps = { announcements: Announcement[], category: UserCategory, } -const styles = { - container: { - transform: 'translateX(0)', - } as CSSProperties, - ul: { - display: 'flex', - gap: 10, - listStyleType: 'none', - overflow: 'scroll', - paddingLeft: 0, - scrollBehavior: 'smooth', - } as CSSProperties, - link: { - textDecoration: 'none', - color: 'var(--bs-body-color)', - maxWidth: 'calc(25vh * 9 / 16)', - display: 'inline-block', - } as CSSProperties, - image: { - height: '25vh', - objectFit: 'contain', - borderRadius: 12, - marginBottom: 5, - maxWidth: 'inherit', - } as CSSProperties, - title: { - overflow: 'hidden', - textOverflow: 'ellipsis', - marginBottom: 5, - } as CSSProperties, - scrollButton: { - position: 'fixed', - right: 0, - top: 0, - zIndex: 100, - background: 'linear-gradient(to right, rgba(17, 17, 17, 0) 0%, rgba(17, 17, 17, 255) 100%)', - display: 'block', - height: '100%', - width: '10%', - border: 'none', - cursor: 'default', - borderRadius: 0, - } as CSSProperties, - leftScrollButton: { - left: 0, - transform: 'scaleX(-1)', - } as CSSProperties, - rightScrollButton: { - right: 0, - } as CSSProperties, -} +const StoriesPreview = ({ announcements, category }: StoriesPreviewProps) => ( + announcements.map((ann, i) => ( +
{ann.name}
+{userCategoriesInfos[category](ann)}
+ +