diff --git a/app/routers/events.py b/app/routers/events.py index bd18654..585f115 100644 --- a/app/routers/events.py +++ b/app/routers/events.py @@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException, status, Response from fastapi.responses import JSONResponse from datetime import datetime from ..dependencies import users_token, permissions_checker, database -from ..models import events, users +from ..models import events, users, tags from pydantic import EmailStr from typing import Annotated, Union from bson import ObjectId @@ -330,6 +330,7 @@ async def update_events(authorize: Annotated[bool, Depends(permissions_checker.P detail="Body request is empty" ) event_repository = events.EventRepository(database=database.database) + tags_repository = tags.TagsRepository(database=database.database) event = event_repository.find_one_by({"name": {'$eq': eventSingle.name}}) if event is not None: @@ -347,6 +348,11 @@ async def update_events(authorize: Annotated[bool, Depends(permissions_checker.P event.longitude = eventSingle.longitude event.imgUrl = eventSingle.imgUrl event.tags = eventSingle.tags + for tag_name in eventSingle: + tag = tags_repository.find_one_by({"name": {'$eq': tag_name}}) + if tag is None: + tag = Tags(name=tag_name) + tags_repository.save(tag) event.status = 1 event.created_at = datetime.today() event_repository.save(event) @@ -363,7 +369,7 @@ async def update_events_id(item_id: str, authorize: Annotated[bool, Depends(perm detail="Body request is empty" ) event_repository = events.EventRepository(database=database.database) - + tags_repository = tags.TagsRepository(database=database) event = event_repository.find_one_by({"id": {'$eq': ObjectId(item_id)}}) if event is None: raise HTTPException( @@ -378,6 +384,11 @@ async def update_events_id(item_id: str, authorize: Annotated[bool, Depends(perm event.end_date = eventSingle.end_date event.organizers = eventSingle.organizers event.tags = eventSingle.tags + for tag_name in eventSingle: + tag = tags_repository.find_one_by({"name": {'$eq': tag_name}}) + if tag is None: + tag = Tags(name=tag_name) + tags_repository.save(tag) event.latitude = eventSingle.latitude event.longitude = eventSingle.longitude event.updated_at = datetime.today()