diff --git a/db/db.go b/db/db.go index d6e76be..6369aa3 100644 --- a/db/db.go +++ b/db/db.go @@ -476,3 +476,7 @@ func (c *Client) UpdateEpisodeFile(mediaID int, seasonNum, episodeNum int, file func (c *Client) SetEpisodeStatus(id int, status episode.Status) error { return c.ent.Episode.Update().Where(episode.ID(id)).SetStatus(status).Exec(context.TODO()) } + +func (c *Client) TmdbIdInWatchlist(tmdb_id int) bool { + return c.ent.Media.Query().Where(media.TmdbID(tmdb_id)).CountX(context.TODO()) > 0 +} \ No newline at end of file diff --git a/pkg/tmdb/tmdb.go b/pkg/tmdb/tmdb.go index 0ff06b9..2da9822 100644 --- a/pkg/tmdb/tmdb.go +++ b/pkg/tmdb/tmdb.go @@ -44,25 +44,25 @@ func (c *Client) SearchTvShow(query string, lang string) (*tmdb.SearchTVShows, e } type SearchResult struct { - Page int `json:"page"` - Results []*SearchResultItem `json:"results"` - TotalResults int64 `json:"total_results"` - TotalPages int64 `json:"total_pages"` - + Page int `json:"page"` + Results []*SearchResultItem `json:"results"` + TotalResults int64 `json:"total_results"` + TotalPages int64 `json:"total_pages"` } type SearchResultItem struct { - PosterPath string `json:"poster_path,omitempty"` + PosterPath string `json:"poster_path"` ID int64 `json:"id"` - Overview string `json:"overview,omitempty"` + Overview string `json:"overview"` MediaType string `json:"media_type"` - FirstAirDate string `json:"first_air_date,omitempty"` - OriginCountry []string `json:"origin_country,omitempty"` - GenreIDs []int64 `json:"genre_ids,omitempty"` - OriginalLanguage string `json:"original_language,omitempty"` - Name string `json:"name,omitempty"` - OriginalName string `json:"original_name,omitempty"` - Adult bool `json:"adult,omitempty"` + FirstAirDate string `json:"first_air_date"` + OriginCountry []string `json:"origin_country"` + GenreIDs []int64 `json:"genre_ids"` + OriginalLanguage string `json:"original_language"` + Name string `json:"name"` + OriginalName string `json:"original_name"` + Adult bool `json:"adult"` + InWatchlist bool `json:"in_watchlist"` } func (c *Client) SearchMedia(query string, lang string, page int) (*SearchResult, error) { @@ -76,25 +76,25 @@ func (c *Client) SearchMedia(query string, lang string, page int) (*SearchResult return nil, errors.Wrap(err, "query imdb") } - searchResult := &SearchResult{ - Page: res.Page, + searchResult := &SearchResult{ + Page: res.Page, TotalResults: res.TotalResults, - TotalPages: res.TotalPages, - } + TotalPages: res.TotalPages, + } for _, r := range res.Results { if r.MediaType != "tv" && r.MediaType != "movie" { continue } item := &SearchResultItem{ - PosterPath: r.PosterPath, - ID: r.ID, - Overview: r.Overview, - MediaType: r.MediaType, - OriginCountry: r.OriginCountry, + PosterPath: r.PosterPath, + ID: r.ID, + Overview: r.Overview, + MediaType: r.MediaType, + OriginCountry: r.OriginCountry, OriginalLanguage: r.OriginalLanguage, - GenreIDs: r.GenreIDs, - Adult: r.Adult, + GenreIDs: r.GenreIDs, + Adult: r.Adult, } if r.MediaType == "tv" { item.Name = r.Name @@ -106,7 +106,7 @@ func (c *Client) SearchMedia(query string, lang string, page int) (*SearchResult item.FirstAirDate = r.ReleaseDate } searchResult.Results = append(searchResult.Results, item) - + } return searchResult, nil } diff --git a/server/watchlist.go b/server/watchlist.go index f43dfea..9edf831 100644 --- a/server/watchlist.go +++ b/server/watchlist.go @@ -45,6 +45,11 @@ func (s *Server) SearchMedia(c *gin.Context) (interface{}, error) { if err != nil { return nil, errors.Wrap(err, "search tv") } + for i, res := range r.Results { + if s.db.TmdbIdInWatchlist(int(res.ID)) { + r.Results[i].InWatchlist = true + } + } return r, nil } diff --git a/ui/lib/providers/welcome_data.dart b/ui/lib/providers/welcome_data.dart index 18edc7b..f0d823b 100644 --- a/ui/lib/providers/welcome_data.dart +++ b/ui/lib/providers/welcome_data.dart @@ -197,6 +197,7 @@ class SearchResult { required this.voteAverage, required this.voteCount, required this.originCountry, + this.inWatchlist }); final String? backdropPath; @@ -214,6 +215,7 @@ class SearchResult { final double? voteAverage; final int? voteCount; final List originCountry; + final bool? inWatchlist; factory SearchResult.fromJson(Map json) { return SearchResult( @@ -233,6 +235,7 @@ class SearchResult { firstAirDate: DateTime.tryParse(json["first_air_date"] ?? ""), voteAverage: json["vote_average"], voteCount: json["vote_count"], + inWatchlist: json["in_watchlist"], originCountry: json["origin_country"] == null ? [] : List.from(json["origin_country"]!.map((x) => x)), diff --git a/ui/lib/search.dart b/ui/lib/search.dart index 828f3c4..7d6d615 100644 --- a/ui/lib/search.dart +++ b/ui/lib/search.dart @@ -36,8 +36,9 @@ class _SearchPageState extends ConsumerState { child: InkWell( //splashColor: Colors.blue.withAlpha(30), onTap: () { - //showDialog(context: context, builder: builder) - _showSubmitDialog(context, item); + if (item.inWatchlist != true) { + _showSubmitDialog(context, item); + } }, child: Row( children: [ @@ -75,7 +76,14 @@ class _SearchPageState extends ConsumerState { )) : const Chip( avatar: Icon(Icons.movie), - label: Text("电影")) + label: Text("电影")), + item.inWatchlist == true + ? const Chip( + label: Icon( + Icons.done, + color: Colors.green, + )) + : const Text("") ], ), const Text(""),