added get_posts endpoint

This commit is contained in:
2024-12-30 09:35:57 +01:00
parent 76b6c6cb79
commit 9f093ce1ee
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
from __future__ import annotations
import json
from flask_restful import Resource
from flask import current_app as app, jsonify, request
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from modules.Archive.database import Database
class Archive_GetPosts(Resource):
def get(self):
db : Database = app.databases["Archive"]
count = request.args["count"] if "count" in request.args else 10
last_id = request.args["last_id"] if "last_id" in request.args else -1
param = []
if "undecided" in request.args:
param.append(0)
if "approved" in request.args:
param.append(1)
if "denied" in request.args:
param.append(2)
if param == []:
param = [0,1,2]
result = db.get_posts(count, param, last_id)
if result is None:
response = app.response_class(status=400)
else:
response = app.response_class(
response=json.dumps(result, ensure_ascii=False, indent=1),
status=200,
mimetype='application/json'
)
response.headers.add("Access-Control-Allow-Origin", "*")
return response