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

from pycs.database.Database import Database


class GetResults(View):
    """
    returns a list of a files results
    """
    # pylint: disable=arguments-differ
    methods = ['GET']

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

    def dispatch_request(self, file_id: int):
        # get file from database
        file = self.db.file(file_id)
        if file is None:
            return abort(404)

        # get results
        results = file.results()

        # return result
        return jsonify(results)
