Skip to content

Commit fb50a4b

Browse files
authored
Merge pull request #1295 from bcc-code/feat/playlist-section-context
Feat/playlist section context
2 parents af62c82 + 409769c commit fb50a4b

17 files changed

Lines changed: 249 additions & 26 deletions

backend/common/items.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ type Section struct {
308308
Style string `json:"style"`
309309
Size string `json:"size"`
310310
CollectionID null.Int `json:"collectionId"`
311+
PlaylistID uuid.NullUUID `json:"playlistId"`
311312
MessageID null.Int `json:"messageId"`
312313
EmbedUrl null.String `json:"embedUrl"`
313314
EmbedAspectRatio null.Float `json:"embedAspectRatio"`

backend/common/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ type Progress struct {
129129
// EpisodeContext contains context for episode
130130
type EpisodeContext struct {
131131
CollectionID null.Int
132+
PlaylistID uuid.NullUUID
132133
Cursor null.String
133134
Shuffle null.Bool
134135
}

backend/graph/api/episodes.resolvers.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,27 +282,31 @@ func (r *episodeResolver) Watched(ctx context.Context, obj *model.Episode) (bool
282282

283283
// Context is the resolver for the context field.
284284
func (r *episodeResolver) Context(ctx context.Context, obj *model.Episode) (model.EpisodeContextUnion, error) {
285-
var collectionId *int
286-
287285
episodeContext, err := r.getEpisodeContext(ctx, obj.ID)
288286
if err != nil {
289287
return nil, err
290288
}
291289

292-
if episodeContext.CollectionID.Valid {
293-
intId := int(episodeContext.CollectionID.Int64)
294-
collectionId = &intId
290+
if episodeContext.PlaylistID.Valid {
291+
playlist, err := r.Loaders.PlaylistLoader.Get(ctx, episodeContext.PlaylistID.UUID)
292+
if err != nil {
293+
return nil, err
294+
}
295+
if playlist != nil {
296+
return model.PlaylistFrom(ctx, playlist), nil
297+
}
295298
}
296299

297-
if collectionId != nil {
298-
col, err := r.Loaders.CollectionLoader.Get(ctx, *collectionId)
300+
if episodeContext.CollectionID.Valid {
301+
collectionId := int(episodeContext.CollectionID.Int64)
302+
col, err := r.Loaders.CollectionLoader.Get(ctx, collectionId)
299303
if err != nil {
300304
return nil, err
301305
}
302306
ginCtx, _ := utils.GinCtx(ctx)
303307
languages := user.GetLanguagesFromCtx(ginCtx)
304308

305-
strID := strconv.Itoa(*collectionId)
309+
strID := strconv.Itoa(collectionId)
306310
return &model.ContextCollection{
307311
ID: strID,
308312
Slug: col.Slugs.GetValueOrNil(languages),

backend/graph/api/generated/generated.go

Lines changed: 85 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/graph/api/model/models_gen.go

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/graph/api/model/section.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ func SectionFrom(ctx context.Context, s *common.Section) Section {
2727
}
2828

2929
switch s.Type {
30-
case "item":
30+
case "item", "playlist":
31+
var playlistID *string
32+
if s.PlaylistID.Valid {
33+
pid := s.PlaylistID.UUID.String()
34+
playlistID = &pid
35+
}
3136
metadata := &ItemSectionMetadata{
3237
SecondaryTitles: s.Options.SecondaryTitles,
3338
MyList: s.Options.MyList,
3439
ContinueWatching: s.Options.ContinueWatching,
3540
CollectionID: strconv.Itoa(int(s.CollectionID.Int64)),
41+
PlaylistID: playlistID,
3642
UseContext: s.Options.UseContext,
3743
PrependLiveElement: s.Options.PrependLiveElement,
3844
Limit: &s.Options.Limit,

backend/graph/api/mutations.resolvers.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,20 @@ func (r *mutationRootResolver) SetEpisodeProgress(ctx context.Context, id string
137137

138138
if context != nil {
139139
var col null.Int
140-
if context.CollectionID != nil {
140+
var playlistID uuid.NullUUID
141+
if context.PlaylistID != nil {
142+
pID := utils.AsUuid(*context.PlaylistID)
143+
playlist, err := r.Loaders.PlaylistLoader.Get(ctx, pID)
144+
if err == nil && playlist != nil {
145+
col = playlist.CollectionID
146+
playlistID = uuid.NullUUID{UUID: pID, Valid: true}
147+
}
148+
}
149+
if !col.Valid && context.CollectionID != nil {
141150
col.SetValid(int64(utils.AsInt(*context.CollectionID)))
142151
}
143152
episodeProgress.Context.CollectionID = col
153+
episodeProgress.Context.PlaylistID = playlistID
144154
} else {
145155
episodeProgress.Context = common.EpisodeContext{}
146156
}

backend/graph/api/schema.resolvers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,21 @@ func (r *queryRootResolver) Episode(ctx context.Context, id string, context *mod
403403
ginCtx, _ := utils.GinCtx(ctx)
404404
if context != nil {
405405
var collectionID null.Int
406+
var playlistID uuid.NullUUID
406407
if context.PlaylistID != nil {
407-
playlist, err := r.Loaders.PlaylistLoader.Get(ctx, utils.AsUuid(*context.PlaylistID))
408+
pID := utils.AsUuid(*context.PlaylistID)
409+
playlist, err := r.Loaders.PlaylistLoader.Get(ctx, pID)
408410
if err == nil && playlist != nil {
409411
collectionID = playlist.CollectionID
412+
playlistID = uuid.NullUUID{UUID: pID, Valid: true}
410413
}
411414
}
412415
if !collectionID.Valid {
413416
collectionID = utils.AsNullInt(context.CollectionID)
414417
}
415418
ginCtx.Set(episodeContextKey, common.EpisodeContext{
416419
CollectionID: collectionID,
420+
PlaylistID: playlistID,
417421
Cursor: null.StringFromPtr(context.Cursor),
418422
Shuffle: null.BoolFromPtr(context.Shuffle),
419423
})

backend/graph/api/schema/episodes.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ enum EpisodeType {
33
standalone
44
}
55

6-
union EpisodeContextUnion = Season | ContextCollection
6+
union EpisodeContextUnion = Season | ContextCollection | Playlist
77

88
enum ShareRestriction {
99
registered

backend/graph/api/schema/sections.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ type ItemSectionMetadata {
33
myList: Boolean!
44
secondaryTitles: Boolean!
55
collectionId: ID!
6+
playlistId: ID
67
useContext: Boolean!
78
prependLiveElement: Boolean!
89
page: Page @goField(forceResolver: true)

0 commit comments

Comments
 (0)