readlist.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package libamuse
  2. import (
  3. "notabug.org/apiote/amuse/accounts"
  4. "notabug.org/apiote/amuse/db"
  5. "notabug.org/apiote/amuse/datastructure"
  6. "notabug.org/apiote/gott"
  7. )
  8. func getReadlist(args ...interface{}) (interface{}, error) {
  9. request := args[0].(*RequestData)
  10. result := args[1].(*Result)
  11. page := args[2].(int)
  12. watchlist, err := db.GetReadlist(result.user.Username, request.id, page)
  13. result.result = &watchlist
  14. return gott.Tuple(args), err
  15. }
  16. func renderReadlist(args ...interface{}) interface{} {
  17. request := args[0].(*RequestData)
  18. result := args[1].(*Result)
  19. page := args[2].(int)
  20. readlist := result.result.(*datastructure.Readlist)
  21. readlist.Page = page
  22. readlist.Query = request.id
  23. result.page = result.renderer.RenderReadlist(*readlist, result.languages)
  24. return gott.Tuple(args)
  25. }
  26. func ShowReadlist(username string, auth accounts.Authentication, languages, mimetype, filter string, page int) (string, error) {
  27. auth.Necessary = true
  28. if page <= 0 {
  29. page = 1
  30. }
  31. request := &RequestData{id: filter, language: languages, mimetype: mimetype, auth: auth, username: username}
  32. r, err := gott.
  33. NewResult(gott.Tuple{request, &Result{}, page}).
  34. Bind(parseLanguage).
  35. Bind(verifyToken).
  36. Bind(verifyUser).
  37. Bind(getReadlist).
  38. Bind(createRenderer).
  39. Map(renderReadlist).
  40. Finish()
  41. if err != nil {
  42. return "", err
  43. } else {
  44. return r.(gott.Tuple)[1].(*Result).page, nil
  45. }
  46. }