mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-17 08:50:49 +08:00
feat: filter media in watchlist
This commit is contained in:
4
db/db.go
4
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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String> originCountry;
|
||||
final bool? inWatchlist;
|
||||
|
||||
factory SearchResult.fromJson(Map<String, dynamic> 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<String>.from(json["origin_country"]!.map((x) => x)),
|
||||
|
||||
@@ -36,8 +36,9 @@ class _SearchPageState extends ConsumerState<SearchPage> {
|
||||
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: <Widget>[
|
||||
@@ -75,7 +76,14 @@ class _SearchPageState extends ConsumerState<SearchPage> {
|
||||
))
|
||||
: 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(""),
|
||||
|
||||
Reference in New Issue
Block a user