Author: Adam <git@apiote.tk>
show watched parts of film collections
libamuse/film.go | 22 ++++++++++++++++++++++ templates/film.html | 3 ++- tmdb/film.go | 1 +
diff --git a/libamuse/film.go b/libamuse/film.go index 95f17c8919374c76cd314c9e10c738d4964b68bc..e9f1629cb18468afb1797b4efafd6447061bbf17 100644 --- a/libamuse/film.go +++ b/libamuse/film.go @@ -35,6 +35,27 @@ } return gott.Tuple(args), err } +func getCollectionWatches(args ...interface{}) (interface{}, error) { + result := args[1].(*Result) + film := result.result.(*tmdb.Film) + + if result.user.IsEmpty() { + return gott.Tuple(args), nil + } + + for i, part := range film.Collection.Parts { + experiences, err := db.GetItemExperiences(result.user.Username, strconv.FormatInt(int64(part.Id), 10), datastructure.ItemTypeFilm) + if err != nil { + return gott.Tuple(args), err + } + if len(experiences) > 0 { + part.IsWatched = true + film.Collection.Parts[i] = part + } + } + return gott.Tuple(args), nil +} + func renderFilm(args ...interface{}) interface{} { result := args[1].(*Result) film := result.result.(*tmdb.Film) @@ -65,6 +86,7 @@ Bind(parseLanguage). Bind(verifyToken). Bind(getFilm). Bind(getCollection). + Bind(getCollectionWatches). Bind(getBasedOn). Bind(getFilmExperiences). Bind(isOnWantList). diff --git a/templates/film.html b/templates/film.html index 357b8b004c994d2457dfc01342b2381549250574..4c80b2dc6b51490f8d5e6379ab8e618a6e5b1035 100644 --- a/templates/film.html +++ b/templates/film.html @@ -148,8 +148,9 @@