wip: content: move watched entry to inside content object

instead of separating both, should be easier to work with this way and enable it to work for search results without complex mapping etc to find related watched entries
This commit is contained in:
IRHM
2025-02-18 22:08:59 +00:00
parent 18c0882650
commit 0ea1fea88a
2 changed files with 8 additions and 7 deletions
+2 -2
View File
@@ -234,7 +234,7 @@ func (b *BaseRouter) addContentRoutes() {
return
}
userId := c.MustGet("userId").(uint)
resp := DataWithWatched[TMDBShowDetails]{}
resp := TMDBShowDetailsWithWatched{}
// 1. Get details
content, err := tvDetails(
b.db,
@@ -248,7 +248,7 @@ func (b *BaseRouter) addContentRoutes() {
c.JSON(http.StatusBadRequest, ErrorResponse{Error: err.Error()})
return
}
resp.Data = &content
resp.TMDBShowDetails = &content
// 2. append watched list entry if exists
if watchedEntry, err := getWatchedItemByTmdbId(b.db, userId, uint(tmdbId), SHOW); err != nil {
if err != gorm.ErrRecordNotFound {
+6 -5
View File
@@ -75,9 +75,7 @@ type WatchedRemoveResponse struct {
NewActivity Activity `json:"newActivity"`
}
// Generic for returning data of (T)ype along with any
// related watched entry data.
type DataWithWatched[T any] struct {
type WatchedAddedToContent struct {
// The related watched entry.
Watched *Watched `json:"watched,omitempty"`
// If we failed to get the watched entry,
@@ -85,8 +83,11 @@ type DataWithWatched[T any] struct {
// notify the user of why there is possibly
// missing watched list data.
FailedToGetWatched bool `json:"failedToGetWatched,omitempty"`
// The data going along with response.
Data *T `json:"data,omitempty"`
}
type TMDBShowDetailsWithWatched struct {
WatchedAddedToContent
*TMDBShowDetails
}
// Get entire watched list