diff --git a/Pipfile b/Pipfile index 743d66a..ad6f9ff 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] flask-restplus = "*" dataclasses = "*" +flask-cors = "*" [dev-packages] pytest = "*" diff --git a/thankful_server/main.py b/thankful_server/main.py index 07b23cf..da6d115 100644 --- a/thankful_server/main.py +++ b/thankful_server/main.py @@ -2,17 +2,20 @@ from flask import Flask from flask_restplus import Api +from flask_cors import CORS from . import __version__ -from .rest import creators, thanks +from .rest import creators, thanks, missing app = Flask(__name__) +CORS(app) api = Api(app, version=__version__, title='Thankful Server API', description='An API for getting information about creators') # TODO: Do some fancy stuff with blueprints to handle versions api.add_namespace(creators.api) api.add_namespace(thanks.api) +api.add_namespace(missing.api) def main() -> None: diff --git a/thankful_server/rest/missing.py b/thankful_server/rest/missing.py new file mode 100644 index 0000000..b80cfaf --- /dev/null +++ b/thankful_server/rest/missing.py @@ -0,0 +1,34 @@ +from sys import version_info + +from flask import request +from flask_restplus import Namespace, Resource, fields + +# Backport +if (3, 5) <= version_info < (3, 7): + from dataclasses import dataclass +elif version_info < (3, 6): + raise Exception("Incompatible Python version") + +api = Namespace('missing', description='For telling us about creators without' + + 'addresses') + +missingModel = api.model('Missing', { + #'creator_url': fields.Url(required=True, description='The creator url,' + + # ' at least for this website'), + 'missing_info': fields.Raw(required=True, description='JSON') + #'donation_amount': fields.Float(required=False, description='The amount' + + # ' that the user wanted to donate'), +}) + + +@api.route('/') +class MissingResource(Resource): + '''beep boop documentation''' + + @api.doc('thank_creator') + @api.param('missing_info', help="The json") + def post(self): + info = request.args["missing_info"] + # TODO: Do fancier logging here + print(info) + return 'thx' \ No newline at end of file