from flask import jsonify
from flask.views import View

from pycs.database.Collection import Collection
from pycs.database.Project import Project


class ListProjectCollections(View):
    """
    return a list of collections for a given project
    """
    # pylint: disable=arguments-differ
    methods = ['GET']


    def dispatch_request(self, project_id: int):
        # find project
        project = Project.get_or_404(project_id)

        # get collection list
        collections = Collection.update_autoselect(project.collections)

        # return files
        return jsonify(collections.all())
