tvqueue.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package libamuse
  2. import (
  3. "notabug.org/apiote/amuse/accounts"
  4. "notabug.org/apiote/amuse/datastructure"
  5. "notabug.org/apiote/amuse/db"
  6. "notabug.org/apiote/gott"
  7. )
  8. func getTvQueue(args ...interface{}) (interface{}, error) {
  9. request := args[0].(*RequestData)
  10. result := args[1].(*Result)
  11. page := args[2].(int)
  12. tvQueue, err := db.GetTvQueue(result.user.Username, request.id, page)
  13. result.result = &tvQueue
  14. return gott.Tuple(args), err
  15. }
  16. func renderTvQueue(args ...interface{}) interface{} {
  17. request := args[0].(*RequestData)
  18. result := args[1].(*Result)
  19. page := args[2].(int)
  20. tvQueue := result.result.(*datastructure.TvQueue)
  21. tvQueue.Page = page
  22. tvQueue.Query = request.id
  23. result.page = result.renderer.RenderTvQueue(*tvQueue, result.languages)
  24. return gott.Tuple(args)
  25. }
  26. func ShowTvQueue(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(getTvQueue).
  38. Bind(getGenres).
  39. Bind(createRenderer).
  40. Map(renderTvQueue).
  41. Finish()
  42. if err != nil {
  43. return "", err
  44. } else {
  45. return r.(gott.Tuple)[1].(*Result).page, nil
  46. }
  47. }