|
|
|
@ -9,7 +9,7 @@ import flask_restful.reqparse
|
|
|
|
|
import sqlalchemy
|
|
|
|
|
import sqlalchemy.engine
|
|
|
|
|
|
|
|
|
|
from db import db, Video, Comment, Association
|
|
|
|
|
from db import db, Video, Comment, Association, Emote
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = flask.Flask(__name__)
|
|
|
|
@ -74,6 +74,11 @@ comment_fields = {
|
|
|
|
|
'updated_at': flask_restful.fields.DateTime(dt_format='iso8601', attribute='comment.updated_at'),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emote_fields = {
|
|
|
|
|
'id': flask_restful.fields.Integer(),
|
|
|
|
|
'code': flask_restful.fields.String(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filter_parser = flask_restful.reqparse.RequestParser()
|
|
|
|
|
filter_parser.add_argument('filter', type=str)
|
|
|
|
@ -169,10 +174,30 @@ class CommentsResource(flask_restful.Resource):
|
|
|
|
|
return assocs, 200, {'X-Total-Count': count}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmoteResource(flask_restful.Resource):
|
|
|
|
|
@flask_restful.marshal_with(emote_fields)
|
|
|
|
|
def get(self, id):
|
|
|
|
|
q = db.session.query(Emote).filter(Emote.id == id)
|
|
|
|
|
emote = q.first()
|
|
|
|
|
if not emote:
|
|
|
|
|
flask_restful.abort(404, message='Emote {0} does not exist'.format(id))
|
|
|
|
|
return emote, 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmotesResource(flask_restful.Resource):
|
|
|
|
|
@flask_restful.marshal_with(emote_fields)
|
|
|
|
|
def get(self):
|
|
|
|
|
q = db.session.query(Emote)
|
|
|
|
|
emotes = q.all()
|
|
|
|
|
return emotes, 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(VideoResource, '/videos/<int:id>')
|
|
|
|
|
api.add_resource(VideosResource, '/videos')
|
|
|
|
|
api.add_resource(CommentResource, '/videos/<int:video_id>/comments/<string:comment_id>')
|
|
|
|
|
api.add_resource(CommentsResource, '/videos/<int:id>/comments')
|
|
|
|
|
api.add_resource(EmoteResource, '/emotes/<int:id>')
|
|
|
|
|
api.add_resource(EmotesResource, '/emotes')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|