setting up ez export api

This commit is contained in:
lza_menace
2022-01-02 23:50:34 -08:00
parent 9754a3f9ce
commit 80d74af7a3
2 changed files with 18 additions and 1 deletions
+5
View File
@@ -3,6 +3,7 @@ from datetime import datetime
from flask import url_for
from flask_login import login_user
from sqlalchemy import inspect
from suchwowx.factory import db
from suchwowx import config
@@ -107,6 +108,10 @@ class Meme(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
user = db.relationship('User', back_populates='memes')
def as_dict(self):
return {c.key: getattr(self, c.key)
for c in inspect(self).mapper.column_attrs}
def __repr__(self):
return str(f'meme-{self.id}')
+13 -1
View File
@@ -5,12 +5,24 @@ from flask_login import current_user
from suchwowx.factory import db
from suchwowx.helpers import verify_signature
from suchwowx.models import User
from suchwowx.models import User, Meme
bp = Blueprint('api', 'api', url_prefix='/api/v1')
@bp.route('/memes')
def memes():
"""
List all the approved memes on the server to allow remote syncing.
"""
all_memes = dict()
memes = Meme.query.filter(Meme.approved == True).all()
for meme in memes:
all_memes[meme.id] = meme.as_dict()
return jsonify(all_memes)
@bp.route('/user_exists')
def user_exists():
"""