channel Signup { out accounts(accDB:Map, signup(aid:Str)) = insert(accDB, aid, {"favorites": nil, "books": nil}) } channel CreateBook(aid:Str) { out accounts.{aid}.books(bookList:List, createBook(title:Str)) = append(bookList, {"title": title, "todos": nil, "favorited": nil}) } channel DeleteAccount { out accounts(accDB:Map, deleteAccount(aid:Str)) = if(contains(accDB, aid), delete(accDB, aid), accDB) } channel ChangeAccountName { out accounts(accDB:Map, changeAccountId(aid:Str, newAid:Str)) = if(aid == newAid, accDB, delete(insert(accDB, newAid, lookup(accDB, aid)), aid)) } channel ChangeBookName(aid:Str, bid:Int) { out accounts.{aid}.books.{bid}.title(title:Str, changeBookName(newTitle)) = newTitle } channel DeleteBook(aid:Str) { out accounts.{aid}.books(bookList:List, deleteBook(bid:Int)) = if(bid < length(bookList), remove(bookList, bid), bookList) } channel CreateToDo(aid:Str, bid:Int) { out accounts.{aid}.books.{bid}.todos(toDoDB:Map, createtodo(year:Str, month:Str, day:Str, title:Str)) = if( contains(toDoDB,year), if( contains(lookup(toDoDB,year),month), if( contains(lookup(lookup(toDoDB,year),month),day), insert(toDoDB,year,insert(lookup(toDoDB,year),month,insert(lookup(lookup(toDoDB,year),month),day,append(lookup(lookup(lookup(toDoDB,year),month),day),{"title":title,"check":false})))), insert(toDoDB,year,insert(lookup(toDoDB,year),month,insert(lookup(lookup(toDoDB,year),month),day,append(nil,{"title":title,"check":false})))) ), insert(toDoDB,year,insert(lookup(toDoDB,year),month,insert(nil,day,append(nil,{"title":title,"check":false})))) ), insert(toDoDB,year,insert(nil,month,insert(nil,day,append(nil,{"title":title,"check":false})))) ) } channel ChangeToDoName(aid:Str, bid:Int, year:Str, month:Str, day:Str, tid:Int) { out accounts.{aid}.books.{bid}.todos.{year}.{month}.{day}.{tid}.title(title:Str, changeToDoName(newTitle)) = newTitle } channel ChangeCheck(aid:Str, bid:Int, year:Str, month:Str, day:Str, tid:Int) { out accounts.{aid}.books.{bid}.todos.{year}.{month}.{day}.{tid}.check(check:Bool, changeCheck(newCheck)) = newCheck } channel DeleteToDo(aid:Str, bid:Int) { out accounts.{aid}.books.{bid}.todos(toDoDB:Map, deleteToDo(year:Str, month:Str, day:Str, tid:Int)) = insert(toDoDB, year, insert(lookup(toDoDB, year), month, insert(lookup(lookup(toDoDB, year), month), day, remove(lookup(lookup(lookup(toDoDB, year), month), day), tid)))) } channel AddFavorited(aid:Str, bid:Int) { out accounts.{aid}.books.{bid}.favorited(faList:List, addFavorited(o_aid:Str)) = if(aid==o_aid, faList, if(contains(faList, o_aid), remove(faList, indexOf(faList, o_aid)), append(faList, o_aid))) out accounts.{o_aid}.favorites(aDB:Map, addFavorited(o_aid:Str)) = if(aid==o_aid, aDB, if(contains(aDB, aid), if(contains(lookup(aDB, aid), bid), insert(aDB, aid, remove(lookup(aDB, aid), indexOf(lookup(aDB, aid), bid))), insert(aDB, aid, append(lookup(aDB, aid), bid))), insert(aDB, aid, append(nil, bid)))) }