from fastapi import FastAPI from fastapi.responses import HTMLResponse from fastapi import Query from pymongo.asynchronous.database import AsyncDatabase from extra.MessageDTO import MessageDTO from typing import List, Annotated from pymongo import DESCENDING class WebExtension: MESSAGE_PORTNUM = 1 app: FastAPI dbStore: AsyncDatabase def __init__(self, core): self.core = core self.app = core.app self.dbStore = core.dbStore @self.app.get(f"{self.core.context}/messages") @self.core.authManager.authRequest() async def listOfMessages(limit: int = Query(10), offset: int = Query(0)): collection = self.dbStore['packet'] c = collection.find({ "to": int(self.core.PUB_CH), "portnum":self.MESSAGE_PORTNUM }).sort("ts", DESCENDING).skip(offset).limit(limit) l = await c.to_list() return [MessageDTO(msg) for msg in l]