from flask import request, Response
from db.repository import Repository
from db.entities import ClusterSet

repo = Repository()

def get():
    return [c.to_serializable_dict() for c in repo.get_clustersets()]

def get_names():
    return repo.get_clusterset_names()


def get_by_name2(name):
    res = repo.get_clusters_for_layer(name)
    if res is None or len(res) == 0:
        return Response(status=404)
    else:
        return [c.to_serializable_dict() for c in res]

def get_by_name(name):
    res = repo.get_clusterset(name)
    if res is not None:
        return res.to_serializable_dict() 
    else:
        return Response(status=404)