setting up ez export api

main
lza_menace 3 years ago
parent 9754a3f9ce
commit 80d74af7a3

@ -3,6 +3,7 @@ from datetime import datetime
from flask import url_for from flask import url_for
from flask_login import login_user from flask_login import login_user
from sqlalchemy import inspect
from suchwowx.factory import db from suchwowx.factory import db
from suchwowx import config from suchwowx import config
@ -107,6 +108,10 @@ class Meme(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('users.id')) user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
user = db.relationship('User', back_populates='memes') 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): def __repr__(self):
return str(f'meme-{self.id}') return str(f'meme-{self.id}')

@ -5,12 +5,24 @@ from flask_login import current_user
from suchwowx.factory import db from suchwowx.factory import db
from suchwowx.helpers import verify_signature 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 = 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') @bp.route('/user_exists')
def user_exists(): def user_exists():
""" """

Loading…
Cancel
Save