experiences.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. "time"
  8. )
  9. func getExperiences(args ...interface{}) (interface{}, error) {
  10. request := args[0].(*RequestData)
  11. result := args[1].(*Result)
  12. page := args[2].(int)
  13. experiences, err := db.GetUserExperiences(result.user.Username, request.id, page)
  14. result.result = experiences
  15. return gott.Tuple(args), err
  16. }
  17. func parseExperienceDates(args ...interface{}) interface{} {
  18. result := args[1].(*Result)
  19. experiences := result.result.(datastructure.Experiences)
  20. location, _ := time.LoadLocation(result.user.Timezone)
  21. for i, experience := range experiences.List {
  22. experience.Datetime = experience.Datetime.In(location)
  23. experiences.List[i] = experience
  24. }
  25. result.result = experiences
  26. return gott.Tuple(args)
  27. }
  28. func renderExperiences(args ...interface{}) interface{} {
  29. request := args[0].(*RequestData)
  30. result := args[1].(*Result)
  31. page := args[2].(int)
  32. experiences := result.result.(datastructure.Experiences)
  33. experiences.Page = page
  34. experiences.Query = request.id
  35. result.page = result.renderer.RenderExperiences(experiences, result.languages)
  36. return gott.Tuple(args)
  37. }
  38. func ShowExperiences(username string, auth accounts.Authentication, languages, mimetype, filter string, page int) (string, error) {
  39. auth.Necessary = true
  40. if page <= 0 {
  41. page = 1
  42. }
  43. request := &RequestData{id: filter, language: languages, mimetype: mimetype, auth: auth, username: username}
  44. r, err := gott.
  45. NewResult(gott.Tuple{request, &Result{}, page}).
  46. Bind(parseLanguage).
  47. Bind(verifyToken).
  48. Bind(verifyUser).
  49. Bind(getExperiences).
  50. Map(parseExperienceDates).
  51. Bind(createRenderer).
  52. Map(renderExperiences).
  53. Finish()
  54. if err != nil {
  55. return "", err
  56. } else {
  57. return r.(gott.Tuple)[1].(*Result).page, nil
  58. }
  59. }