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

repo = Repository()


def get():
    return [e.to_serializable_dict() for e in repo.get_time_slices()]


def get_by_name(layername):
    res = repo.get_time_slices_by_name(layername)
    # print(len(res))
    
    if res is not None and len(res) != 0:
        return [e.to_serializable_dict() for e in res]
    else:
        return Response(status=404)

def get_by_name2(name):
    res = repo.get_time_slices_by_name(name)
    # print(len(res))
    
    if res is not None and len(res) != 0:
        return [e.to_serializable_dict() for e in res]
    else:
        return Response(status=404)