enter image description here
@statistic_router.post('/{statistic_id}/event/{event_id}', name="add event")
async def add_event(statistic_id : str, event_id : str, statistic_service=statistics_service, me=Depends(get_me)):
if me.role not in ['manager', 'admin']:
raise HTTPException(403, 'forbidden')
return await statistic_service.add_event_in_statistic(statistic_id=statistic_id, event_id=event_id)
async def add_event_in_statistic(self, statistic_id, event_id):
event = await self.session.get(StatisticEvents, event_id)
statistic = await self.session.get(self.model, statistic_id, options=[selectinload(Statistic.statistic_events)])
if not event:
raise HTTPException(404, "event not found")
if not statistic:
raise HTTPException(404, "statistic not found")
model = StatisticEventsUsers(statistics_id=statistic_id, statistics_events_id=event_id)
if event.is_many == False:
model.updated_at = datetime.now() # Обновляем поле updated_at
await self.session.commit()
await self.session.refresh(statistic)
else:
self.session.add(model)
await self.session.commit()
await self.session.refresh(statistic)
return statistic
I double-checked the variable name, put a slash between them, and changed the query path in various ways. Nothing helped, for some reason the second variable is passed as {event_id} and not its value itself. p.s. I swapped event_id and statistic_id, and then the problems with statistic_id began. Guys, please help me, i really dont know what me do
New contributor
Timplay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.