import logging
from flask import jsonify, make_response
from flask_restful import Resource, reqparse

from app.models import User, BucketList
from app.utils.auth.authorize import login_required

logger = logging.getLogger(__name__)


class BucketListsResource(Resource):
    """ this class gets all the bucketlists in the database."""
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.parser.add_argument("name",
                                 type=str,
                                 required=True,
                                 help="bucketlist name is required")

        self.parser.add_argument("description",
                                 type=str,
                                 required=True,
                                 help="bucketlist description is required")

    @login_required
    def get(self, user_id, response):
        return make_response(jsonify({
            "message": response[0]
        }), response[1])


class BucketListResource(Resource):
    """ this class gets a single bucketlist. """
    @login_required
    def get(self, id, user_id, response):
        if user_id is not None:
            user = User.query.filter_by(id=user_id)
            if user:
                logger.info("this is the user id %(user_id)")
            else:
                response = ("Please login to access your bucketlists", 401)

        return make_response(jsonify({
            "message": response[0]
        }), response[1])

@@ -93,17 +93,34 @@
 reqparse
+, fields, marshal
 %0A
-
 %0Afrom ap
@@ -152,16 +152,68 @@
 ketList%0A
+from app.utils.db import save_record, delete_record%0A
 from app
@@ -257,16 +257,16 @@
 quired%0A%0A
-
 logger =
@@ -295,16 +295,265 @@
 ame__)%0A%0A
+# Field marshal for bucketlist item%0Abucketlist_fields = %7B%22id%22: fields.Integer,%0A                     %22name%22: fields.String,%0A                     %22description%22: fields.String,%0A                     %22created_at%22: fields.DateTime%0A                     %7D%0A%0A
 %0Aclass B

Add marshal fields for bucketlist to format json output data