blob: 123836429f11a0010fdba8c6e78ea93579a9200c [file] [log] [blame]
from flask import Blueprint, render_template
from .functions.Fpost import Fpost;
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config import Config
from flask import jsonify,request
main = Blueprint('main', __name__)
@main.route('/spostlist',methods=['POST','GET'])
def postlist():
data=request.get_json()
engine=create_engine(Config.SQLURL)
SessionLocal = sessionmaker(bind=engine)
session = SessionLocal()
f=Fpost(session)
checres=f.checkid(data['userid'])
if(not checres):
return jsonify()
res=f.getlist()
respons=[]
for datai in res:
respons.append({
'id': datai[0],
'title': datai[1],
'status': datai[2]
})
return jsonify(respons)
@main.route('/sgetpost',methods=['POST','GET'])
def post():
data=request.get_json()
engine=create_engine(Config.SQLURL)
SessionLocal = sessionmaker(bind=engine)
session = SessionLocal()
f=Fpost(session)
checres=f.checkid(data['userid'])
if(not checres):
return jsonify()
res=f.getpost(data['postid'])
return jsonify(res.to_dict() if res else {})