Ejemplo n.º 1
0
def deleteTodoList(id):
  tl = TodoList.query.filter(TodoList.id==id).first()

  if tl:
    # add data
    db.session.delete(tl)
    db.session.commit()
    return wrapResponse(tl.toJson())
  else:
    return wrapResponse(f'TodoList with id: {id} not found!',\
      400,"NOT FOUND"), 400
Ejemplo n.º 2
0
def DeleteTodoItem(id):

  ti = TodoItem.query.filter(TodoItem.id==id).first()

  if ti:
    # add data
    db.session.delete(ti)
    db.session.commit()
    return wrapResponse(ti.toJson())
  else:
    return wrapResponse(f'TodoItem with id: {id} not found!',\
      400,"NOT FOUND"), 400
Ejemplo n.º 3
0
def updateTodoList(request):
  id = request.json['id']
  # find todolist
  tl = TodoList.query.filter(TodoList.id==id).first()

  if tl:
    data = request.json
    # add these to class
    for key in data:
      setattr(tl,key,data[key])
    # add data
    db.session.add(tl)
    db.session.commit()
    return wrapResponse(tl.toJson())
  else:
    return wrapResponse(f'TodoList with id: {id} not found!',400,"NOT FOUND"),\
      400
Ejemplo n.º 4
0
def getTodoItems(request,id):
  page=1
  per_page=10

  ti = TodoItem.query\
    .filter(TodoItem.list_id==id)\
    .paginate(page=page,per_page=per_page)

  items=[]
  for item in ti.items:
    items.append(item.toJson())

  return wrapResponse(items)
Ejemplo n.º 5
0
def addTodoList(request):
  # create new instance
  tl = TodoList()
  # get data from request
  data = request.json
  # add these to class
  for key in data:
    setattr(tl,key,data[key])
  # add data
  db.session.add(tl)
  db.session.commit()
  # return response
  return wrapResponse(tl.toJson())
Ejemplo n.º 6
0
def addTodoItem(request, lid):
   # create new instance
  ti = TodoItem()
  # add list id
  ti.list_id = lid
  # get data from request
  data = request.json
  # add these to class
  for key in data:
    setattr(ti,key,data[key])
  # add data
  db.session.add(ti)
  db.session.commit()
  # return response
  return wrapResponse(ti.toJson())
Ejemplo n.º 7
0
def getTodoLists(request):
  # select top 50 items
  page=1
  per_page=50
  paginated = TodoList.query\
      .paginate(page=page,per_page=per_page)

  data = {
    'page':page,
    'per_page':per_page,
    'pages': paginated.pages,
    'total': paginated.total
  }

  if paginated.total==0:
    data['found']=0
    data['items']=[]
  else:
    items=[]
    for item in paginated.items:
      items.append(item.toJson())
    data['items'] = items

  return wrapResponse(data)
Ejemplo n.º 8
0
def home():
    return wrapResponse({'message': "It works"})