TRM-coding | 130f05c | 2025-06-15 16:05:28 +0800 | [diff] [blame^] | 1 | from flask import Blueprint, render_template |
| 2 | from .functions.Fpost import Fpost; |
| 3 | from sqlalchemy import create_engine |
| 4 | from sqlalchemy.orm import sessionmaker |
| 5 | from config import Config |
| 6 | from flask import jsonify,request |
| 7 | |
| 8 | main = Blueprint('main', __name__) |
| 9 | |
| 10 | |
| 11 | @main.route('/apostlist',methods=['POST','GET']) |
| 12 | def postlist(): |
| 13 | data=request.get_json() |
| 14 | engine=create_engine(Config.SQLURL) |
| 15 | SessionLocal = sessionmaker(bind=engine) |
| 16 | session = SessionLocal() |
| 17 | f=Fpost(session) |
| 18 | checres=f.checkid(data['userid']) |
| 19 | if(not checres): |
| 20 | return jsonify({'status': 'error', 'message': 'Unauthorized'}) |
| 21 | res=f.getlist() |
| 22 | respons=[] |
| 23 | for datai in res: |
| 24 | respons.append({ |
| 25 | 'id': datai[0], |
| 26 | 'title': datai[1], |
| 27 | 'status': datai[2] |
| 28 | }) |
| 29 | return jsonify(respons) |
| 30 | |
| 31 | @main.route('/agetpost',methods=['POST','GET']) |
| 32 | def post(): |
| 33 | data=request.get_json() |
| 34 | engine=create_engine(Config.SQLURL) |
| 35 | SessionLocal = sessionmaker(bind=engine) |
| 36 | session = SessionLocal() |
| 37 | f=Fpost(session) |
| 38 | checres=f.checkid(data['userid']) |
| 39 | if(not checres): |
| 40 | return jsonify({'status': 'error', 'message': 'Unauthorized'}) |
| 41 | res=f.getpost(data['postid']) |
| 42 | |
| 43 | return jsonify(res.to_dict() if res else {}) |
| 44 | |
| 45 | @main.route('/areview',methods=['POST','GET']) |
| 46 | def review(): |
| 47 | data=request.get_json() |
| 48 | engine=create_engine(Config.SQLURL) |
| 49 | SessionLocal = sessionmaker(bind=engine) |
| 50 | session = SessionLocal() |
| 51 | f=Fpost(session) |
| 52 | checres=f.checkid(data['userid']) |
| 53 | if(not checres): |
| 54 | return jsonify({'status': 'error', 'message': 'Unauthorized'}) |
| 55 | |
| 56 | res=f.review(data['postid'],data['status']) |
| 57 | if not res: |
| 58 | return jsonify({'status': 'error', 'message': 'Post not found'}) |
| 59 | |
| 60 | return jsonify({'status': 'success', 'message': 'Post reviewed successfully'}) |
| 61 | |
| 62 | |
| 63 | |