Skip to content

Commit

Permalink
Merge pull request #69 from cloudcloud/feature/mark-all-watched
Browse files Browse the repository at this point in the history
Adding a button to mark all episodes within a season as watched
  • Loading branch information
CerealBoy authored Sep 8, 2024
2 parents 084dcd6 + f72c117 commit 5f8f9d1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/data/episodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;`
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions pkg/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
},
Expand Down
24 changes: 24 additions & 0 deletions src/components/PageEpisodic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@

<v-col cols="12" v-if="meta.total_specials_count > 0">
<v-card title="Specials" shaped>
<template v-slot:append>
<v-btn
text="Mark all watched"
color="primary"
@click="allWatched(''+0)"
variant="outlined"
density="comfortable" />
</template>

<v-data-table-virtual
:headers="headers"
:items="item.episodes"
Expand All @@ -57,6 +66,15 @@

<v-col cols="12" v-for="idx in seasons">
<v-card :title="'Season '+idx" shaped>
<template v-slot:append>
<v-btn
text="Mark all watched"
color="primary"
@click="allWatched(''+idx)"
variant="outlined"
density="comfortable" />
</template>

<v-data-table-virtual
:headers="headers"
:items="item.episodes"
Expand Down Expand Up @@ -147,6 +165,12 @@ export default {
});
},
allWatched(season) {
this.$store.dispatch('markSeasonWatched', { id: this.id, season_id: season }).then((data) => {
this.loadEpisodic();
});
},
...mapActions(['getEpisodic']),
},
};
Expand Down
4 changes: 4 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down

0 comments on commit 5f8f9d1

Please sign in to comment.