from flask import abort, jsonify
from flask.views import View

from pycs.database.Database import Database


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

    def __init__(self, db: Database):
        # pylint: disable=invalid-name
        self.db = db

    def dispatch_request(self, identifier):
        # find project
        project = self.db.project(identifier)
        if project is None:
            abort(404)

        # get labels
        labels = project.labels()

        # return labels
        return jsonify(labels)
