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 }
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 }
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 }
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 }
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
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()
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()
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