예제 #1
0
def deleteService(request):
    for service in DBSession.query(CSH_Services).order_by(CSH_Services.id):
        if service.name == request.GET['name']:
            DBSession.delete(service)
    return {
            'success': True
            }
예제 #2
0
def addFavorites(request):
    """
    ->
    {
        'rank'
        'service_id'
    }
    <-
    {
        'success': True
        'service_id': <>
        'rank': <>
    }
    """
    if (len(DBSession.query(Favorites).order_by(desc(Favorites.id)).all()) == 0):
        uid = 0
    else:
        uid = DBSession.query(Favorites).order_by(desc(Favorites.id)).first().id + 1
    new_fav = Favorites(
            id = uid,
            service_id = request.json_body['service_id'],
            rank = request.json_body['rank']
    )

    DBSession.add(new_fav)
    #DBSession.commit()
    return {
            'success': True,
            'id': new_fav.id,
            'service_id': new_fav.service_id,
            'rank': new_fav.rank
            }
예제 #3
0
def removeFavorites(request):
    """
    does it's own thing
    """
    for favorite in DBSession.query(Favorites).order_by(desc(Favorites.id)):
        if favorite.service_id == request.GET['service_id']:
            DBSession.delete(favorite)
    return{
            'success':True
            }
예제 #4
0
def addService(request):
    """
    ->
    {
        'name'
        'icon'
        'url'
    }
    <-
    {
        'success': True
        'id': <>
        'icon': <>
        'name': <>
        'url': <>
    }
    """
    if (len(DBSession.query(CSH_Services).order_by(desc(CSH_Services.id)).all()) == 0):
        service_id = 0
    else:
        service_id = DBSession.query(CSH_Services).order_by(desc(CSH_Services.id)).first().id + 1

    new_service = CSH_Services(
            id = service_id,
            icon = request.json_body['icon'],
            name = request.json_body['name'],
            url = request.json_body['url']

            )
    DBSession.add(new_service)
    return {
            'success': True,
            'id': new_service.id,
            'icon': new_service.icon,
            'name': new_service.name,
            'url': new_service.url
            }
예제 #5
0
def getOrderedFavorites(request):
    """
    <-
    {
        all favorites objects ordered by rank
        {
            'service_id': <>
            'rank': <>
        }
    }
    """
    arr = []
    for favorite in DBSession.query(Favorites).order_by(Favorites.rank):
        obj = {}
        obj['service_id'] = favorite.service_id
        obj['rank'] = favorite.rank
        arr.append(obj)
    return arr
예제 #6
0
def getServiceByID(request):
    """
    <-
    {
        'id': <>
        'icon': <>
        'name': <>
        'url': <>
    }
    """
    for service in DBSession.query(CSH_Services).order_by(CSH_Services.id):
        if service.id == int(request.GET['id']):
            return{
                    'id': service.id,
                    'icon': service.icon,
                    'name': service.name,
                    'url': service.url
                    }
    return HTTPForbidden()
예제 #7
0
def getFavoriteByRank(request):
    """
    ->
    {
        'rank'
    }
    <-
    {
        'service_id': <>
        'rank': <>
    }
    """
    for favorite in DBSession.query(Favorites).order_by(Favorites.rank):
        if favorite.rank == int(request.GET['rank']):
        #if favorite.rank is request.validated['favorite'].rank:
            return {'service_id': favorite.service_id,
                    'rank': favorite.rank
                   }
    return HTTPForbidden()
예제 #8
0
def getServices(request):
    """
    <-
    {
    all service objects
        {
            'id': <>
            'icon': <>
            'name': <>
            'url': <>
        }
    }
    """
    arr = []
    for csh_service in DBSession.query(CSH_Services).order_by(CSH_Services.id):
        service_wrapper = {}
        service_wrapper['id'] = csh_service.id
        service_wrapper['icon'] = csh_service.icon
        service_wrapper['name'] = csh_service.name
        service_wrapper['url'] = csh_service.url

        arr.append(service_wrapper)
    return arr