mirror of
https://github.com/jwinterm/tubbymemes.git
synced 2026-10-17 05:21:28 +02:00
setting up ez export api
This commit is contained in:
@@ -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
@@ -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():
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user