diff --git a/pkg/data/episodic.go b/pkg/data/episodic.go index 74abfcd..9649ae3 100644 --- a/pkg/data/episodic.go +++ b/pkg/data/episodic.go @@ -19,6 +19,7 @@ const ( sqlGetEpisodesByEpisodic = `SELECT * FROM episodic_episode WHERE episodic_episode.episodic_id = ?;` sqlInsertEpisode = `INSERT INTO episodic_episode (id, episodic_id, title, season_id, episode_number, date_added, date_updated, is_watched, date_watched, file_entry, integration_identifier, date_first_aired, overview) VALUES (@id, @episodic_id, @title, @season_id, @episode_number, @date_added, @date_updated, @is_watched, @date_watched, @file_entry, @integration_identifier, @date_first_aired, @overview);` sqlMarkEpisodeWatched = `UPDATE episodic_episode SET is_watched = ((is_watched - 1) * (-1)) WHERE id = ? AND episodic_id = ?;` + sqlMarkEpisodicSeasonWatched = `UPDATE episodic_episode SET is_watched = 1 WHERE season_id = ? AND episodic_id = ?;` sqlRemoveAllEpisodes = `DELETE FROM episodic_episode WHERE episodic_id = ?;` sqlRemoveEpisodic = `DELETE FROM episodic WHERE episodic.id = ?;` sqlUpdateEpisode = `UPDATE episodic_episode SET title = @title, season_id = @season_id, episode_number = @episode_number, date_updated = @date_updated, is_watched = @is_watched, date_watched = @date_watched, file_entry = @file_entry, integration_identifier = @integration_identifier, date_first_aired = @date_first_aired, overview = @overview WHERE id = @id;` @@ -226,6 +227,19 @@ func (d *Base) MarkEpisodeWatched(ctx context.Context, id, episodeID string) err ) } +func (d *Base) MarkEpisodicSeasonWatched(ctx context.Context, id, season string) error { + conn := d.conn.Get(ctx) + defer d.conn.Put(conn) + + return sqlitex.Execute( + conn, + sqlMarkEpisodicSeasonWatched, + &sqlitex.ExecOptions{ + Args: []any{season, id}, + }, + ) +} + func (d *Base) StoreEpisode(ctx context.Context, ep *types.Episode) error { conn := d.conn.Get(ctx) defer d.conn.Put(conn) diff --git a/pkg/server/handlers.go b/pkg/server/handlers.go index 379c092..14a9409 100644 --- a/pkg/server/handlers.go +++ b/pkg/server/handlers.go @@ -34,6 +34,7 @@ func routeAPI(g *gin.Engine) { api.GET("episodic/refresh/:id", getEpisodicRefresh) api.POST("episodic/integration/:id", postEpisodicIntegration) api.GET("episodic/:id/watched/:episode", getEpisodicWatched) + api.GET("episodic/:id/season/watched/:season", getEpisodicSeasonWatched) api.GET("search/episodic/:id/:title", getSearchEpisodic) } @@ -60,6 +61,20 @@ func getEpisodicWatched(c *gin.Context) { }) } +func getEpisodicSeasonWatched(c *gin.Context) { + wrap(c, func(ctx *gin.Context) (interface{}, []string, int) { + db := ctx.MustGet("db").(*data.Base) + id := ctx.Param("id") + season := ctx.Param("season") + + err := db.MarkEpisodicSeasonWatched(ctx, id, season) + if err != nil { + return bad(err) + } + return good(gin.H{"mark_watched": true}) + }) +} + func getFilesystems(c *gin.Context) { wrap(c, func(ctx *gin.Context) (interface{}, []string, int) { db := ctx.MustGet("db").(*data.Base) diff --git a/src/api.js b/src/api.js index 35d4e6d..9ac8539 100644 --- a/src/api.js +++ b/src/api.js @@ -51,6 +51,10 @@ export default { return this.perform('get', `/api/v1/episodic/${id}/watched/${episode_id}`); }, + markSeasonWatched(id, season_id) { + return this.perform('get', `/api/v1/episodic/${id}/season/watched/${season_id}`); + }, + refreshEpisodic(id) { return this.perform('get', `/api/v1/episodic/refresh/${id}`); }, diff --git a/src/components/PageEpisodic.vue b/src/components/PageEpisodic.vue index 37c56b8..e62dfd0 100644 --- a/src/components/PageEpisodic.vue +++ b/src/components/PageEpisodic.vue @@ -34,6 +34,15 @@ + + + + { + this.loadEpisodic(); + }); + }, + ...mapActions(['getEpisodic']), }, }; diff --git a/src/store/index.js b/src/store/index.js index f9c1c89..dc57c5e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -120,6 +120,10 @@ export default createStore({ return apiClient.markEpisodeWatched(id, episode_id); }, + markSeasonWatched(_, {id, season_id}) { + return apiClient.markSeasonWatched(id, season_id); + }, + refreshEpisodic(_, {id}) { return apiClient.refreshEpisodic(id); },