You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
881 B
24 lines
881 B
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")
|
|
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]
|