diff --git a/ent/client.go b/ent/client.go index a4d8897e..e7534a9b 100644 --- a/ent/client.go +++ b/ent/client.go @@ -22,6 +22,7 @@ import ( "github.com/zibbp/ganymede/ent/live" "github.com/zibbp/ganymede/ent/livecategory" "github.com/zibbp/ganymede/ent/livetitleregex" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/mutedsegment" "github.com/zibbp/ganymede/ent/playback" "github.com/zibbp/ganymede/ent/playlist" @@ -48,6 +49,8 @@ type Client struct { LiveCategory *LiveCategoryClient // LiveTitleRegex is the client for interacting with the LiveTitleRegex builders. LiveTitleRegex *LiveTitleRegexClient + // MultistreamInfo is the client for interacting with the MultistreamInfo builders. + MultistreamInfo *MultistreamInfoClient // MutedSegment is the client for interacting with the MutedSegment builders. MutedSegment *MutedSegmentClient // Playback is the client for interacting with the Playback builders. @@ -79,6 +82,7 @@ func (c *Client) init() { c.Live = NewLiveClient(c.config) c.LiveCategory = NewLiveCategoryClient(c.config) c.LiveTitleRegex = NewLiveTitleRegexClient(c.config) + c.MultistreamInfo = NewMultistreamInfoClient(c.config) c.MutedSegment = NewMutedSegmentClient(c.config) c.Playback = NewPlaybackClient(c.config) c.Playlist = NewPlaylistClient(c.config) @@ -176,21 +180,22 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { cfg := c.config cfg.driver = tx return &Tx{ - ctx: ctx, - config: cfg, - BlockedVideos: NewBlockedVideosClient(cfg), - Channel: NewChannelClient(cfg), - Chapter: NewChapterClient(cfg), - Live: NewLiveClient(cfg), - LiveCategory: NewLiveCategoryClient(cfg), - LiveTitleRegex: NewLiveTitleRegexClient(cfg), - MutedSegment: NewMutedSegmentClient(cfg), - Playback: NewPlaybackClient(cfg), - Playlist: NewPlaylistClient(cfg), - Queue: NewQueueClient(cfg), - TwitchCategory: NewTwitchCategoryClient(cfg), - User: NewUserClient(cfg), - Vod: NewVodClient(cfg), + ctx: ctx, + config: cfg, + BlockedVideos: NewBlockedVideosClient(cfg), + Channel: NewChannelClient(cfg), + Chapter: NewChapterClient(cfg), + Live: NewLiveClient(cfg), + LiveCategory: NewLiveCategoryClient(cfg), + LiveTitleRegex: NewLiveTitleRegexClient(cfg), + MultistreamInfo: NewMultistreamInfoClient(cfg), + MutedSegment: NewMutedSegmentClient(cfg), + Playback: NewPlaybackClient(cfg), + Playlist: NewPlaylistClient(cfg), + Queue: NewQueueClient(cfg), + TwitchCategory: NewTwitchCategoryClient(cfg), + User: NewUserClient(cfg), + Vod: NewVodClient(cfg), }, nil } @@ -208,21 +213,22 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ - ctx: ctx, - config: cfg, - BlockedVideos: NewBlockedVideosClient(cfg), - Channel: NewChannelClient(cfg), - Chapter: NewChapterClient(cfg), - Live: NewLiveClient(cfg), - LiveCategory: NewLiveCategoryClient(cfg), - LiveTitleRegex: NewLiveTitleRegexClient(cfg), - MutedSegment: NewMutedSegmentClient(cfg), - Playback: NewPlaybackClient(cfg), - Playlist: NewPlaylistClient(cfg), - Queue: NewQueueClient(cfg), - TwitchCategory: NewTwitchCategoryClient(cfg), - User: NewUserClient(cfg), - Vod: NewVodClient(cfg), + ctx: ctx, + config: cfg, + BlockedVideos: NewBlockedVideosClient(cfg), + Channel: NewChannelClient(cfg), + Chapter: NewChapterClient(cfg), + Live: NewLiveClient(cfg), + LiveCategory: NewLiveCategoryClient(cfg), + LiveTitleRegex: NewLiveTitleRegexClient(cfg), + MultistreamInfo: NewMultistreamInfoClient(cfg), + MutedSegment: NewMutedSegmentClient(cfg), + Playback: NewPlaybackClient(cfg), + Playlist: NewPlaylistClient(cfg), + Queue: NewQueueClient(cfg), + TwitchCategory: NewTwitchCategoryClient(cfg), + User: NewUserClient(cfg), + Vod: NewVodClient(cfg), }, nil } @@ -253,8 +259,8 @@ func (c *Client) Close() error { func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ c.BlockedVideos, c.Channel, c.Chapter, c.Live, c.LiveCategory, c.LiveTitleRegex, - c.MutedSegment, c.Playback, c.Playlist, c.Queue, c.TwitchCategory, c.User, - c.Vod, + c.MultistreamInfo, c.MutedSegment, c.Playback, c.Playlist, c.Queue, + c.TwitchCategory, c.User, c.Vod, } { n.Use(hooks...) } @@ -265,8 +271,8 @@ func (c *Client) Use(hooks ...Hook) { func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.BlockedVideos, c.Channel, c.Chapter, c.Live, c.LiveCategory, c.LiveTitleRegex, - c.MutedSegment, c.Playback, c.Playlist, c.Queue, c.TwitchCategory, c.User, - c.Vod, + c.MultistreamInfo, c.MutedSegment, c.Playback, c.Playlist, c.Queue, + c.TwitchCategory, c.User, c.Vod, } { n.Intercept(interceptors...) } @@ -287,6 +293,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.LiveCategory.mutate(ctx, m) case *LiveTitleRegexMutation: return c.LiveTitleRegex.mutate(ctx, m) + case *MultistreamInfoMutation: + return c.MultistreamInfo.mutate(ctx, m) case *MutedSegmentMutation: return c.MutedSegment.mutate(ctx, m) case *PlaybackMutation: @@ -1232,6 +1240,171 @@ func (c *LiveTitleRegexClient) mutate(ctx context.Context, m *LiveTitleRegexMuta } } +// MultistreamInfoClient is a client for the MultistreamInfo schema. +type MultistreamInfoClient struct { + config +} + +// NewMultistreamInfoClient returns a client for the MultistreamInfo from the given config. +func NewMultistreamInfoClient(c config) *MultistreamInfoClient { + return &MultistreamInfoClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `multistreaminfo.Hooks(f(g(h())))`. +func (c *MultistreamInfoClient) Use(hooks ...Hook) { + c.hooks.MultistreamInfo = append(c.hooks.MultistreamInfo, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `multistreaminfo.Intercept(f(g(h())))`. +func (c *MultistreamInfoClient) Intercept(interceptors ...Interceptor) { + c.inters.MultistreamInfo = append(c.inters.MultistreamInfo, interceptors...) +} + +// Create returns a builder for creating a MultistreamInfo entity. +func (c *MultistreamInfoClient) Create() *MultistreamInfoCreate { + mutation := newMultistreamInfoMutation(c.config, OpCreate) + return &MultistreamInfoCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of MultistreamInfo entities. +func (c *MultistreamInfoClient) CreateBulk(builders ...*MultistreamInfoCreate) *MultistreamInfoCreateBulk { + return &MultistreamInfoCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MultistreamInfoClient) MapCreateBulk(slice any, setFunc func(*MultistreamInfoCreate, int)) *MultistreamInfoCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MultistreamInfoCreateBulk{err: fmt.Errorf("calling to MultistreamInfoClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MultistreamInfoCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MultistreamInfoCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for MultistreamInfo. +func (c *MultistreamInfoClient) Update() *MultistreamInfoUpdate { + mutation := newMultistreamInfoMutation(c.config, OpUpdate) + return &MultistreamInfoUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *MultistreamInfoClient) UpdateOne(mi *MultistreamInfo) *MultistreamInfoUpdateOne { + mutation := newMultistreamInfoMutation(c.config, OpUpdateOne, withMultistreamInfo(mi)) + return &MultistreamInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *MultistreamInfoClient) UpdateOneID(id int) *MultistreamInfoUpdateOne { + mutation := newMultistreamInfoMutation(c.config, OpUpdateOne, withMultistreamInfoID(id)) + return &MultistreamInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for MultistreamInfo. +func (c *MultistreamInfoClient) Delete() *MultistreamInfoDelete { + mutation := newMultistreamInfoMutation(c.config, OpDelete) + return &MultistreamInfoDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *MultistreamInfoClient) DeleteOne(mi *MultistreamInfo) *MultistreamInfoDeleteOne { + return c.DeleteOneID(mi.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *MultistreamInfoClient) DeleteOneID(id int) *MultistreamInfoDeleteOne { + builder := c.Delete().Where(multistreaminfo.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &MultistreamInfoDeleteOne{builder} +} + +// Query returns a query builder for MultistreamInfo. +func (c *MultistreamInfoClient) Query() *MultistreamInfoQuery { + return &MultistreamInfoQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeMultistreamInfo}, + inters: c.Interceptors(), + } +} + +// Get returns a MultistreamInfo entity by its id. +func (c *MultistreamInfoClient) Get(ctx context.Context, id int) (*MultistreamInfo, error) { + return c.Query().Where(multistreaminfo.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *MultistreamInfoClient) GetX(ctx context.Context, id int) *MultistreamInfo { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryVod queries the vod edge of a MultistreamInfo. +func (c *MultistreamInfoClient) QueryVod(mi *MultistreamInfo) *VodQuery { + query := (&VodClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := mi.ID + step := sqlgraph.NewStep( + sqlgraph.From(multistreaminfo.Table, multistreaminfo.FieldID, id), + sqlgraph.To(vod.Table, vod.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, multistreaminfo.VodTable, multistreaminfo.VodColumn), + ) + fromV = sqlgraph.Neighbors(mi.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryPlaylist queries the playlist edge of a MultistreamInfo. +func (c *MultistreamInfoClient) QueryPlaylist(mi *MultistreamInfo) *PlaylistQuery { + query := (&PlaylistClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := mi.ID + step := sqlgraph.NewStep( + sqlgraph.From(multistreaminfo.Table, multistreaminfo.FieldID, id), + sqlgraph.To(playlist.Table, playlist.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, multistreaminfo.PlaylistTable, multistreaminfo.PlaylistColumn), + ) + fromV = sqlgraph.Neighbors(mi.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *MultistreamInfoClient) Hooks() []Hook { + return c.hooks.MultistreamInfo +} + +// Interceptors returns the client interceptors. +func (c *MultistreamInfoClient) Interceptors() []Interceptor { + return c.inters.MultistreamInfo +} + +func (c *MultistreamInfoClient) mutate(ctx context.Context, m *MultistreamInfoMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&MultistreamInfoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&MultistreamInfoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&MultistreamInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&MultistreamInfoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown MultistreamInfo mutation op: %q", m.Op()) + } +} + // MutedSegmentClient is a client for the MutedSegment schema. type MutedSegmentClient struct { config @@ -1638,6 +1811,22 @@ func (c *PlaylistClient) QueryVods(pl *Playlist) *VodQuery { return query } +// QueryMultistreamInfo queries the multistream_info edge of a Playlist. +func (c *PlaylistClient) QueryMultistreamInfo(pl *Playlist) *MultistreamInfoQuery { + query := (&MultistreamInfoClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := pl.ID + step := sqlgraph.NewStep( + sqlgraph.From(playlist.Table, playlist.FieldID, id), + sqlgraph.To(multistreaminfo.Table, multistreaminfo.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, playlist.MultistreamInfoTable, playlist.MultistreamInfoColumn), + ) + fromV = sqlgraph.Neighbors(pl.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *PlaylistClient) Hooks() []Hook { return c.hooks.Playlist @@ -2266,6 +2455,22 @@ func (c *VodClient) QueryMutedSegments(v *Vod) *MutedSegmentQuery { return query } +// QueryMultistreamInfo queries the multistream_info edge of a Vod. +func (c *VodClient) QueryMultistreamInfo(v *Vod) *MultistreamInfoQuery { + query := (&MultistreamInfoClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := v.ID + step := sqlgraph.NewStep( + sqlgraph.From(vod.Table, vod.FieldID, id), + sqlgraph.To(multistreaminfo.Table, multistreaminfo.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, vod.MultistreamInfoTable, vod.MultistreamInfoColumn), + ) + fromV = sqlgraph.Neighbors(v.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *VodClient) Hooks() []Hook { return c.hooks.Vod @@ -2295,11 +2500,12 @@ func (c *VodClient) mutate(ctx context.Context, m *VodMutation) (Value, error) { type ( hooks struct { BlockedVideos, Channel, Chapter, Live, LiveCategory, LiveTitleRegex, - MutedSegment, Playback, Playlist, Queue, TwitchCategory, User, Vod []ent.Hook + MultistreamInfo, MutedSegment, Playback, Playlist, Queue, TwitchCategory, User, + Vod []ent.Hook } inters struct { BlockedVideos, Channel, Chapter, Live, LiveCategory, LiveTitleRegex, - MutedSegment, Playback, Playlist, Queue, TwitchCategory, User, + MultistreamInfo, MutedSegment, Playback, Playlist, Queue, TwitchCategory, User, Vod []ent.Interceptor } ) diff --git a/ent/ent.go b/ent/ent.go index d1787f47..a7a3fc26 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -18,6 +18,7 @@ import ( "github.com/zibbp/ganymede/ent/live" "github.com/zibbp/ganymede/ent/livecategory" "github.com/zibbp/ganymede/ent/livetitleregex" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/mutedsegment" "github.com/zibbp/ganymede/ent/playback" "github.com/zibbp/ganymede/ent/playlist" @@ -85,19 +86,20 @@ var ( func checkColumn(table, column string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - blockedvideos.Table: blockedvideos.ValidColumn, - channel.Table: channel.ValidColumn, - chapter.Table: chapter.ValidColumn, - live.Table: live.ValidColumn, - livecategory.Table: livecategory.ValidColumn, - livetitleregex.Table: livetitleregex.ValidColumn, - mutedsegment.Table: mutedsegment.ValidColumn, - playback.Table: playback.ValidColumn, - playlist.Table: playlist.ValidColumn, - queue.Table: queue.ValidColumn, - twitchcategory.Table: twitchcategory.ValidColumn, - user.Table: user.ValidColumn, - vod.Table: vod.ValidColumn, + blockedvideos.Table: blockedvideos.ValidColumn, + channel.Table: channel.ValidColumn, + chapter.Table: chapter.ValidColumn, + live.Table: live.ValidColumn, + livecategory.Table: livecategory.ValidColumn, + livetitleregex.Table: livetitleregex.ValidColumn, + multistreaminfo.Table: multistreaminfo.ValidColumn, + mutedsegment.Table: mutedsegment.ValidColumn, + playback.Table: playback.ValidColumn, + playlist.Table: playlist.ValidColumn, + queue.Table: queue.ValidColumn, + twitchcategory.Table: twitchcategory.ValidColumn, + user.Table: user.ValidColumn, + vod.Table: vod.ValidColumn, }) }) return columnCheck(table, column) diff --git a/ent/hook/hook.go b/ent/hook/hook.go index db107e62..986901f8 100644 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -81,6 +81,18 @@ func (f LiveTitleRegexFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Val return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LiveTitleRegexMutation", m) } +// The MultistreamInfoFunc type is an adapter to allow the use of ordinary +// function as MultistreamInfo mutator. +type MultistreamInfoFunc func(context.Context, *ent.MultistreamInfoMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f MultistreamInfoFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.MultistreamInfoMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MultistreamInfoMutation", m) +} + // The MutedSegmentFunc type is an adapter to allow the use of ordinary // function as MutedSegment mutator. type MutedSegmentFunc func(context.Context, *ent.MutedSegmentMutation) (ent.Value, error) diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index c5a72cc8..eeb63a4b 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -136,6 +136,33 @@ var ( }, }, } + // MultistreamInfosColumns holds the columns for the "multistream_infos" table. + MultistreamInfosColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "delay_ms", Type: field.TypeInt, Nullable: true}, + {Name: "multistream_info_vod", Type: field.TypeUUID}, + {Name: "playlist_multistream_info", Type: field.TypeUUID}, + } + // MultistreamInfosTable holds the schema information for the "multistream_infos" table. + MultistreamInfosTable = &schema.Table{ + Name: "multistream_infos", + Columns: MultistreamInfosColumns, + PrimaryKey: []*schema.Column{MultistreamInfosColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "multistream_infos_vods_vod", + Columns: []*schema.Column{MultistreamInfosColumns[2]}, + RefColumns: []*schema.Column{VodsColumns[0]}, + OnDelete: schema.NoAction, + }, + { + Symbol: "multistream_infos_playlists_multistream_info", + Columns: []*schema.Column{MultistreamInfosColumns[3]}, + RefColumns: []*schema.Column{PlaylistsColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + } // MutedSegmentsColumns holds the columns for the "muted_segments" table. MutedSegmentsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -347,6 +374,7 @@ var ( LivesTable, LiveCategoriesTable, LiveTitleRegexesTable, + MultistreamInfosTable, MutedSegmentsTable, PlaybacksTable, PlaylistsTable, @@ -363,6 +391,8 @@ func init() { LivesTable.ForeignKeys[0].RefTable = ChannelsTable LiveCategoriesTable.ForeignKeys[0].RefTable = LivesTable LiveTitleRegexesTable.ForeignKeys[0].RefTable = LivesTable + MultistreamInfosTable.ForeignKeys[0].RefTable = VodsTable + MultistreamInfosTable.ForeignKeys[1].RefTable = PlaylistsTable MutedSegmentsTable.ForeignKeys[0].RefTable = VodsTable QueuesTable.ForeignKeys[0].RefTable = VodsTable VodsTable.ForeignKeys[0].RefTable = ChannelsTable diff --git a/ent/multistreaminfo.go b/ent/multistreaminfo.go new file mode 100644 index 00000000..072a1b53 --- /dev/null +++ b/ent/multistreaminfo.go @@ -0,0 +1,170 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/zibbp/ganymede/ent/multistreaminfo" + "github.com/zibbp/ganymede/ent/playlist" + "github.com/zibbp/ganymede/ent/vod" +) + +// MultistreamInfo is the model entity for the MultistreamInfo schema. +type MultistreamInfo struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // DelayMs holds the value of the "delay_ms" field. + DelayMs int `json:"delay_ms,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the MultistreamInfoQuery when eager-loading is set. + Edges MultistreamInfoEdges `json:"edges"` + multistream_info_vod *uuid.UUID + playlist_multistream_info *uuid.UUID + selectValues sql.SelectValues +} + +// MultistreamInfoEdges holds the relations/edges for other nodes in the graph. +type MultistreamInfoEdges struct { + // Vod holds the value of the vod edge. + Vod *Vod `json:"vod,omitempty"` + // Playlist holds the value of the playlist edge. + Playlist *Playlist `json:"playlist,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool +} + +// VodOrErr returns the Vod value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e MultistreamInfoEdges) VodOrErr() (*Vod, error) { + if e.Vod != nil { + return e.Vod, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: vod.Label} + } + return nil, &NotLoadedError{edge: "vod"} +} + +// PlaylistOrErr returns the Playlist value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e MultistreamInfoEdges) PlaylistOrErr() (*Playlist, error) { + if e.Playlist != nil { + return e.Playlist, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: playlist.Label} + } + return nil, &NotLoadedError{edge: "playlist"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*MultistreamInfo) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case multistreaminfo.FieldID, multistreaminfo.FieldDelayMs: + values[i] = new(sql.NullInt64) + case multistreaminfo.ForeignKeys[0]: // multistream_info_vod + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + case multistreaminfo.ForeignKeys[1]: // playlist_multistream_info + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the MultistreamInfo fields. +func (mi *MultistreamInfo) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case multistreaminfo.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + mi.ID = int(value.Int64) + case multistreaminfo.FieldDelayMs: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field delay_ms", values[i]) + } else if value.Valid { + mi.DelayMs = int(value.Int64) + } + case multistreaminfo.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field multistream_info_vod", values[i]) + } else if value.Valid { + mi.multistream_info_vod = new(uuid.UUID) + *mi.multistream_info_vod = *value.S.(*uuid.UUID) + } + case multistreaminfo.ForeignKeys[1]: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field playlist_multistream_info", values[i]) + } else if value.Valid { + mi.playlist_multistream_info = new(uuid.UUID) + *mi.playlist_multistream_info = *value.S.(*uuid.UUID) + } + default: + mi.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the MultistreamInfo. +// This includes values selected through modifiers, order, etc. +func (mi *MultistreamInfo) Value(name string) (ent.Value, error) { + return mi.selectValues.Get(name) +} + +// QueryVod queries the "vod" edge of the MultistreamInfo entity. +func (mi *MultistreamInfo) QueryVod() *VodQuery { + return NewMultistreamInfoClient(mi.config).QueryVod(mi) +} + +// QueryPlaylist queries the "playlist" edge of the MultistreamInfo entity. +func (mi *MultistreamInfo) QueryPlaylist() *PlaylistQuery { + return NewMultistreamInfoClient(mi.config).QueryPlaylist(mi) +} + +// Update returns a builder for updating this MultistreamInfo. +// Note that you need to call MultistreamInfo.Unwrap() before calling this method if this MultistreamInfo +// was returned from a transaction, and the transaction was committed or rolled back. +func (mi *MultistreamInfo) Update() *MultistreamInfoUpdateOne { + return NewMultistreamInfoClient(mi.config).UpdateOne(mi) +} + +// Unwrap unwraps the MultistreamInfo entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (mi *MultistreamInfo) Unwrap() *MultistreamInfo { + _tx, ok := mi.config.driver.(*txDriver) + if !ok { + panic("ent: MultistreamInfo is not a transactional entity") + } + mi.config.driver = _tx.drv + return mi +} + +// String implements the fmt.Stringer. +func (mi *MultistreamInfo) String() string { + var builder strings.Builder + builder.WriteString("MultistreamInfo(") + builder.WriteString(fmt.Sprintf("id=%v, ", mi.ID)) + builder.WriteString("delay_ms=") + builder.WriteString(fmt.Sprintf("%v", mi.DelayMs)) + builder.WriteByte(')') + return builder.String() +} + +// MultistreamInfos is a parsable slice of MultistreamInfo. +type MultistreamInfos []*MultistreamInfo diff --git a/ent/multistreaminfo/multistreaminfo.go b/ent/multistreaminfo/multistreaminfo.go new file mode 100644 index 00000000..ce1ef01f --- /dev/null +++ b/ent/multistreaminfo/multistreaminfo.go @@ -0,0 +1,106 @@ +// Code generated by ent, DO NOT EDIT. + +package multistreaminfo + +import ( + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the multistreaminfo type in the database. + Label = "multistream_info" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldDelayMs holds the string denoting the delay_ms field in the database. + FieldDelayMs = "delay_ms" + // EdgeVod holds the string denoting the vod edge name in mutations. + EdgeVod = "vod" + // EdgePlaylist holds the string denoting the playlist edge name in mutations. + EdgePlaylist = "playlist" + // Table holds the table name of the multistreaminfo in the database. + Table = "multistream_infos" + // VodTable is the table that holds the vod relation/edge. + VodTable = "multistream_infos" + // VodInverseTable is the table name for the Vod entity. + // It exists in this package in order to avoid circular dependency with the "vod" package. + VodInverseTable = "vods" + // VodColumn is the table column denoting the vod relation/edge. + VodColumn = "multistream_info_vod" + // PlaylistTable is the table that holds the playlist relation/edge. + PlaylistTable = "multistream_infos" + // PlaylistInverseTable is the table name for the Playlist entity. + // It exists in this package in order to avoid circular dependency with the "playlist" package. + PlaylistInverseTable = "playlists" + // PlaylistColumn is the table column denoting the playlist relation/edge. + PlaylistColumn = "playlist_multistream_info" +) + +// Columns holds all SQL columns for multistreaminfo fields. +var Columns = []string{ + FieldID, + FieldDelayMs, +} + +// ForeignKeys holds the SQL foreign-keys that are owned by the "multistream_infos" +// table and are not defined as standalone fields in the schema. +var ForeignKeys = []string{ + "multistream_info_vod", + "playlist_multistream_info", +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + for i := range ForeignKeys { + if column == ForeignKeys[i] { + return true + } + } + return false +} + +// OrderOption defines the ordering options for the MultistreamInfo queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByDelayMs orders the results by the delay_ms field. +func ByDelayMs(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDelayMs, opts...).ToFunc() +} + +// ByVodField orders the results by vod field. +func ByVodField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newVodStep(), sql.OrderByField(field, opts...)) + } +} + +// ByPlaylistField orders the results by playlist field. +func ByPlaylistField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newPlaylistStep(), sql.OrderByField(field, opts...)) + } +} +func newVodStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(VodInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, VodTable, VodColumn), + ) +} +func newPlaylistStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(PlaylistInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, PlaylistTable, PlaylistColumn), + ) +} diff --git a/ent/multistreaminfo/where.go b/ent/multistreaminfo/where.go new file mode 100644 index 00000000..805b2dcc --- /dev/null +++ b/ent/multistreaminfo/where.go @@ -0,0 +1,170 @@ +// Code generated by ent, DO NOT EDIT. + +package multistreaminfo + +import ( + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/zibbp/ganymede/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldLTE(FieldID, id)) +} + +// DelayMs applies equality check predicate on the "delay_ms" field. It's identical to DelayMsEQ. +func DelayMs(v int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldEQ(FieldDelayMs, v)) +} + +// DelayMsEQ applies the EQ predicate on the "delay_ms" field. +func DelayMsEQ(v int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldEQ(FieldDelayMs, v)) +} + +// DelayMsNEQ applies the NEQ predicate on the "delay_ms" field. +func DelayMsNEQ(v int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldNEQ(FieldDelayMs, v)) +} + +// DelayMsIn applies the In predicate on the "delay_ms" field. +func DelayMsIn(vs ...int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldIn(FieldDelayMs, vs...)) +} + +// DelayMsNotIn applies the NotIn predicate on the "delay_ms" field. +func DelayMsNotIn(vs ...int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldNotIn(FieldDelayMs, vs...)) +} + +// DelayMsGT applies the GT predicate on the "delay_ms" field. +func DelayMsGT(v int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldGT(FieldDelayMs, v)) +} + +// DelayMsGTE applies the GTE predicate on the "delay_ms" field. +func DelayMsGTE(v int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldGTE(FieldDelayMs, v)) +} + +// DelayMsLT applies the LT predicate on the "delay_ms" field. +func DelayMsLT(v int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldLT(FieldDelayMs, v)) +} + +// DelayMsLTE applies the LTE predicate on the "delay_ms" field. +func DelayMsLTE(v int) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldLTE(FieldDelayMs, v)) +} + +// DelayMsIsNil applies the IsNil predicate on the "delay_ms" field. +func DelayMsIsNil() predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldIsNull(FieldDelayMs)) +} + +// DelayMsNotNil applies the NotNil predicate on the "delay_ms" field. +func DelayMsNotNil() predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.FieldNotNull(FieldDelayMs)) +} + +// HasVod applies the HasEdge predicate on the "vod" edge. +func HasVod() predicate.MultistreamInfo { + return predicate.MultistreamInfo(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, VodTable, VodColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasVodWith applies the HasEdge predicate on the "vod" edge with a given conditions (other predicates). +func HasVodWith(preds ...predicate.Vod) predicate.MultistreamInfo { + return predicate.MultistreamInfo(func(s *sql.Selector) { + step := newVodStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasPlaylist applies the HasEdge predicate on the "playlist" edge. +func HasPlaylist() predicate.MultistreamInfo { + return predicate.MultistreamInfo(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, PlaylistTable, PlaylistColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasPlaylistWith applies the HasEdge predicate on the "playlist" edge with a given conditions (other predicates). +func HasPlaylistWith(preds ...predicate.Playlist) predicate.MultistreamInfo { + return predicate.MultistreamInfo(func(s *sql.Selector) { + step := newPlaylistStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.MultistreamInfo) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.MultistreamInfo) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.MultistreamInfo) predicate.MultistreamInfo { + return predicate.MultistreamInfo(sql.NotPredicates(p)) +} diff --git a/ent/multistreaminfo_create.go b/ent/multistreaminfo_create.go new file mode 100644 index 00000000..fadca1d2 --- /dev/null +++ b/ent/multistreaminfo_create.go @@ -0,0 +1,564 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/zibbp/ganymede/ent/multistreaminfo" + "github.com/zibbp/ganymede/ent/playlist" + "github.com/zibbp/ganymede/ent/vod" +) + +// MultistreamInfoCreate is the builder for creating a MultistreamInfo entity. +type MultistreamInfoCreate struct { + config + mutation *MultistreamInfoMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetDelayMs sets the "delay_ms" field. +func (mic *MultistreamInfoCreate) SetDelayMs(i int) *MultistreamInfoCreate { + mic.mutation.SetDelayMs(i) + return mic +} + +// SetNillableDelayMs sets the "delay_ms" field if the given value is not nil. +func (mic *MultistreamInfoCreate) SetNillableDelayMs(i *int) *MultistreamInfoCreate { + if i != nil { + mic.SetDelayMs(*i) + } + return mic +} + +// SetVodID sets the "vod" edge to the Vod entity by ID. +func (mic *MultistreamInfoCreate) SetVodID(id uuid.UUID) *MultistreamInfoCreate { + mic.mutation.SetVodID(id) + return mic +} + +// SetVod sets the "vod" edge to the Vod entity. +func (mic *MultistreamInfoCreate) SetVod(v *Vod) *MultistreamInfoCreate { + return mic.SetVodID(v.ID) +} + +// SetPlaylistID sets the "playlist" edge to the Playlist entity by ID. +func (mic *MultistreamInfoCreate) SetPlaylistID(id uuid.UUID) *MultistreamInfoCreate { + mic.mutation.SetPlaylistID(id) + return mic +} + +// SetPlaylist sets the "playlist" edge to the Playlist entity. +func (mic *MultistreamInfoCreate) SetPlaylist(p *Playlist) *MultistreamInfoCreate { + return mic.SetPlaylistID(p.ID) +} + +// Mutation returns the MultistreamInfoMutation object of the builder. +func (mic *MultistreamInfoCreate) Mutation() *MultistreamInfoMutation { + return mic.mutation +} + +// Save creates the MultistreamInfo in the database. +func (mic *MultistreamInfoCreate) Save(ctx context.Context) (*MultistreamInfo, error) { + return withHooks(ctx, mic.sqlSave, mic.mutation, mic.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (mic *MultistreamInfoCreate) SaveX(ctx context.Context) *MultistreamInfo { + v, err := mic.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mic *MultistreamInfoCreate) Exec(ctx context.Context) error { + _, err := mic.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mic *MultistreamInfoCreate) ExecX(ctx context.Context) { + if err := mic.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (mic *MultistreamInfoCreate) check() error { + if _, ok := mic.mutation.VodID(); !ok { + return &ValidationError{Name: "vod", err: errors.New(`ent: missing required edge "MultistreamInfo.vod"`)} + } + if _, ok := mic.mutation.PlaylistID(); !ok { + return &ValidationError{Name: "playlist", err: errors.New(`ent: missing required edge "MultistreamInfo.playlist"`)} + } + return nil +} + +func (mic *MultistreamInfoCreate) sqlSave(ctx context.Context) (*MultistreamInfo, error) { + if err := mic.check(); err != nil { + return nil, err + } + _node, _spec := mic.createSpec() + if err := sqlgraph.CreateNode(ctx, mic.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + mic.mutation.id = &_node.ID + mic.mutation.done = true + return _node, nil +} + +func (mic *MultistreamInfoCreate) createSpec() (*MultistreamInfo, *sqlgraph.CreateSpec) { + var ( + _node = &MultistreamInfo{config: mic.config} + _spec = sqlgraph.NewCreateSpec(multistreaminfo.Table, sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt)) + ) + _spec.OnConflict = mic.conflict + if value, ok := mic.mutation.DelayMs(); ok { + _spec.SetField(multistreaminfo.FieldDelayMs, field.TypeInt, value) + _node.DelayMs = value + } + if nodes := mic.mutation.VodIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: multistreaminfo.VodTable, + Columns: []string{multistreaminfo.VodColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(vod.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.multistream_info_vod = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := mic.mutation.PlaylistIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: multistreaminfo.PlaylistTable, + Columns: []string{multistreaminfo.PlaylistColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(playlist.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.playlist_multistream_info = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.MultistreamInfo.Create(). +// SetDelayMs(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.MultistreamInfoUpsert) { +// SetDelayMs(v+v). +// }). +// Exec(ctx) +func (mic *MultistreamInfoCreate) OnConflict(opts ...sql.ConflictOption) *MultistreamInfoUpsertOne { + mic.conflict = opts + return &MultistreamInfoUpsertOne{ + create: mic, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.MultistreamInfo.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (mic *MultistreamInfoCreate) OnConflictColumns(columns ...string) *MultistreamInfoUpsertOne { + mic.conflict = append(mic.conflict, sql.ConflictColumns(columns...)) + return &MultistreamInfoUpsertOne{ + create: mic, + } +} + +type ( + // MultistreamInfoUpsertOne is the builder for "upsert"-ing + // one MultistreamInfo node. + MultistreamInfoUpsertOne struct { + create *MultistreamInfoCreate + } + + // MultistreamInfoUpsert is the "OnConflict" setter. + MultistreamInfoUpsert struct { + *sql.UpdateSet + } +) + +// SetDelayMs sets the "delay_ms" field. +func (u *MultistreamInfoUpsert) SetDelayMs(v int) *MultistreamInfoUpsert { + u.Set(multistreaminfo.FieldDelayMs, v) + return u +} + +// UpdateDelayMs sets the "delay_ms" field to the value that was provided on create. +func (u *MultistreamInfoUpsert) UpdateDelayMs() *MultistreamInfoUpsert { + u.SetExcluded(multistreaminfo.FieldDelayMs) + return u +} + +// AddDelayMs adds v to the "delay_ms" field. +func (u *MultistreamInfoUpsert) AddDelayMs(v int) *MultistreamInfoUpsert { + u.Add(multistreaminfo.FieldDelayMs, v) + return u +} + +// ClearDelayMs clears the value of the "delay_ms" field. +func (u *MultistreamInfoUpsert) ClearDelayMs() *MultistreamInfoUpsert { + u.SetNull(multistreaminfo.FieldDelayMs) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create. +// Using this option is equivalent to using: +// +// client.MultistreamInfo.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *MultistreamInfoUpsertOne) UpdateNewValues() *MultistreamInfoUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.MultistreamInfo.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *MultistreamInfoUpsertOne) Ignore() *MultistreamInfoUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *MultistreamInfoUpsertOne) DoNothing() *MultistreamInfoUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the MultistreamInfoCreate.OnConflict +// documentation for more info. +func (u *MultistreamInfoUpsertOne) Update(set func(*MultistreamInfoUpsert)) *MultistreamInfoUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&MultistreamInfoUpsert{UpdateSet: update}) + })) + return u +} + +// SetDelayMs sets the "delay_ms" field. +func (u *MultistreamInfoUpsertOne) SetDelayMs(v int) *MultistreamInfoUpsertOne { + return u.Update(func(s *MultistreamInfoUpsert) { + s.SetDelayMs(v) + }) +} + +// AddDelayMs adds v to the "delay_ms" field. +func (u *MultistreamInfoUpsertOne) AddDelayMs(v int) *MultistreamInfoUpsertOne { + return u.Update(func(s *MultistreamInfoUpsert) { + s.AddDelayMs(v) + }) +} + +// UpdateDelayMs sets the "delay_ms" field to the value that was provided on create. +func (u *MultistreamInfoUpsertOne) UpdateDelayMs() *MultistreamInfoUpsertOne { + return u.Update(func(s *MultistreamInfoUpsert) { + s.UpdateDelayMs() + }) +} + +// ClearDelayMs clears the value of the "delay_ms" field. +func (u *MultistreamInfoUpsertOne) ClearDelayMs() *MultistreamInfoUpsertOne { + return u.Update(func(s *MultistreamInfoUpsert) { + s.ClearDelayMs() + }) +} + +// Exec executes the query. +func (u *MultistreamInfoUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for MultistreamInfoCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *MultistreamInfoUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *MultistreamInfoUpsertOne) ID(ctx context.Context) (id int, err error) { + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *MultistreamInfoUpsertOne) IDX(ctx context.Context) int { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// MultistreamInfoCreateBulk is the builder for creating many MultistreamInfo entities in bulk. +type MultistreamInfoCreateBulk struct { + config + err error + builders []*MultistreamInfoCreate + conflict []sql.ConflictOption +} + +// Save creates the MultistreamInfo entities in the database. +func (micb *MultistreamInfoCreateBulk) Save(ctx context.Context) ([]*MultistreamInfo, error) { + if micb.err != nil { + return nil, micb.err + } + specs := make([]*sqlgraph.CreateSpec, len(micb.builders)) + nodes := make([]*MultistreamInfo, len(micb.builders)) + mutators := make([]Mutator, len(micb.builders)) + for i := range micb.builders { + func(i int, root context.Context) { + builder := micb.builders[i] + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MultistreamInfoMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, micb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = micb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, micb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, micb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (micb *MultistreamInfoCreateBulk) SaveX(ctx context.Context) []*MultistreamInfo { + v, err := micb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (micb *MultistreamInfoCreateBulk) Exec(ctx context.Context) error { + _, err := micb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (micb *MultistreamInfoCreateBulk) ExecX(ctx context.Context) { + if err := micb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.MultistreamInfo.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.MultistreamInfoUpsert) { +// SetDelayMs(v+v). +// }). +// Exec(ctx) +func (micb *MultistreamInfoCreateBulk) OnConflict(opts ...sql.ConflictOption) *MultistreamInfoUpsertBulk { + micb.conflict = opts + return &MultistreamInfoUpsertBulk{ + create: micb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.MultistreamInfo.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (micb *MultistreamInfoCreateBulk) OnConflictColumns(columns ...string) *MultistreamInfoUpsertBulk { + micb.conflict = append(micb.conflict, sql.ConflictColumns(columns...)) + return &MultistreamInfoUpsertBulk{ + create: micb, + } +} + +// MultistreamInfoUpsertBulk is the builder for "upsert"-ing +// a bulk of MultistreamInfo nodes. +type MultistreamInfoUpsertBulk struct { + create *MultistreamInfoCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.MultistreamInfo.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *MultistreamInfoUpsertBulk) UpdateNewValues() *MultistreamInfoUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.MultistreamInfo.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *MultistreamInfoUpsertBulk) Ignore() *MultistreamInfoUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *MultistreamInfoUpsertBulk) DoNothing() *MultistreamInfoUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the MultistreamInfoCreateBulk.OnConflict +// documentation for more info. +func (u *MultistreamInfoUpsertBulk) Update(set func(*MultistreamInfoUpsert)) *MultistreamInfoUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&MultistreamInfoUpsert{UpdateSet: update}) + })) + return u +} + +// SetDelayMs sets the "delay_ms" field. +func (u *MultistreamInfoUpsertBulk) SetDelayMs(v int) *MultistreamInfoUpsertBulk { + return u.Update(func(s *MultistreamInfoUpsert) { + s.SetDelayMs(v) + }) +} + +// AddDelayMs adds v to the "delay_ms" field. +func (u *MultistreamInfoUpsertBulk) AddDelayMs(v int) *MultistreamInfoUpsertBulk { + return u.Update(func(s *MultistreamInfoUpsert) { + s.AddDelayMs(v) + }) +} + +// UpdateDelayMs sets the "delay_ms" field to the value that was provided on create. +func (u *MultistreamInfoUpsertBulk) UpdateDelayMs() *MultistreamInfoUpsertBulk { + return u.Update(func(s *MultistreamInfoUpsert) { + s.UpdateDelayMs() + }) +} + +// ClearDelayMs clears the value of the "delay_ms" field. +func (u *MultistreamInfoUpsertBulk) ClearDelayMs() *MultistreamInfoUpsertBulk { + return u.Update(func(s *MultistreamInfoUpsert) { + s.ClearDelayMs() + }) +} + +// Exec executes the query. +func (u *MultistreamInfoUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the MultistreamInfoCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for MultistreamInfoCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *MultistreamInfoUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/multistreaminfo_delete.go b/ent/multistreaminfo_delete.go new file mode 100644 index 00000000..19b9276f --- /dev/null +++ b/ent/multistreaminfo_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/zibbp/ganymede/ent/multistreaminfo" + "github.com/zibbp/ganymede/ent/predicate" +) + +// MultistreamInfoDelete is the builder for deleting a MultistreamInfo entity. +type MultistreamInfoDelete struct { + config + hooks []Hook + mutation *MultistreamInfoMutation +} + +// Where appends a list predicates to the MultistreamInfoDelete builder. +func (mid *MultistreamInfoDelete) Where(ps ...predicate.MultistreamInfo) *MultistreamInfoDelete { + mid.mutation.Where(ps...) + return mid +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (mid *MultistreamInfoDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, mid.sqlExec, mid.mutation, mid.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (mid *MultistreamInfoDelete) ExecX(ctx context.Context) int { + n, err := mid.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (mid *MultistreamInfoDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(multistreaminfo.Table, sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt)) + if ps := mid.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, mid.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + mid.mutation.done = true + return affected, err +} + +// MultistreamInfoDeleteOne is the builder for deleting a single MultistreamInfo entity. +type MultistreamInfoDeleteOne struct { + mid *MultistreamInfoDelete +} + +// Where appends a list predicates to the MultistreamInfoDelete builder. +func (mido *MultistreamInfoDeleteOne) Where(ps ...predicate.MultistreamInfo) *MultistreamInfoDeleteOne { + mido.mid.mutation.Where(ps...) + return mido +} + +// Exec executes the deletion query. +func (mido *MultistreamInfoDeleteOne) Exec(ctx context.Context) error { + n, err := mido.mid.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{multistreaminfo.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (mido *MultistreamInfoDeleteOne) ExecX(ctx context.Context) { + if err := mido.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/multistreaminfo_query.go b/ent/multistreaminfo_query.go new file mode 100644 index 00000000..4b73a26c --- /dev/null +++ b/ent/multistreaminfo_query.go @@ -0,0 +1,689 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/zibbp/ganymede/ent/multistreaminfo" + "github.com/zibbp/ganymede/ent/playlist" + "github.com/zibbp/ganymede/ent/predicate" + "github.com/zibbp/ganymede/ent/vod" +) + +// MultistreamInfoQuery is the builder for querying MultistreamInfo entities. +type MultistreamInfoQuery struct { + config + ctx *QueryContext + order []multistreaminfo.OrderOption + inters []Interceptor + predicates []predicate.MultistreamInfo + withVod *VodQuery + withPlaylist *PlaylistQuery + withFKs bool + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the MultistreamInfoQuery builder. +func (miq *MultistreamInfoQuery) Where(ps ...predicate.MultistreamInfo) *MultistreamInfoQuery { + miq.predicates = append(miq.predicates, ps...) + return miq +} + +// Limit the number of records to be returned by this query. +func (miq *MultistreamInfoQuery) Limit(limit int) *MultistreamInfoQuery { + miq.ctx.Limit = &limit + return miq +} + +// Offset to start from. +func (miq *MultistreamInfoQuery) Offset(offset int) *MultistreamInfoQuery { + miq.ctx.Offset = &offset + return miq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (miq *MultistreamInfoQuery) Unique(unique bool) *MultistreamInfoQuery { + miq.ctx.Unique = &unique + return miq +} + +// Order specifies how the records should be ordered. +func (miq *MultistreamInfoQuery) Order(o ...multistreaminfo.OrderOption) *MultistreamInfoQuery { + miq.order = append(miq.order, o...) + return miq +} + +// QueryVod chains the current query on the "vod" edge. +func (miq *MultistreamInfoQuery) QueryVod() *VodQuery { + query := (&VodClient{config: miq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := miq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := miq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(multistreaminfo.Table, multistreaminfo.FieldID, selector), + sqlgraph.To(vod.Table, vod.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, multistreaminfo.VodTable, multistreaminfo.VodColumn), + ) + fromU = sqlgraph.SetNeighbors(miq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryPlaylist chains the current query on the "playlist" edge. +func (miq *MultistreamInfoQuery) QueryPlaylist() *PlaylistQuery { + query := (&PlaylistClient{config: miq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := miq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := miq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(multistreaminfo.Table, multistreaminfo.FieldID, selector), + sqlgraph.To(playlist.Table, playlist.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, multistreaminfo.PlaylistTable, multistreaminfo.PlaylistColumn), + ) + fromU = sqlgraph.SetNeighbors(miq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first MultistreamInfo entity from the query. +// Returns a *NotFoundError when no MultistreamInfo was found. +func (miq *MultistreamInfoQuery) First(ctx context.Context) (*MultistreamInfo, error) { + nodes, err := miq.Limit(1).All(setContextOp(ctx, miq.ctx, "First")) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{multistreaminfo.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (miq *MultistreamInfoQuery) FirstX(ctx context.Context) *MultistreamInfo { + node, err := miq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first MultistreamInfo ID from the query. +// Returns a *NotFoundError when no MultistreamInfo ID was found. +func (miq *MultistreamInfoQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = miq.Limit(1).IDs(setContextOp(ctx, miq.ctx, "FirstID")); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{multistreaminfo.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (miq *MultistreamInfoQuery) FirstIDX(ctx context.Context) int { + id, err := miq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single MultistreamInfo entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one MultistreamInfo entity is found. +// Returns a *NotFoundError when no MultistreamInfo entities are found. +func (miq *MultistreamInfoQuery) Only(ctx context.Context) (*MultistreamInfo, error) { + nodes, err := miq.Limit(2).All(setContextOp(ctx, miq.ctx, "Only")) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{multistreaminfo.Label} + default: + return nil, &NotSingularError{multistreaminfo.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (miq *MultistreamInfoQuery) OnlyX(ctx context.Context) *MultistreamInfo { + node, err := miq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only MultistreamInfo ID in the query. +// Returns a *NotSingularError when more than one MultistreamInfo ID is found. +// Returns a *NotFoundError when no entities are found. +func (miq *MultistreamInfoQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = miq.Limit(2).IDs(setContextOp(ctx, miq.ctx, "OnlyID")); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{multistreaminfo.Label} + default: + err = &NotSingularError{multistreaminfo.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (miq *MultistreamInfoQuery) OnlyIDX(ctx context.Context) int { + id, err := miq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of MultistreamInfos. +func (miq *MultistreamInfoQuery) All(ctx context.Context) ([]*MultistreamInfo, error) { + ctx = setContextOp(ctx, miq.ctx, "All") + if err := miq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*MultistreamInfo, *MultistreamInfoQuery]() + return withInterceptors[[]*MultistreamInfo](ctx, miq, qr, miq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (miq *MultistreamInfoQuery) AllX(ctx context.Context) []*MultistreamInfo { + nodes, err := miq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of MultistreamInfo IDs. +func (miq *MultistreamInfoQuery) IDs(ctx context.Context) (ids []int, err error) { + if miq.ctx.Unique == nil && miq.path != nil { + miq.Unique(true) + } + ctx = setContextOp(ctx, miq.ctx, "IDs") + if err = miq.Select(multistreaminfo.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (miq *MultistreamInfoQuery) IDsX(ctx context.Context) []int { + ids, err := miq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (miq *MultistreamInfoQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, miq.ctx, "Count") + if err := miq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, miq, querierCount[*MultistreamInfoQuery](), miq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (miq *MultistreamInfoQuery) CountX(ctx context.Context) int { + count, err := miq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (miq *MultistreamInfoQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, miq.ctx, "Exist") + switch _, err := miq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (miq *MultistreamInfoQuery) ExistX(ctx context.Context) bool { + exist, err := miq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the MultistreamInfoQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (miq *MultistreamInfoQuery) Clone() *MultistreamInfoQuery { + if miq == nil { + return nil + } + return &MultistreamInfoQuery{ + config: miq.config, + ctx: miq.ctx.Clone(), + order: append([]multistreaminfo.OrderOption{}, miq.order...), + inters: append([]Interceptor{}, miq.inters...), + predicates: append([]predicate.MultistreamInfo{}, miq.predicates...), + withVod: miq.withVod.Clone(), + withPlaylist: miq.withPlaylist.Clone(), + // clone intermediate query. + sql: miq.sql.Clone(), + path: miq.path, + } +} + +// WithVod tells the query-builder to eager-load the nodes that are connected to +// the "vod" edge. The optional arguments are used to configure the query builder of the edge. +func (miq *MultistreamInfoQuery) WithVod(opts ...func(*VodQuery)) *MultistreamInfoQuery { + query := (&VodClient{config: miq.config}).Query() + for _, opt := range opts { + opt(query) + } + miq.withVod = query + return miq +} + +// WithPlaylist tells the query-builder to eager-load the nodes that are connected to +// the "playlist" edge. The optional arguments are used to configure the query builder of the edge. +func (miq *MultistreamInfoQuery) WithPlaylist(opts ...func(*PlaylistQuery)) *MultistreamInfoQuery { + query := (&PlaylistClient{config: miq.config}).Query() + for _, opt := range opts { + opt(query) + } + miq.withPlaylist = query + return miq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// DelayMs int `json:"delay_ms,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.MultistreamInfo.Query(). +// GroupBy(multistreaminfo.FieldDelayMs). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (miq *MultistreamInfoQuery) GroupBy(field string, fields ...string) *MultistreamInfoGroupBy { + miq.ctx.Fields = append([]string{field}, fields...) + grbuild := &MultistreamInfoGroupBy{build: miq} + grbuild.flds = &miq.ctx.Fields + grbuild.label = multistreaminfo.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// DelayMs int `json:"delay_ms,omitempty"` +// } +// +// client.MultistreamInfo.Query(). +// Select(multistreaminfo.FieldDelayMs). +// Scan(ctx, &v) +func (miq *MultistreamInfoQuery) Select(fields ...string) *MultistreamInfoSelect { + miq.ctx.Fields = append(miq.ctx.Fields, fields...) + sbuild := &MultistreamInfoSelect{MultistreamInfoQuery: miq} + sbuild.label = multistreaminfo.Label + sbuild.flds, sbuild.scan = &miq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a MultistreamInfoSelect configured with the given aggregations. +func (miq *MultistreamInfoQuery) Aggregate(fns ...AggregateFunc) *MultistreamInfoSelect { + return miq.Select().Aggregate(fns...) +} + +func (miq *MultistreamInfoQuery) prepareQuery(ctx context.Context) error { + for _, inter := range miq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, miq); err != nil { + return err + } + } + } + for _, f := range miq.ctx.Fields { + if !multistreaminfo.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if miq.path != nil { + prev, err := miq.path(ctx) + if err != nil { + return err + } + miq.sql = prev + } + return nil +} + +func (miq *MultistreamInfoQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*MultistreamInfo, error) { + var ( + nodes = []*MultistreamInfo{} + withFKs = miq.withFKs + _spec = miq.querySpec() + loadedTypes = [2]bool{ + miq.withVod != nil, + miq.withPlaylist != nil, + } + ) + if miq.withVod != nil || miq.withPlaylist != nil { + withFKs = true + } + if withFKs { + _spec.Node.Columns = append(_spec.Node.Columns, multistreaminfo.ForeignKeys...) + } + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*MultistreamInfo).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &MultistreamInfo{config: miq.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, miq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := miq.withVod; query != nil { + if err := miq.loadVod(ctx, query, nodes, nil, + func(n *MultistreamInfo, e *Vod) { n.Edges.Vod = e }); err != nil { + return nil, err + } + } + if query := miq.withPlaylist; query != nil { + if err := miq.loadPlaylist(ctx, query, nodes, nil, + func(n *MultistreamInfo, e *Playlist) { n.Edges.Playlist = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (miq *MultistreamInfoQuery) loadVod(ctx context.Context, query *VodQuery, nodes []*MultistreamInfo, init func(*MultistreamInfo), assign func(*MultistreamInfo, *Vod)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*MultistreamInfo) + for i := range nodes { + if nodes[i].multistream_info_vod == nil { + continue + } + fk := *nodes[i].multistream_info_vod + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(vod.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "multistream_info_vod" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (miq *MultistreamInfoQuery) loadPlaylist(ctx context.Context, query *PlaylistQuery, nodes []*MultistreamInfo, init func(*MultistreamInfo), assign func(*MultistreamInfo, *Playlist)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*MultistreamInfo) + for i := range nodes { + if nodes[i].playlist_multistream_info == nil { + continue + } + fk := *nodes[i].playlist_multistream_info + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(playlist.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "playlist_multistream_info" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (miq *MultistreamInfoQuery) sqlCount(ctx context.Context) (int, error) { + _spec := miq.querySpec() + _spec.Node.Columns = miq.ctx.Fields + if len(miq.ctx.Fields) > 0 { + _spec.Unique = miq.ctx.Unique != nil && *miq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, miq.driver, _spec) +} + +func (miq *MultistreamInfoQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(multistreaminfo.Table, multistreaminfo.Columns, sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt)) + _spec.From = miq.sql + if unique := miq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if miq.path != nil { + _spec.Unique = true + } + if fields := miq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, multistreaminfo.FieldID) + for i := range fields { + if fields[i] != multistreaminfo.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := miq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := miq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := miq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := miq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (miq *MultistreamInfoQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(miq.driver.Dialect()) + t1 := builder.Table(multistreaminfo.Table) + columns := miq.ctx.Fields + if len(columns) == 0 { + columns = multistreaminfo.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if miq.sql != nil { + selector = miq.sql + selector.Select(selector.Columns(columns...)...) + } + if miq.ctx.Unique != nil && *miq.ctx.Unique { + selector.Distinct() + } + for _, p := range miq.predicates { + p(selector) + } + for _, p := range miq.order { + p(selector) + } + if offset := miq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := miq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// MultistreamInfoGroupBy is the group-by builder for MultistreamInfo entities. +type MultistreamInfoGroupBy struct { + selector + build *MultistreamInfoQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (migb *MultistreamInfoGroupBy) Aggregate(fns ...AggregateFunc) *MultistreamInfoGroupBy { + migb.fns = append(migb.fns, fns...) + return migb +} + +// Scan applies the selector query and scans the result into the given value. +func (migb *MultistreamInfoGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, migb.build.ctx, "GroupBy") + if err := migb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*MultistreamInfoQuery, *MultistreamInfoGroupBy](ctx, migb.build, migb, migb.build.inters, v) +} + +func (migb *MultistreamInfoGroupBy) sqlScan(ctx context.Context, root *MultistreamInfoQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(migb.fns)) + for _, fn := range migb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*migb.flds)+len(migb.fns)) + for _, f := range *migb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*migb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := migb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// MultistreamInfoSelect is the builder for selecting fields of MultistreamInfo entities. +type MultistreamInfoSelect struct { + *MultistreamInfoQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (mis *MultistreamInfoSelect) Aggregate(fns ...AggregateFunc) *MultistreamInfoSelect { + mis.fns = append(mis.fns, fns...) + return mis +} + +// Scan applies the selector query and scans the result into the given value. +func (mis *MultistreamInfoSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, mis.ctx, "Select") + if err := mis.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*MultistreamInfoQuery, *MultistreamInfoSelect](ctx, mis.MultistreamInfoQuery, mis, mis.inters, v) +} + +func (mis *MultistreamInfoSelect) sqlScan(ctx context.Context, root *MultistreamInfoQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(mis.fns)) + for _, fn := range mis.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*mis.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := mis.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/multistreaminfo_update.go b/ent/multistreaminfo_update.go new file mode 100644 index 00000000..1ad1555c --- /dev/null +++ b/ent/multistreaminfo_update.go @@ -0,0 +1,369 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/zibbp/ganymede/ent/multistreaminfo" + "github.com/zibbp/ganymede/ent/playlist" + "github.com/zibbp/ganymede/ent/predicate" +) + +// MultistreamInfoUpdate is the builder for updating MultistreamInfo entities. +type MultistreamInfoUpdate struct { + config + hooks []Hook + mutation *MultistreamInfoMutation +} + +// Where appends a list predicates to the MultistreamInfoUpdate builder. +func (miu *MultistreamInfoUpdate) Where(ps ...predicate.MultistreamInfo) *MultistreamInfoUpdate { + miu.mutation.Where(ps...) + return miu +} + +// SetDelayMs sets the "delay_ms" field. +func (miu *MultistreamInfoUpdate) SetDelayMs(i int) *MultistreamInfoUpdate { + miu.mutation.ResetDelayMs() + miu.mutation.SetDelayMs(i) + return miu +} + +// SetNillableDelayMs sets the "delay_ms" field if the given value is not nil. +func (miu *MultistreamInfoUpdate) SetNillableDelayMs(i *int) *MultistreamInfoUpdate { + if i != nil { + miu.SetDelayMs(*i) + } + return miu +} + +// AddDelayMs adds i to the "delay_ms" field. +func (miu *MultistreamInfoUpdate) AddDelayMs(i int) *MultistreamInfoUpdate { + miu.mutation.AddDelayMs(i) + return miu +} + +// ClearDelayMs clears the value of the "delay_ms" field. +func (miu *MultistreamInfoUpdate) ClearDelayMs() *MultistreamInfoUpdate { + miu.mutation.ClearDelayMs() + return miu +} + +// SetPlaylistID sets the "playlist" edge to the Playlist entity by ID. +func (miu *MultistreamInfoUpdate) SetPlaylistID(id uuid.UUID) *MultistreamInfoUpdate { + miu.mutation.SetPlaylistID(id) + return miu +} + +// SetPlaylist sets the "playlist" edge to the Playlist entity. +func (miu *MultistreamInfoUpdate) SetPlaylist(p *Playlist) *MultistreamInfoUpdate { + return miu.SetPlaylistID(p.ID) +} + +// Mutation returns the MultistreamInfoMutation object of the builder. +func (miu *MultistreamInfoUpdate) Mutation() *MultistreamInfoMutation { + return miu.mutation +} + +// ClearPlaylist clears the "playlist" edge to the Playlist entity. +func (miu *MultistreamInfoUpdate) ClearPlaylist() *MultistreamInfoUpdate { + miu.mutation.ClearPlaylist() + return miu +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (miu *MultistreamInfoUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, miu.sqlSave, miu.mutation, miu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (miu *MultistreamInfoUpdate) SaveX(ctx context.Context) int { + affected, err := miu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (miu *MultistreamInfoUpdate) Exec(ctx context.Context) error { + _, err := miu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (miu *MultistreamInfoUpdate) ExecX(ctx context.Context) { + if err := miu.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (miu *MultistreamInfoUpdate) check() error { + if _, ok := miu.mutation.VodID(); miu.mutation.VodCleared() && !ok { + return errors.New(`ent: clearing a required unique edge "MultistreamInfo.vod"`) + } + if _, ok := miu.mutation.PlaylistID(); miu.mutation.PlaylistCleared() && !ok { + return errors.New(`ent: clearing a required unique edge "MultistreamInfo.playlist"`) + } + return nil +} + +func (miu *MultistreamInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := miu.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(multistreaminfo.Table, multistreaminfo.Columns, sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt)) + if ps := miu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := miu.mutation.DelayMs(); ok { + _spec.SetField(multistreaminfo.FieldDelayMs, field.TypeInt, value) + } + if value, ok := miu.mutation.AddedDelayMs(); ok { + _spec.AddField(multistreaminfo.FieldDelayMs, field.TypeInt, value) + } + if miu.mutation.DelayMsCleared() { + _spec.ClearField(multistreaminfo.FieldDelayMs, field.TypeInt) + } + if miu.mutation.PlaylistCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: multistreaminfo.PlaylistTable, + Columns: []string{multistreaminfo.PlaylistColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(playlist.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := miu.mutation.PlaylistIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: multistreaminfo.PlaylistTable, + Columns: []string{multistreaminfo.PlaylistColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(playlist.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, miu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{multistreaminfo.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + miu.mutation.done = true + return n, nil +} + +// MultistreamInfoUpdateOne is the builder for updating a single MultistreamInfo entity. +type MultistreamInfoUpdateOne struct { + config + fields []string + hooks []Hook + mutation *MultistreamInfoMutation +} + +// SetDelayMs sets the "delay_ms" field. +func (miuo *MultistreamInfoUpdateOne) SetDelayMs(i int) *MultistreamInfoUpdateOne { + miuo.mutation.ResetDelayMs() + miuo.mutation.SetDelayMs(i) + return miuo +} + +// SetNillableDelayMs sets the "delay_ms" field if the given value is not nil. +func (miuo *MultistreamInfoUpdateOne) SetNillableDelayMs(i *int) *MultistreamInfoUpdateOne { + if i != nil { + miuo.SetDelayMs(*i) + } + return miuo +} + +// AddDelayMs adds i to the "delay_ms" field. +func (miuo *MultistreamInfoUpdateOne) AddDelayMs(i int) *MultistreamInfoUpdateOne { + miuo.mutation.AddDelayMs(i) + return miuo +} + +// ClearDelayMs clears the value of the "delay_ms" field. +func (miuo *MultistreamInfoUpdateOne) ClearDelayMs() *MultistreamInfoUpdateOne { + miuo.mutation.ClearDelayMs() + return miuo +} + +// SetPlaylistID sets the "playlist" edge to the Playlist entity by ID. +func (miuo *MultistreamInfoUpdateOne) SetPlaylistID(id uuid.UUID) *MultistreamInfoUpdateOne { + miuo.mutation.SetPlaylistID(id) + return miuo +} + +// SetPlaylist sets the "playlist" edge to the Playlist entity. +func (miuo *MultistreamInfoUpdateOne) SetPlaylist(p *Playlist) *MultistreamInfoUpdateOne { + return miuo.SetPlaylistID(p.ID) +} + +// Mutation returns the MultistreamInfoMutation object of the builder. +func (miuo *MultistreamInfoUpdateOne) Mutation() *MultistreamInfoMutation { + return miuo.mutation +} + +// ClearPlaylist clears the "playlist" edge to the Playlist entity. +func (miuo *MultistreamInfoUpdateOne) ClearPlaylist() *MultistreamInfoUpdateOne { + miuo.mutation.ClearPlaylist() + return miuo +} + +// Where appends a list predicates to the MultistreamInfoUpdate builder. +func (miuo *MultistreamInfoUpdateOne) Where(ps ...predicate.MultistreamInfo) *MultistreamInfoUpdateOne { + miuo.mutation.Where(ps...) + return miuo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (miuo *MultistreamInfoUpdateOne) Select(field string, fields ...string) *MultistreamInfoUpdateOne { + miuo.fields = append([]string{field}, fields...) + return miuo +} + +// Save executes the query and returns the updated MultistreamInfo entity. +func (miuo *MultistreamInfoUpdateOne) Save(ctx context.Context) (*MultistreamInfo, error) { + return withHooks(ctx, miuo.sqlSave, miuo.mutation, miuo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (miuo *MultistreamInfoUpdateOne) SaveX(ctx context.Context) *MultistreamInfo { + node, err := miuo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (miuo *MultistreamInfoUpdateOne) Exec(ctx context.Context) error { + _, err := miuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (miuo *MultistreamInfoUpdateOne) ExecX(ctx context.Context) { + if err := miuo.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (miuo *MultistreamInfoUpdateOne) check() error { + if _, ok := miuo.mutation.VodID(); miuo.mutation.VodCleared() && !ok { + return errors.New(`ent: clearing a required unique edge "MultistreamInfo.vod"`) + } + if _, ok := miuo.mutation.PlaylistID(); miuo.mutation.PlaylistCleared() && !ok { + return errors.New(`ent: clearing a required unique edge "MultistreamInfo.playlist"`) + } + return nil +} + +func (miuo *MultistreamInfoUpdateOne) sqlSave(ctx context.Context) (_node *MultistreamInfo, err error) { + if err := miuo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(multistreaminfo.Table, multistreaminfo.Columns, sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt)) + id, ok := miuo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MultistreamInfo.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := miuo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, multistreaminfo.FieldID) + for _, f := range fields { + if !multistreaminfo.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != multistreaminfo.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := miuo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := miuo.mutation.DelayMs(); ok { + _spec.SetField(multistreaminfo.FieldDelayMs, field.TypeInt, value) + } + if value, ok := miuo.mutation.AddedDelayMs(); ok { + _spec.AddField(multistreaminfo.FieldDelayMs, field.TypeInt, value) + } + if miuo.mutation.DelayMsCleared() { + _spec.ClearField(multistreaminfo.FieldDelayMs, field.TypeInt) + } + if miuo.mutation.PlaylistCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: multistreaminfo.PlaylistTable, + Columns: []string{multistreaminfo.PlaylistColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(playlist.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := miuo.mutation.PlaylistIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: multistreaminfo.PlaylistTable, + Columns: []string{multistreaminfo.PlaylistColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(playlist.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &MultistreamInfo{config: miuo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, miuo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{multistreaminfo.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + miuo.mutation.done = true + return _node, nil +} diff --git a/ent/mutation.go b/ent/mutation.go index e64d25c3..caf5ea53 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -18,6 +18,7 @@ import ( "github.com/zibbp/ganymede/ent/live" "github.com/zibbp/ganymede/ent/livecategory" "github.com/zibbp/ganymede/ent/livetitleregex" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/mutedsegment" "github.com/zibbp/ganymede/ent/playback" "github.com/zibbp/ganymede/ent/playlist" @@ -38,19 +39,20 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeBlockedVideos = "BlockedVideos" - TypeChannel = "Channel" - TypeChapter = "Chapter" - TypeLive = "Live" - TypeLiveCategory = "LiveCategory" - TypeLiveTitleRegex = "LiveTitleRegex" - TypeMutedSegment = "MutedSegment" - TypePlayback = "Playback" - TypePlaylist = "Playlist" - TypeQueue = "Queue" - TypeTwitchCategory = "TwitchCategory" - TypeUser = "User" - TypeVod = "Vod" + TypeBlockedVideos = "BlockedVideos" + TypeChannel = "Channel" + TypeChapter = "Chapter" + TypeLive = "Live" + TypeLiveCategory = "LiveCategory" + TypeLiveTitleRegex = "LiveTitleRegex" + TypeMultistreamInfo = "MultistreamInfo" + TypeMutedSegment = "MutedSegment" + TypePlayback = "Playback" + TypePlaylist = "Playlist" + TypeQueue = "Queue" + TypeTwitchCategory = "TwitchCategory" + TypeUser = "User" + TypeVod = "Vod" ) // BlockedVideosMutation represents an operation that mutates the BlockedVideos nodes in the graph. @@ -4347,6 +4349,517 @@ func (m *LiveTitleRegexMutation) ResetEdge(name string) error { return fmt.Errorf("unknown LiveTitleRegex edge %s", name) } +// MultistreamInfoMutation represents an operation that mutates the MultistreamInfo nodes in the graph. +type MultistreamInfoMutation struct { + config + op Op + typ string + id *int + delay_ms *int + adddelay_ms *int + clearedFields map[string]struct{} + vod *uuid.UUID + clearedvod bool + playlist *uuid.UUID + clearedplaylist bool + done bool + oldValue func(context.Context) (*MultistreamInfo, error) + predicates []predicate.MultistreamInfo +} + +var _ ent.Mutation = (*MultistreamInfoMutation)(nil) + +// multistreaminfoOption allows management of the mutation configuration using functional options. +type multistreaminfoOption func(*MultistreamInfoMutation) + +// newMultistreamInfoMutation creates new mutation for the MultistreamInfo entity. +func newMultistreamInfoMutation(c config, op Op, opts ...multistreaminfoOption) *MultistreamInfoMutation { + m := &MultistreamInfoMutation{ + config: c, + op: op, + typ: TypeMultistreamInfo, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withMultistreamInfoID sets the ID field of the mutation. +func withMultistreamInfoID(id int) multistreaminfoOption { + return func(m *MultistreamInfoMutation) { + var ( + err error + once sync.Once + value *MultistreamInfo + ) + m.oldValue = func(ctx context.Context) (*MultistreamInfo, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().MultistreamInfo.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withMultistreamInfo sets the old MultistreamInfo of the mutation. +func withMultistreamInfo(node *MultistreamInfo) multistreaminfoOption { + return func(m *MultistreamInfoMutation) { + m.oldValue = func(context.Context) (*MultistreamInfo, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m MultistreamInfoMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m MultistreamInfoMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *MultistreamInfoMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *MultistreamInfoMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().MultistreamInfo.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetDelayMs sets the "delay_ms" field. +func (m *MultistreamInfoMutation) SetDelayMs(i int) { + m.delay_ms = &i + m.adddelay_ms = nil +} + +// DelayMs returns the value of the "delay_ms" field in the mutation. +func (m *MultistreamInfoMutation) DelayMs() (r int, exists bool) { + v := m.delay_ms + if v == nil { + return + } + return *v, true +} + +// OldDelayMs returns the old "delay_ms" field's value of the MultistreamInfo entity. +// If the MultistreamInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MultistreamInfoMutation) OldDelayMs(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDelayMs is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDelayMs requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDelayMs: %w", err) + } + return oldValue.DelayMs, nil +} + +// AddDelayMs adds i to the "delay_ms" field. +func (m *MultistreamInfoMutation) AddDelayMs(i int) { + if m.adddelay_ms != nil { + *m.adddelay_ms += i + } else { + m.adddelay_ms = &i + } +} + +// AddedDelayMs returns the value that was added to the "delay_ms" field in this mutation. +func (m *MultistreamInfoMutation) AddedDelayMs() (r int, exists bool) { + v := m.adddelay_ms + if v == nil { + return + } + return *v, true +} + +// ClearDelayMs clears the value of the "delay_ms" field. +func (m *MultistreamInfoMutation) ClearDelayMs() { + m.delay_ms = nil + m.adddelay_ms = nil + m.clearedFields[multistreaminfo.FieldDelayMs] = struct{}{} +} + +// DelayMsCleared returns if the "delay_ms" field was cleared in this mutation. +func (m *MultistreamInfoMutation) DelayMsCleared() bool { + _, ok := m.clearedFields[multistreaminfo.FieldDelayMs] + return ok +} + +// ResetDelayMs resets all changes to the "delay_ms" field. +func (m *MultistreamInfoMutation) ResetDelayMs() { + m.delay_ms = nil + m.adddelay_ms = nil + delete(m.clearedFields, multistreaminfo.FieldDelayMs) +} + +// SetVodID sets the "vod" edge to the Vod entity by id. +func (m *MultistreamInfoMutation) SetVodID(id uuid.UUID) { + m.vod = &id +} + +// ClearVod clears the "vod" edge to the Vod entity. +func (m *MultistreamInfoMutation) ClearVod() { + m.clearedvod = true +} + +// VodCleared reports if the "vod" edge to the Vod entity was cleared. +func (m *MultistreamInfoMutation) VodCleared() bool { + return m.clearedvod +} + +// VodID returns the "vod" edge ID in the mutation. +func (m *MultistreamInfoMutation) VodID() (id uuid.UUID, exists bool) { + if m.vod != nil { + return *m.vod, true + } + return +} + +// VodIDs returns the "vod" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// VodID instead. It exists only for internal usage by the builders. +func (m *MultistreamInfoMutation) VodIDs() (ids []uuid.UUID) { + if id := m.vod; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetVod resets all changes to the "vod" edge. +func (m *MultistreamInfoMutation) ResetVod() { + m.vod = nil + m.clearedvod = false +} + +// SetPlaylistID sets the "playlist" edge to the Playlist entity by id. +func (m *MultistreamInfoMutation) SetPlaylistID(id uuid.UUID) { + m.playlist = &id +} + +// ClearPlaylist clears the "playlist" edge to the Playlist entity. +func (m *MultistreamInfoMutation) ClearPlaylist() { + m.clearedplaylist = true +} + +// PlaylistCleared reports if the "playlist" edge to the Playlist entity was cleared. +func (m *MultistreamInfoMutation) PlaylistCleared() bool { + return m.clearedplaylist +} + +// PlaylistID returns the "playlist" edge ID in the mutation. +func (m *MultistreamInfoMutation) PlaylistID() (id uuid.UUID, exists bool) { + if m.playlist != nil { + return *m.playlist, true + } + return +} + +// PlaylistIDs returns the "playlist" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// PlaylistID instead. It exists only for internal usage by the builders. +func (m *MultistreamInfoMutation) PlaylistIDs() (ids []uuid.UUID) { + if id := m.playlist; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetPlaylist resets all changes to the "playlist" edge. +func (m *MultistreamInfoMutation) ResetPlaylist() { + m.playlist = nil + m.clearedplaylist = false +} + +// Where appends a list predicates to the MultistreamInfoMutation builder. +func (m *MultistreamInfoMutation) Where(ps ...predicate.MultistreamInfo) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the MultistreamInfoMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *MultistreamInfoMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.MultistreamInfo, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *MultistreamInfoMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *MultistreamInfoMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (MultistreamInfo). +func (m *MultistreamInfoMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *MultistreamInfoMutation) Fields() []string { + fields := make([]string, 0, 1) + if m.delay_ms != nil { + fields = append(fields, multistreaminfo.FieldDelayMs) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *MultistreamInfoMutation) Field(name string) (ent.Value, bool) { + switch name { + case multistreaminfo.FieldDelayMs: + return m.DelayMs() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *MultistreamInfoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case multistreaminfo.FieldDelayMs: + return m.OldDelayMs(ctx) + } + return nil, fmt.Errorf("unknown MultistreamInfo field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *MultistreamInfoMutation) SetField(name string, value ent.Value) error { + switch name { + case multistreaminfo.FieldDelayMs: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDelayMs(v) + return nil + } + return fmt.Errorf("unknown MultistreamInfo field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *MultistreamInfoMutation) AddedFields() []string { + var fields []string + if m.adddelay_ms != nil { + fields = append(fields, multistreaminfo.FieldDelayMs) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *MultistreamInfoMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case multistreaminfo.FieldDelayMs: + return m.AddedDelayMs() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *MultistreamInfoMutation) AddField(name string, value ent.Value) error { + switch name { + case multistreaminfo.FieldDelayMs: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddDelayMs(v) + return nil + } + return fmt.Errorf("unknown MultistreamInfo numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *MultistreamInfoMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(multistreaminfo.FieldDelayMs) { + fields = append(fields, multistreaminfo.FieldDelayMs) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *MultistreamInfoMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *MultistreamInfoMutation) ClearField(name string) error { + switch name { + case multistreaminfo.FieldDelayMs: + m.ClearDelayMs() + return nil + } + return fmt.Errorf("unknown MultistreamInfo nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *MultistreamInfoMutation) ResetField(name string) error { + switch name { + case multistreaminfo.FieldDelayMs: + m.ResetDelayMs() + return nil + } + return fmt.Errorf("unknown MultistreamInfo field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *MultistreamInfoMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.vod != nil { + edges = append(edges, multistreaminfo.EdgeVod) + } + if m.playlist != nil { + edges = append(edges, multistreaminfo.EdgePlaylist) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *MultistreamInfoMutation) AddedIDs(name string) []ent.Value { + switch name { + case multistreaminfo.EdgeVod: + if id := m.vod; id != nil { + return []ent.Value{*id} + } + case multistreaminfo.EdgePlaylist: + if id := m.playlist; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *MultistreamInfoMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *MultistreamInfoMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *MultistreamInfoMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedvod { + edges = append(edges, multistreaminfo.EdgeVod) + } + if m.clearedplaylist { + edges = append(edges, multistreaminfo.EdgePlaylist) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *MultistreamInfoMutation) EdgeCleared(name string) bool { + switch name { + case multistreaminfo.EdgeVod: + return m.clearedvod + case multistreaminfo.EdgePlaylist: + return m.clearedplaylist + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *MultistreamInfoMutation) ClearEdge(name string) error { + switch name { + case multistreaminfo.EdgeVod: + m.ClearVod() + return nil + case multistreaminfo.EdgePlaylist: + m.ClearPlaylist() + return nil + } + return fmt.Errorf("unknown MultistreamInfo unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *MultistreamInfoMutation) ResetEdge(name string) error { + switch name { + case multistreaminfo.EdgeVod: + m.ResetVod() + return nil + case multistreaminfo.EdgePlaylist: + m.ResetPlaylist() + return nil + } + return fmt.Errorf("unknown MultistreamInfo edge %s", name) +} + // MutedSegmentMutation represents an operation that mutates the MutedSegment nodes in the graph. type MutedSegmentMutation struct { config @@ -5532,21 +6045,24 @@ func (m *PlaybackMutation) ResetEdge(name string) error { // PlaylistMutation represents an operation that mutates the Playlist nodes in the graph. type PlaylistMutation struct { config - op Op - typ string - id *uuid.UUID - name *string - description *string - thumbnail_path *string - updated_at *time.Time - created_at *time.Time - clearedFields map[string]struct{} - vods map[uuid.UUID]struct{} - removedvods map[uuid.UUID]struct{} - clearedvods bool - done bool - oldValue func(context.Context) (*Playlist, error) - predicates []predicate.Playlist + op Op + typ string + id *uuid.UUID + name *string + description *string + thumbnail_path *string + updated_at *time.Time + created_at *time.Time + clearedFields map[string]struct{} + vods map[uuid.UUID]struct{} + removedvods map[uuid.UUID]struct{} + clearedvods bool + multistream_info map[int]struct{} + removedmultistream_info map[int]struct{} + clearedmultistream_info bool + done bool + oldValue func(context.Context) (*Playlist, error) + predicates []predicate.Playlist } var _ ent.Mutation = (*PlaylistMutation)(nil) @@ -5913,6 +6429,60 @@ func (m *PlaylistMutation) ResetVods() { m.removedvods = nil } +// AddMultistreamInfoIDs adds the "multistream_info" edge to the MultistreamInfo entity by ids. +func (m *PlaylistMutation) AddMultistreamInfoIDs(ids ...int) { + if m.multistream_info == nil { + m.multistream_info = make(map[int]struct{}) + } + for i := range ids { + m.multistream_info[ids[i]] = struct{}{} + } +} + +// ClearMultistreamInfo clears the "multistream_info" edge to the MultistreamInfo entity. +func (m *PlaylistMutation) ClearMultistreamInfo() { + m.clearedmultistream_info = true +} + +// MultistreamInfoCleared reports if the "multistream_info" edge to the MultistreamInfo entity was cleared. +func (m *PlaylistMutation) MultistreamInfoCleared() bool { + return m.clearedmultistream_info +} + +// RemoveMultistreamInfoIDs removes the "multistream_info" edge to the MultistreamInfo entity by IDs. +func (m *PlaylistMutation) RemoveMultistreamInfoIDs(ids ...int) { + if m.removedmultistream_info == nil { + m.removedmultistream_info = make(map[int]struct{}) + } + for i := range ids { + delete(m.multistream_info, ids[i]) + m.removedmultistream_info[ids[i]] = struct{}{} + } +} + +// RemovedMultistreamInfo returns the removed IDs of the "multistream_info" edge to the MultistreamInfo entity. +func (m *PlaylistMutation) RemovedMultistreamInfoIDs() (ids []int) { + for id := range m.removedmultistream_info { + ids = append(ids, id) + } + return +} + +// MultistreamInfoIDs returns the "multistream_info" edge IDs in the mutation. +func (m *PlaylistMutation) MultistreamInfoIDs() (ids []int) { + for id := range m.multistream_info { + ids = append(ids, id) + } + return +} + +// ResetMultistreamInfo resets all changes to the "multistream_info" edge. +func (m *PlaylistMutation) ResetMultistreamInfo() { + m.multistream_info = nil + m.clearedmultistream_info = false + m.removedmultistream_info = nil +} + // Where appends a list predicates to the PlaylistMutation builder. func (m *PlaylistMutation) Where(ps ...predicate.Playlist) { m.predicates = append(m.predicates, ps...) @@ -6129,10 +6699,13 @@ func (m *PlaylistMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *PlaylistMutation) AddedEdges() []string { - edges := make([]string, 0, 1) + edges := make([]string, 0, 2) if m.vods != nil { edges = append(edges, playlist.EdgeVods) } + if m.multistream_info != nil { + edges = append(edges, playlist.EdgeMultistreamInfo) + } return edges } @@ -6146,16 +6719,25 @@ func (m *PlaylistMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case playlist.EdgeMultistreamInfo: + ids := make([]ent.Value, 0, len(m.multistream_info)) + for id := range m.multistream_info { + ids = append(ids, id) + } + return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *PlaylistMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) + edges := make([]string, 0, 2) if m.removedvods != nil { edges = append(edges, playlist.EdgeVods) } + if m.removedmultistream_info != nil { + edges = append(edges, playlist.EdgeMultistreamInfo) + } return edges } @@ -6169,16 +6751,25 @@ func (m *PlaylistMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case playlist.EdgeMultistreamInfo: + ids := make([]ent.Value, 0, len(m.removedmultistream_info)) + for id := range m.removedmultistream_info { + ids = append(ids, id) + } + return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *PlaylistMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) + edges := make([]string, 0, 2) if m.clearedvods { edges = append(edges, playlist.EdgeVods) } + if m.clearedmultistream_info { + edges = append(edges, playlist.EdgeMultistreamInfo) + } return edges } @@ -6188,6 +6779,8 @@ func (m *PlaylistMutation) EdgeCleared(name string) bool { switch name { case playlist.EdgeVods: return m.clearedvods + case playlist.EdgeMultistreamInfo: + return m.clearedmultistream_info } return false } @@ -6207,6 +6800,9 @@ func (m *PlaylistMutation) ResetEdge(name string) error { case playlist.EdgeVods: m.ResetVods() return nil + case playlist.EdgeMultistreamInfo: + m.ResetMultistreamInfo() + return nil } return fmt.Errorf("unknown Playlist edge %s", name) } @@ -9447,6 +10043,9 @@ type VodMutation struct { muted_segments map[uuid.UUID]struct{} removedmuted_segments map[uuid.UUID]struct{} clearedmuted_segments bool + multistream_info map[int]struct{} + removedmultistream_info map[int]struct{} + clearedmultistream_info bool done bool oldValue func(context.Context) (*Vod, error) predicates []predicate.Vod @@ -11291,6 +11890,60 @@ func (m *VodMutation) ResetMutedSegments() { m.removedmuted_segments = nil } +// AddMultistreamInfoIDs adds the "multistream_info" edge to the MultistreamInfo entity by ids. +func (m *VodMutation) AddMultistreamInfoIDs(ids ...int) { + if m.multistream_info == nil { + m.multistream_info = make(map[int]struct{}) + } + for i := range ids { + m.multistream_info[ids[i]] = struct{}{} + } +} + +// ClearMultistreamInfo clears the "multistream_info" edge to the MultistreamInfo entity. +func (m *VodMutation) ClearMultistreamInfo() { + m.clearedmultistream_info = true +} + +// MultistreamInfoCleared reports if the "multistream_info" edge to the MultistreamInfo entity was cleared. +func (m *VodMutation) MultistreamInfoCleared() bool { + return m.clearedmultistream_info +} + +// RemoveMultistreamInfoIDs removes the "multistream_info" edge to the MultistreamInfo entity by IDs. +func (m *VodMutation) RemoveMultistreamInfoIDs(ids ...int) { + if m.removedmultistream_info == nil { + m.removedmultistream_info = make(map[int]struct{}) + } + for i := range ids { + delete(m.multistream_info, ids[i]) + m.removedmultistream_info[ids[i]] = struct{}{} + } +} + +// RemovedMultistreamInfo returns the removed IDs of the "multistream_info" edge to the MultistreamInfo entity. +func (m *VodMutation) RemovedMultistreamInfoIDs() (ids []int) { + for id := range m.removedmultistream_info { + ids = append(ids, id) + } + return +} + +// MultistreamInfoIDs returns the "multistream_info" edge IDs in the mutation. +func (m *VodMutation) MultistreamInfoIDs() (ids []int) { + for id := range m.multistream_info { + ids = append(ids, id) + } + return +} + +// ResetMultistreamInfo resets all changes to the "multistream_info" edge. +func (m *VodMutation) ResetMultistreamInfo() { + m.multistream_info = nil + m.clearedmultistream_info = false + m.removedmultistream_info = nil +} + // Where appends a list predicates to the VodMutation builder. func (m *VodMutation) Where(ps ...predicate.Vod) { m.predicates = append(m.predicates, ps...) @@ -12124,7 +12777,7 @@ func (m *VodMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *VodMutation) AddedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.channel != nil { edges = append(edges, vod.EdgeChannel) } @@ -12140,6 +12793,9 @@ func (m *VodMutation) AddedEdges() []string { if m.muted_segments != nil { edges = append(edges, vod.EdgeMutedSegments) } + if m.multistream_info != nil { + edges = append(edges, vod.EdgeMultistreamInfo) + } return edges } @@ -12173,13 +12829,19 @@ func (m *VodMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case vod.EdgeMultistreamInfo: + ids := make([]ent.Value, 0, len(m.multistream_info)) + for id := range m.multistream_info { + ids = append(ids, id) + } + return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *VodMutation) RemovedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.removedplaylists != nil { edges = append(edges, vod.EdgePlaylists) } @@ -12189,6 +12851,9 @@ func (m *VodMutation) RemovedEdges() []string { if m.removedmuted_segments != nil { edges = append(edges, vod.EdgeMutedSegments) } + if m.removedmultistream_info != nil { + edges = append(edges, vod.EdgeMultistreamInfo) + } return edges } @@ -12214,13 +12879,19 @@ func (m *VodMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case vod.EdgeMultistreamInfo: + ids := make([]ent.Value, 0, len(m.removedmultistream_info)) + for id := range m.removedmultistream_info { + ids = append(ids, id) + } + return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *VodMutation) ClearedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.clearedchannel { edges = append(edges, vod.EdgeChannel) } @@ -12236,6 +12907,9 @@ func (m *VodMutation) ClearedEdges() []string { if m.clearedmuted_segments { edges = append(edges, vod.EdgeMutedSegments) } + if m.clearedmultistream_info { + edges = append(edges, vod.EdgeMultistreamInfo) + } return edges } @@ -12253,6 +12927,8 @@ func (m *VodMutation) EdgeCleared(name string) bool { return m.clearedchapters case vod.EdgeMutedSegments: return m.clearedmuted_segments + case vod.EdgeMultistreamInfo: + return m.clearedmultistream_info } return false } @@ -12290,6 +12966,9 @@ func (m *VodMutation) ResetEdge(name string) error { case vod.EdgeMutedSegments: m.ResetMutedSegments() return nil + case vod.EdgeMultistreamInfo: + m.ResetMultistreamInfo() + return nil } return fmt.Errorf("unknown Vod edge %s", name) } diff --git a/ent/playlist.go b/ent/playlist.go index 0baa3641..e94e7456 100644 --- a/ent/playlist.go +++ b/ent/playlist.go @@ -38,9 +38,11 @@ type Playlist struct { type PlaylistEdges struct { // Vods holds the value of the vods edge. Vods []*Vod `json:"vods,omitempty"` + // MultistreamInfo holds the value of the multistream_info edge. + MultistreamInfo []*MultistreamInfo `json:"multistream_info,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool + loadedTypes [2]bool } // VodsOrErr returns the Vods value or an error if the edge @@ -52,6 +54,15 @@ func (e PlaylistEdges) VodsOrErr() ([]*Vod, error) { return nil, &NotLoadedError{edge: "vods"} } +// MultistreamInfoOrErr returns the MultistreamInfo value or an error if the edge +// was not loaded in eager-loading. +func (e PlaylistEdges) MultistreamInfoOrErr() ([]*MultistreamInfo, error) { + if e.loadedTypes[1] { + return e.MultistreamInfo, nil + } + return nil, &NotLoadedError{edge: "multistream_info"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*Playlist) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -132,6 +143,11 @@ func (pl *Playlist) QueryVods() *VodQuery { return NewPlaylistClient(pl.config).QueryVods(pl) } +// QueryMultistreamInfo queries the "multistream_info" edge of the Playlist entity. +func (pl *Playlist) QueryMultistreamInfo() *MultistreamInfoQuery { + return NewPlaylistClient(pl.config).QueryMultistreamInfo(pl) +} + // Update returns a builder for updating this Playlist. // Note that you need to call Playlist.Unwrap() before calling this method if this Playlist // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/ent/playlist/playlist.go b/ent/playlist/playlist.go index 6b64b390..28e5d454 100644 --- a/ent/playlist/playlist.go +++ b/ent/playlist/playlist.go @@ -27,6 +27,8 @@ const ( FieldCreatedAt = "created_at" // EdgeVods holds the string denoting the vods edge name in mutations. EdgeVods = "vods" + // EdgeMultistreamInfo holds the string denoting the multistream_info edge name in mutations. + EdgeMultistreamInfo = "multistream_info" // Table holds the table name of the playlist in the database. Table = "playlists" // VodsTable is the table that holds the vods relation/edge. The primary key declared below. @@ -34,6 +36,13 @@ const ( // VodsInverseTable is the table name for the Vod entity. // It exists in this package in order to avoid circular dependency with the "vod" package. VodsInverseTable = "vods" + // MultistreamInfoTable is the table that holds the multistream_info relation/edge. + MultistreamInfoTable = "multistream_infos" + // MultistreamInfoInverseTable is the table name for the MultistreamInfo entity. + // It exists in this package in order to avoid circular dependency with the "multistreaminfo" package. + MultistreamInfoInverseTable = "multistream_infos" + // MultistreamInfoColumn is the table column denoting the multistream_info relation/edge. + MultistreamInfoColumn = "playlist_multistream_info" ) // Columns holds all SQL columns for playlist fields. @@ -119,6 +128,20 @@ func ByVods(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { sqlgraph.OrderByNeighborTerms(s, newVodsStep(), append([]sql.OrderTerm{term}, terms...)...) } } + +// ByMultistreamInfoCount orders the results by multistream_info count. +func ByMultistreamInfoCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newMultistreamInfoStep(), opts...) + } +} + +// ByMultistreamInfo orders the results by multistream_info terms. +func ByMultistreamInfo(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newMultistreamInfoStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} func newVodsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -126,3 +149,10 @@ func newVodsStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.M2M, false, VodsTable, VodsPrimaryKey...), ) } +func newMultistreamInfoStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MultistreamInfoInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, MultistreamInfoTable, MultistreamInfoColumn), + ) +} diff --git a/ent/playlist/where.go b/ent/playlist/where.go index 919ea087..11ca5fc4 100644 --- a/ent/playlist/where.go +++ b/ent/playlist/where.go @@ -399,6 +399,29 @@ func HasVodsWith(preds ...predicate.Vod) predicate.Playlist { }) } +// HasMultistreamInfo applies the HasEdge predicate on the "multistream_info" edge. +func HasMultistreamInfo() predicate.Playlist { + return predicate.Playlist(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, MultistreamInfoTable, MultistreamInfoColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasMultistreamInfoWith applies the HasEdge predicate on the "multistream_info" edge with a given conditions (other predicates). +func HasMultistreamInfoWith(preds ...predicate.MultistreamInfo) predicate.Playlist { + return predicate.Playlist(func(s *sql.Selector) { + step := newMultistreamInfoStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.Playlist) predicate.Playlist { return predicate.Playlist(sql.AndPredicates(predicates...)) diff --git a/ent/playlist_create.go b/ent/playlist_create.go index 57adc33a..bd0af507 100644 --- a/ent/playlist_create.go +++ b/ent/playlist_create.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/google/uuid" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/playlist" "github.com/zibbp/ganymede/ent/vod" ) @@ -116,6 +117,21 @@ func (pc *PlaylistCreate) AddVods(v ...*Vod) *PlaylistCreate { return pc.AddVodIDs(ids...) } +// AddMultistreamInfoIDs adds the "multistream_info" edge to the MultistreamInfo entity by IDs. +func (pc *PlaylistCreate) AddMultistreamInfoIDs(ids ...int) *PlaylistCreate { + pc.mutation.AddMultistreamInfoIDs(ids...) + return pc +} + +// AddMultistreamInfo adds the "multistream_info" edges to the MultistreamInfo entity. +func (pc *PlaylistCreate) AddMultistreamInfo(m ...*MultistreamInfo) *PlaylistCreate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return pc.AddMultistreamInfoIDs(ids...) +} + // Mutation returns the PlaylistMutation object of the builder. func (pc *PlaylistCreate) Mutation() *PlaylistMutation { return pc.mutation @@ -248,6 +264,22 @@ func (pc *PlaylistCreate) createSpec() (*Playlist, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := pc.mutation.MultistreamInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: playlist.MultistreamInfoTable, + Columns: []string{playlist.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/ent/playlist_query.go b/ent/playlist_query.go index 2180479b..4bd290fe 100644 --- a/ent/playlist_query.go +++ b/ent/playlist_query.go @@ -12,6 +12,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/google/uuid" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/playlist" "github.com/zibbp/ganymede/ent/predicate" "github.com/zibbp/ganymede/ent/vod" @@ -20,11 +21,12 @@ import ( // PlaylistQuery is the builder for querying Playlist entities. type PlaylistQuery struct { config - ctx *QueryContext - order []playlist.OrderOption - inters []Interceptor - predicates []predicate.Playlist - withVods *VodQuery + ctx *QueryContext + order []playlist.OrderOption + inters []Interceptor + predicates []predicate.Playlist + withVods *VodQuery + withMultistreamInfo *MultistreamInfoQuery // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -83,6 +85,28 @@ func (pq *PlaylistQuery) QueryVods() *VodQuery { return query } +// QueryMultistreamInfo chains the current query on the "multistream_info" edge. +func (pq *PlaylistQuery) QueryMultistreamInfo() *MultistreamInfoQuery { + query := (&MultistreamInfoClient{config: pq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := pq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := pq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(playlist.Table, playlist.FieldID, selector), + sqlgraph.To(multistreaminfo.Table, multistreaminfo.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, playlist.MultistreamInfoTable, playlist.MultistreamInfoColumn), + ) + fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step) + return fromU, nil + } + return query +} + // First returns the first Playlist entity from the query. // Returns a *NotFoundError when no Playlist was found. func (pq *PlaylistQuery) First(ctx context.Context) (*Playlist, error) { @@ -270,12 +294,13 @@ func (pq *PlaylistQuery) Clone() *PlaylistQuery { return nil } return &PlaylistQuery{ - config: pq.config, - ctx: pq.ctx.Clone(), - order: append([]playlist.OrderOption{}, pq.order...), - inters: append([]Interceptor{}, pq.inters...), - predicates: append([]predicate.Playlist{}, pq.predicates...), - withVods: pq.withVods.Clone(), + config: pq.config, + ctx: pq.ctx.Clone(), + order: append([]playlist.OrderOption{}, pq.order...), + inters: append([]Interceptor{}, pq.inters...), + predicates: append([]predicate.Playlist{}, pq.predicates...), + withVods: pq.withVods.Clone(), + withMultistreamInfo: pq.withMultistreamInfo.Clone(), // clone intermediate query. sql: pq.sql.Clone(), path: pq.path, @@ -293,6 +318,17 @@ func (pq *PlaylistQuery) WithVods(opts ...func(*VodQuery)) *PlaylistQuery { return pq } +// WithMultistreamInfo tells the query-builder to eager-load the nodes that are connected to +// the "multistream_info" edge. The optional arguments are used to configure the query builder of the edge. +func (pq *PlaylistQuery) WithMultistreamInfo(opts ...func(*MultistreamInfoQuery)) *PlaylistQuery { + query := (&MultistreamInfoClient{config: pq.config}).Query() + for _, opt := range opts { + opt(query) + } + pq.withMultistreamInfo = query + return pq +} + // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // @@ -371,8 +407,9 @@ func (pq *PlaylistQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Pla var ( nodes = []*Playlist{} _spec = pq.querySpec() - loadedTypes = [1]bool{ + loadedTypes = [2]bool{ pq.withVods != nil, + pq.withMultistreamInfo != nil, } ) _spec.ScanValues = func(columns []string) ([]any, error) { @@ -400,6 +437,13 @@ func (pq *PlaylistQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Pla return nil, err } } + if query := pq.withMultistreamInfo; query != nil { + if err := pq.loadMultistreamInfo(ctx, query, nodes, + func(n *Playlist) { n.Edges.MultistreamInfo = []*MultistreamInfo{} }, + func(n *Playlist, e *MultistreamInfo) { n.Edges.MultistreamInfo = append(n.Edges.MultistreamInfo, e) }); err != nil { + return nil, err + } + } return nodes, nil } @@ -464,6 +508,37 @@ func (pq *PlaylistQuery) loadVods(ctx context.Context, query *VodQuery, nodes [] } return nil } +func (pq *PlaylistQuery) loadMultistreamInfo(ctx context.Context, query *MultistreamInfoQuery, nodes []*Playlist, init func(*Playlist), assign func(*Playlist, *MultistreamInfo)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Playlist) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + query.withFKs = true + query.Where(predicate.MultistreamInfo(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(playlist.MultistreamInfoColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.playlist_multistream_info + if fk == nil { + return fmt.Errorf(`foreign-key "playlist_multistream_info" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "playlist_multistream_info" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (pq *PlaylistQuery) sqlCount(ctx context.Context) (int, error) { _spec := pq.querySpec() diff --git a/ent/playlist_update.go b/ent/playlist_update.go index 729a1bac..aaf28726 100644 --- a/ent/playlist_update.go +++ b/ent/playlist_update.go @@ -12,6 +12,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/google/uuid" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/playlist" "github.com/zibbp/ganymede/ent/predicate" "github.com/zibbp/ganymede/ent/vod" @@ -105,6 +106,21 @@ func (pu *PlaylistUpdate) AddVods(v ...*Vod) *PlaylistUpdate { return pu.AddVodIDs(ids...) } +// AddMultistreamInfoIDs adds the "multistream_info" edge to the MultistreamInfo entity by IDs. +func (pu *PlaylistUpdate) AddMultistreamInfoIDs(ids ...int) *PlaylistUpdate { + pu.mutation.AddMultistreamInfoIDs(ids...) + return pu +} + +// AddMultistreamInfo adds the "multistream_info" edges to the MultistreamInfo entity. +func (pu *PlaylistUpdate) AddMultistreamInfo(m ...*MultistreamInfo) *PlaylistUpdate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return pu.AddMultistreamInfoIDs(ids...) +} + // Mutation returns the PlaylistMutation object of the builder. func (pu *PlaylistUpdate) Mutation() *PlaylistMutation { return pu.mutation @@ -131,6 +147,27 @@ func (pu *PlaylistUpdate) RemoveVods(v ...*Vod) *PlaylistUpdate { return pu.RemoveVodIDs(ids...) } +// ClearMultistreamInfo clears all "multistream_info" edges to the MultistreamInfo entity. +func (pu *PlaylistUpdate) ClearMultistreamInfo() *PlaylistUpdate { + pu.mutation.ClearMultistreamInfo() + return pu +} + +// RemoveMultistreamInfoIDs removes the "multistream_info" edge to MultistreamInfo entities by IDs. +func (pu *PlaylistUpdate) RemoveMultistreamInfoIDs(ids ...int) *PlaylistUpdate { + pu.mutation.RemoveMultistreamInfoIDs(ids...) + return pu +} + +// RemoveMultistreamInfo removes "multistream_info" edges to MultistreamInfo entities. +func (pu *PlaylistUpdate) RemoveMultistreamInfo(m ...*MultistreamInfo) *PlaylistUpdate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return pu.RemoveMultistreamInfoIDs(ids...) +} + // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PlaylistUpdate) Save(ctx context.Context) (int, error) { pu.defaults() @@ -239,6 +276,51 @@ func (pu *PlaylistUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if pu.mutation.MultistreamInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: playlist.MultistreamInfoTable, + Columns: []string{playlist.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := pu.mutation.RemovedMultistreamInfoIDs(); len(nodes) > 0 && !pu.mutation.MultistreamInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: playlist.MultistreamInfoTable, + Columns: []string{playlist.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := pu.mutation.MultistreamInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: playlist.MultistreamInfoTable, + Columns: []string{playlist.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{playlist.Label} @@ -334,6 +416,21 @@ func (puo *PlaylistUpdateOne) AddVods(v ...*Vod) *PlaylistUpdateOne { return puo.AddVodIDs(ids...) } +// AddMultistreamInfoIDs adds the "multistream_info" edge to the MultistreamInfo entity by IDs. +func (puo *PlaylistUpdateOne) AddMultistreamInfoIDs(ids ...int) *PlaylistUpdateOne { + puo.mutation.AddMultistreamInfoIDs(ids...) + return puo +} + +// AddMultistreamInfo adds the "multistream_info" edges to the MultistreamInfo entity. +func (puo *PlaylistUpdateOne) AddMultistreamInfo(m ...*MultistreamInfo) *PlaylistUpdateOne { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return puo.AddMultistreamInfoIDs(ids...) +} + // Mutation returns the PlaylistMutation object of the builder. func (puo *PlaylistUpdateOne) Mutation() *PlaylistMutation { return puo.mutation @@ -360,6 +457,27 @@ func (puo *PlaylistUpdateOne) RemoveVods(v ...*Vod) *PlaylistUpdateOne { return puo.RemoveVodIDs(ids...) } +// ClearMultistreamInfo clears all "multistream_info" edges to the MultistreamInfo entity. +func (puo *PlaylistUpdateOne) ClearMultistreamInfo() *PlaylistUpdateOne { + puo.mutation.ClearMultistreamInfo() + return puo +} + +// RemoveMultistreamInfoIDs removes the "multistream_info" edge to MultistreamInfo entities by IDs. +func (puo *PlaylistUpdateOne) RemoveMultistreamInfoIDs(ids ...int) *PlaylistUpdateOne { + puo.mutation.RemoveMultistreamInfoIDs(ids...) + return puo +} + +// RemoveMultistreamInfo removes "multistream_info" edges to MultistreamInfo entities. +func (puo *PlaylistUpdateOne) RemoveMultistreamInfo(m ...*MultistreamInfo) *PlaylistUpdateOne { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return puo.RemoveMultistreamInfoIDs(ids...) +} + // Where appends a list predicates to the PlaylistUpdate builder. func (puo *PlaylistUpdateOne) Where(ps ...predicate.Playlist) *PlaylistUpdateOne { puo.mutation.Where(ps...) @@ -498,6 +616,51 @@ func (puo *PlaylistUpdateOne) sqlSave(ctx context.Context) (_node *Playlist, err } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if puo.mutation.MultistreamInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: playlist.MultistreamInfoTable, + Columns: []string{playlist.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := puo.mutation.RemovedMultistreamInfoIDs(); len(nodes) > 0 && !puo.mutation.MultistreamInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: playlist.MultistreamInfoTable, + Columns: []string{playlist.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := puo.mutation.MultistreamInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: playlist.MultistreamInfoTable, + Columns: []string{playlist.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _node = &Playlist{config: puo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go index 88af71e5..ecf937f3 100644 --- a/ent/predicate/predicate.go +++ b/ent/predicate/predicate.go @@ -24,6 +24,9 @@ type LiveCategory func(*sql.Selector) // LiveTitleRegex is the predicate function for livetitleregex builders. type LiveTitleRegex func(*sql.Selector) +// MultistreamInfo is the predicate function for multistreaminfo builders. +type MultistreamInfo func(*sql.Selector) + // MutedSegment is the predicate function for mutedsegment builders. type MutedSegment func(*sql.Selector) diff --git a/ent/schema/multistreaminfo.go b/ent/schema/multistreaminfo.go new file mode 100644 index 00000000..d36f40e8 --- /dev/null +++ b/ent/schema/multistreaminfo.go @@ -0,0 +1,27 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" +) + +// MultistreamInfo holds the schema definition for the MultistreamInfo entity. +type MultistreamInfo struct { + ent.Schema +} + +// Fields of the MultistreamInfo. +func (MultistreamInfo) Fields() []ent.Field { + return []ent.Field{ + field.Int("delay_ms").Optional(), + } +} + +// Edges of the MultistreamInfo. +func (MultistreamInfo) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("vod", Vod.Type).Immutable().Unique().Required(), + edge.From("playlist", Playlist.Type).Ref("multistream_info").Unique().Required(), + } +} diff --git a/ent/schema/playlist.go b/ent/schema/playlist.go index 87199473..e8a9c4ac 100644 --- a/ent/schema/playlist.go +++ b/ent/schema/playlist.go @@ -1,11 +1,12 @@ package schema import ( + "time" + "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "github.com/google/uuid" - "time" ) // Playlist holds the schema definition for the Playlist entity. @@ -29,5 +30,6 @@ func (Playlist) Fields() []ent.Field { func (Playlist) Edges() []ent.Edge { return []ent.Edge{ edge.To("vods", Vod.Type), + edge.To("multistream_info", MultistreamInfo.Type), } } diff --git a/ent/schema/vod.go b/ent/schema/vod.go index 1bda4172..34fbe4be 100644 --- a/ent/schema/vod.go +++ b/ent/schema/vod.go @@ -63,5 +63,6 @@ func (Vod) Edges() []ent.Edge { edge.From("playlists", Playlist.Type).Ref("vods"), edge.To("chapters", Chapter.Type), edge.To("muted_segments", MutedSegment.Type), + edge.From("multistream_info", MultistreamInfo.Type).Ref("vod"), } } diff --git a/ent/tx.go b/ent/tx.go index 92e4abb1..0456ac0d 100644 --- a/ent/tx.go +++ b/ent/tx.go @@ -24,6 +24,8 @@ type Tx struct { LiveCategory *LiveCategoryClient // LiveTitleRegex is the client for interacting with the LiveTitleRegex builders. LiveTitleRegex *LiveTitleRegexClient + // MultistreamInfo is the client for interacting with the MultistreamInfo builders. + MultistreamInfo *MultistreamInfoClient // MutedSegment is the client for interacting with the MutedSegment builders. MutedSegment *MutedSegmentClient // Playback is the client for interacting with the Playback builders. @@ -175,6 +177,7 @@ func (tx *Tx) init() { tx.Live = NewLiveClient(tx.config) tx.LiveCategory = NewLiveCategoryClient(tx.config) tx.LiveTitleRegex = NewLiveTitleRegexClient(tx.config) + tx.MultistreamInfo = NewMultistreamInfoClient(tx.config) tx.MutedSegment = NewMutedSegmentClient(tx.config) tx.Playback = NewPlaybackClient(tx.config) tx.Playlist = NewPlaylistClient(tx.config) diff --git a/ent/vod.go b/ent/vod.go index 374c3315..34acb2de 100644 --- a/ent/vod.go +++ b/ent/vod.go @@ -106,9 +106,11 @@ type VodEdges struct { Chapters []*Chapter `json:"chapters,omitempty"` // MutedSegments holds the value of the muted_segments edge. MutedSegments []*MutedSegment `json:"muted_segments,omitempty"` + // MultistreamInfo holds the value of the multistream_info edge. + MultistreamInfo []*MultistreamInfo `json:"multistream_info,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [5]bool + loadedTypes [6]bool } // ChannelOrErr returns the Channel value or an error if the edge @@ -160,6 +162,15 @@ func (e VodEdges) MutedSegmentsOrErr() ([]*MutedSegment, error) { return nil, &NotLoadedError{edge: "muted_segments"} } +// MultistreamInfoOrErr returns the MultistreamInfo value or an error if the edge +// was not loaded in eager-loading. +func (e VodEdges) MultistreamInfoOrErr() ([]*MultistreamInfo, error) { + if e.loadedTypes[5] { + return e.MultistreamInfo, nil + } + return nil, &NotLoadedError{edge: "multistream_info"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*Vod) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -441,6 +452,11 @@ func (v *Vod) QueryMutedSegments() *MutedSegmentQuery { return NewVodClient(v.config).QueryMutedSegments(v) } +// QueryMultistreamInfo queries the "multistream_info" edge of the Vod entity. +func (v *Vod) QueryMultistreamInfo() *MultistreamInfoQuery { + return NewVodClient(v.config).QueryMultistreamInfo(v) +} + // Update returns a builder for updating this Vod. // Note that you need to call Vod.Unwrap() before calling this method if this Vod // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/ent/vod/vod.go b/ent/vod/vod.go index b5cf18c4..a6684544 100644 --- a/ent/vod/vod.go +++ b/ent/vod/vod.go @@ -93,6 +93,8 @@ const ( EdgeChapters = "chapters" // EdgeMutedSegments holds the string denoting the muted_segments edge name in mutations. EdgeMutedSegments = "muted_segments" + // EdgeMultistreamInfo holds the string denoting the multistream_info edge name in mutations. + EdgeMultistreamInfo = "multistream_info" // Table holds the table name of the vod in the database. Table = "vods" // ChannelTable is the table that holds the channel relation/edge. @@ -128,6 +130,13 @@ const ( MutedSegmentsInverseTable = "muted_segments" // MutedSegmentsColumn is the table column denoting the muted_segments relation/edge. MutedSegmentsColumn = "vod_muted_segments" + // MultistreamInfoTable is the table that holds the multistream_info relation/edge. + MultistreamInfoTable = "multistream_infos" + // MultistreamInfoInverseTable is the table name for the MultistreamInfo entity. + // It exists in this package in order to avoid circular dependency with the "multistreaminfo" package. + MultistreamInfoInverseTable = "multistream_infos" + // MultistreamInfoColumn is the table column denoting the multistream_info relation/edge. + MultistreamInfoColumn = "multistream_info_vod" ) // Columns holds all SQL columns for vod fields. @@ -470,6 +479,20 @@ func ByMutedSegments(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { sqlgraph.OrderByNeighborTerms(s, newMutedSegmentsStep(), append([]sql.OrderTerm{term}, terms...)...) } } + +// ByMultistreamInfoCount orders the results by multistream_info count. +func ByMultistreamInfoCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newMultistreamInfoStep(), opts...) + } +} + +// ByMultistreamInfo orders the results by multistream_info terms. +func ByMultistreamInfo(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newMultistreamInfoStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} func newChannelStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -505,3 +528,10 @@ func newMutedSegmentsStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, MutedSegmentsTable, MutedSegmentsColumn), ) } +func newMultistreamInfoStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MultistreamInfoInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, MultistreamInfoTable, MultistreamInfoColumn), + ) +} diff --git a/ent/vod/where.go b/ent/vod/where.go index c30dd718..eacad8f1 100644 --- a/ent/vod/where.go +++ b/ent/vod/where.go @@ -2332,6 +2332,29 @@ func HasMutedSegmentsWith(preds ...predicate.MutedSegment) predicate.Vod { }) } +// HasMultistreamInfo applies the HasEdge predicate on the "multistream_info" edge. +func HasMultistreamInfo() predicate.Vod { + return predicate.Vod(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, MultistreamInfoTable, MultistreamInfoColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasMultistreamInfoWith applies the HasEdge predicate on the "multistream_info" edge with a given conditions (other predicates). +func HasMultistreamInfoWith(preds ...predicate.MultistreamInfo) predicate.Vod { + return predicate.Vod(func(s *sql.Selector) { + step := newMultistreamInfoStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.Vod) predicate.Vod { return predicate.Vod(sql.AndPredicates(predicates...)) diff --git a/ent/vod_create.go b/ent/vod_create.go index 69337b29..b7638eaf 100644 --- a/ent/vod_create.go +++ b/ent/vod_create.go @@ -15,6 +15,7 @@ import ( "github.com/google/uuid" "github.com/zibbp/ganymede/ent/channel" "github.com/zibbp/ganymede/ent/chapter" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/mutedsegment" "github.com/zibbp/ganymede/ent/playlist" "github.com/zibbp/ganymede/ent/queue" @@ -549,6 +550,21 @@ func (vc *VodCreate) AddMutedSegments(m ...*MutedSegment) *VodCreate { return vc.AddMutedSegmentIDs(ids...) } +// AddMultistreamInfoIDs adds the "multistream_info" edge to the MultistreamInfo entity by IDs. +func (vc *VodCreate) AddMultistreamInfoIDs(ids ...int) *VodCreate { + vc.mutation.AddMultistreamInfoIDs(ids...) + return vc +} + +// AddMultistreamInfo adds the "multistream_info" edges to the MultistreamInfo entity. +func (vc *VodCreate) AddMultistreamInfo(m ...*MultistreamInfo) *VodCreate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return vc.AddMultistreamInfoIDs(ids...) +} + // Mutation returns the VodMutation object of the builder. func (vc *VodCreate) Mutation() *VodMutation { return vc.mutation @@ -936,6 +952,22 @@ func (vc *VodCreate) createSpec() (*Vod, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := vc.mutation.MultistreamInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: vod.MultistreamInfoTable, + Columns: []string{vod.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/ent/vod_query.go b/ent/vod_query.go index fd039f6b..0fbc609a 100644 --- a/ent/vod_query.go +++ b/ent/vod_query.go @@ -14,6 +14,7 @@ import ( "github.com/google/uuid" "github.com/zibbp/ganymede/ent/channel" "github.com/zibbp/ganymede/ent/chapter" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/mutedsegment" "github.com/zibbp/ganymede/ent/playlist" "github.com/zibbp/ganymede/ent/predicate" @@ -24,16 +25,17 @@ import ( // VodQuery is the builder for querying Vod entities. type VodQuery struct { config - ctx *QueryContext - order []vod.OrderOption - inters []Interceptor - predicates []predicate.Vod - withChannel *ChannelQuery - withQueue *QueueQuery - withPlaylists *PlaylistQuery - withChapters *ChapterQuery - withMutedSegments *MutedSegmentQuery - withFKs bool + ctx *QueryContext + order []vod.OrderOption + inters []Interceptor + predicates []predicate.Vod + withChannel *ChannelQuery + withQueue *QueueQuery + withPlaylists *PlaylistQuery + withChapters *ChapterQuery + withMutedSegments *MutedSegmentQuery + withMultistreamInfo *MultistreamInfoQuery + withFKs bool // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -180,6 +182,28 @@ func (vq *VodQuery) QueryMutedSegments() *MutedSegmentQuery { return query } +// QueryMultistreamInfo chains the current query on the "multistream_info" edge. +func (vq *VodQuery) QueryMultistreamInfo() *MultistreamInfoQuery { + query := (&MultistreamInfoClient{config: vq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := vq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := vq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(vod.Table, vod.FieldID, selector), + sqlgraph.To(multistreaminfo.Table, multistreaminfo.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, vod.MultistreamInfoTable, vod.MultistreamInfoColumn), + ) + fromU = sqlgraph.SetNeighbors(vq.driver.Dialect(), step) + return fromU, nil + } + return query +} + // First returns the first Vod entity from the query. // Returns a *NotFoundError when no Vod was found. func (vq *VodQuery) First(ctx context.Context) (*Vod, error) { @@ -367,16 +391,17 @@ func (vq *VodQuery) Clone() *VodQuery { return nil } return &VodQuery{ - config: vq.config, - ctx: vq.ctx.Clone(), - order: append([]vod.OrderOption{}, vq.order...), - inters: append([]Interceptor{}, vq.inters...), - predicates: append([]predicate.Vod{}, vq.predicates...), - withChannel: vq.withChannel.Clone(), - withQueue: vq.withQueue.Clone(), - withPlaylists: vq.withPlaylists.Clone(), - withChapters: vq.withChapters.Clone(), - withMutedSegments: vq.withMutedSegments.Clone(), + config: vq.config, + ctx: vq.ctx.Clone(), + order: append([]vod.OrderOption{}, vq.order...), + inters: append([]Interceptor{}, vq.inters...), + predicates: append([]predicate.Vod{}, vq.predicates...), + withChannel: vq.withChannel.Clone(), + withQueue: vq.withQueue.Clone(), + withPlaylists: vq.withPlaylists.Clone(), + withChapters: vq.withChapters.Clone(), + withMutedSegments: vq.withMutedSegments.Clone(), + withMultistreamInfo: vq.withMultistreamInfo.Clone(), // clone intermediate query. sql: vq.sql.Clone(), path: vq.path, @@ -438,6 +463,17 @@ func (vq *VodQuery) WithMutedSegments(opts ...func(*MutedSegmentQuery)) *VodQuer return vq } +// WithMultistreamInfo tells the query-builder to eager-load the nodes that are connected to +// the "multistream_info" edge. The optional arguments are used to configure the query builder of the edge. +func (vq *VodQuery) WithMultistreamInfo(opts ...func(*MultistreamInfoQuery)) *VodQuery { + query := (&MultistreamInfoClient{config: vq.config}).Query() + for _, opt := range opts { + opt(query) + } + vq.withMultistreamInfo = query + return vq +} + // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // @@ -517,12 +553,13 @@ func (vq *VodQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Vod, err nodes = []*Vod{} withFKs = vq.withFKs _spec = vq.querySpec() - loadedTypes = [5]bool{ + loadedTypes = [6]bool{ vq.withChannel != nil, vq.withQueue != nil, vq.withPlaylists != nil, vq.withChapters != nil, vq.withMutedSegments != nil, + vq.withMultistreamInfo != nil, } ) if vq.withChannel != nil { @@ -582,6 +619,13 @@ func (vq *VodQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Vod, err return nil, err } } + if query := vq.withMultistreamInfo; query != nil { + if err := vq.loadMultistreamInfo(ctx, query, nodes, + func(n *Vod) { n.Edges.MultistreamInfo = []*MultistreamInfo{} }, + func(n *Vod, e *MultistreamInfo) { n.Edges.MultistreamInfo = append(n.Edges.MultistreamInfo, e) }); err != nil { + return nil, err + } + } return nodes, nil } @@ -768,6 +812,37 @@ func (vq *VodQuery) loadMutedSegments(ctx context.Context, query *MutedSegmentQu } return nil } +func (vq *VodQuery) loadMultistreamInfo(ctx context.Context, query *MultistreamInfoQuery, nodes []*Vod, init func(*Vod), assign func(*Vod, *MultistreamInfo)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Vod) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + query.withFKs = true + query.Where(predicate.MultistreamInfo(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(vod.MultistreamInfoColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.multistream_info_vod + if fk == nil { + return fmt.Errorf(`foreign-key "multistream_info_vod" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "multistream_info_vod" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (vq *VodQuery) sqlCount(ctx context.Context) (int, error) { _spec := vq.querySpec() diff --git a/ent/vod_update.go b/ent/vod_update.go index 7bf5c4c2..ff1fb588 100644 --- a/ent/vod_update.go +++ b/ent/vod_update.go @@ -14,6 +14,7 @@ import ( "github.com/google/uuid" "github.com/zibbp/ganymede/ent/channel" "github.com/zibbp/ganymede/ent/chapter" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/mutedsegment" "github.com/zibbp/ganymede/ent/playlist" "github.com/zibbp/ganymede/ent/predicate" @@ -685,6 +686,21 @@ func (vu *VodUpdate) AddMutedSegments(m ...*MutedSegment) *VodUpdate { return vu.AddMutedSegmentIDs(ids...) } +// AddMultistreamInfoIDs adds the "multistream_info" edge to the MultistreamInfo entity by IDs. +func (vu *VodUpdate) AddMultistreamInfoIDs(ids ...int) *VodUpdate { + vu.mutation.AddMultistreamInfoIDs(ids...) + return vu +} + +// AddMultistreamInfo adds the "multistream_info" edges to the MultistreamInfo entity. +func (vu *VodUpdate) AddMultistreamInfo(m ...*MultistreamInfo) *VodUpdate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return vu.AddMultistreamInfoIDs(ids...) +} + // Mutation returns the VodMutation object of the builder. func (vu *VodUpdate) Mutation() *VodMutation { return vu.mutation @@ -765,6 +781,27 @@ func (vu *VodUpdate) RemoveMutedSegments(m ...*MutedSegment) *VodUpdate { return vu.RemoveMutedSegmentIDs(ids...) } +// ClearMultistreamInfo clears all "multistream_info" edges to the MultistreamInfo entity. +func (vu *VodUpdate) ClearMultistreamInfo() *VodUpdate { + vu.mutation.ClearMultistreamInfo() + return vu +} + +// RemoveMultistreamInfoIDs removes the "multistream_info" edge to MultistreamInfo entities by IDs. +func (vu *VodUpdate) RemoveMultistreamInfoIDs(ids ...int) *VodUpdate { + vu.mutation.RemoveMultistreamInfoIDs(ids...) + return vu +} + +// RemoveMultistreamInfo removes "multistream_info" edges to MultistreamInfo entities. +func (vu *VodUpdate) RemoveMultistreamInfo(m ...*MultistreamInfo) *VodUpdate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return vu.RemoveMultistreamInfoIDs(ids...) +} + // Save executes the query and returns the number of nodes affected by the update operation. func (vu *VodUpdate) Save(ctx context.Context) (int, error) { vu.defaults() @@ -1186,6 +1223,51 @@ func (vu *VodUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if vu.mutation.MultistreamInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: vod.MultistreamInfoTable, + Columns: []string{vod.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := vu.mutation.RemovedMultistreamInfoIDs(); len(nodes) > 0 && !vu.mutation.MultistreamInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: vod.MultistreamInfoTable, + Columns: []string{vod.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := vu.mutation.MultistreamInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: vod.MultistreamInfoTable, + Columns: []string{vod.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if n, err = sqlgraph.UpdateNodes(ctx, vu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{vod.Label} @@ -1856,6 +1938,21 @@ func (vuo *VodUpdateOne) AddMutedSegments(m ...*MutedSegment) *VodUpdateOne { return vuo.AddMutedSegmentIDs(ids...) } +// AddMultistreamInfoIDs adds the "multistream_info" edge to the MultistreamInfo entity by IDs. +func (vuo *VodUpdateOne) AddMultistreamInfoIDs(ids ...int) *VodUpdateOne { + vuo.mutation.AddMultistreamInfoIDs(ids...) + return vuo +} + +// AddMultistreamInfo adds the "multistream_info" edges to the MultistreamInfo entity. +func (vuo *VodUpdateOne) AddMultistreamInfo(m ...*MultistreamInfo) *VodUpdateOne { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return vuo.AddMultistreamInfoIDs(ids...) +} + // Mutation returns the VodMutation object of the builder. func (vuo *VodUpdateOne) Mutation() *VodMutation { return vuo.mutation @@ -1936,6 +2033,27 @@ func (vuo *VodUpdateOne) RemoveMutedSegments(m ...*MutedSegment) *VodUpdateOne { return vuo.RemoveMutedSegmentIDs(ids...) } +// ClearMultistreamInfo clears all "multistream_info" edges to the MultistreamInfo entity. +func (vuo *VodUpdateOne) ClearMultistreamInfo() *VodUpdateOne { + vuo.mutation.ClearMultistreamInfo() + return vuo +} + +// RemoveMultistreamInfoIDs removes the "multistream_info" edge to MultistreamInfo entities by IDs. +func (vuo *VodUpdateOne) RemoveMultistreamInfoIDs(ids ...int) *VodUpdateOne { + vuo.mutation.RemoveMultistreamInfoIDs(ids...) + return vuo +} + +// RemoveMultistreamInfo removes "multistream_info" edges to MultistreamInfo entities. +func (vuo *VodUpdateOne) RemoveMultistreamInfo(m ...*MultistreamInfo) *VodUpdateOne { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return vuo.RemoveMultistreamInfoIDs(ids...) +} + // Where appends a list predicates to the VodUpdate builder. func (vuo *VodUpdateOne) Where(ps ...predicate.Vod) *VodUpdateOne { vuo.mutation.Where(ps...) @@ -2387,6 +2505,51 @@ func (vuo *VodUpdateOne) sqlSave(ctx context.Context) (_node *Vod, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if vuo.mutation.MultistreamInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: vod.MultistreamInfoTable, + Columns: []string{vod.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := vuo.mutation.RemovedMultistreamInfoIDs(); len(nodes) > 0 && !vuo.mutation.MultistreamInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: vod.MultistreamInfoTable, + Columns: []string{vod.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := vuo.mutation.MultistreamInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: vod.MultistreamInfoTable, + Columns: []string{vod.MultistreamInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(multistreaminfo.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _node = &Vod{config: vuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/go.sum b/go.sum index 5b8c18a1..22c787c9 100644 --- a/go.sum +++ b/go.sum @@ -157,6 +157,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= @@ -175,6 +177,8 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= @@ -228,6 +232,10 @@ github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= diff --git a/internal/playlist/playlist.go b/internal/playlist/playlist.go index 82623e05..a3e390e2 100644 --- a/internal/playlist/playlist.go +++ b/internal/playlist/playlist.go @@ -7,7 +7,9 @@ import ( "github.com/google/uuid" "github.com/labstack/echo/v4" "github.com/zibbp/ganymede/ent" + "github.com/zibbp/ganymede/ent/multistreaminfo" "github.com/zibbp/ganymede/ent/playlist" + "github.com/zibbp/ganymede/ent/vod" "github.com/zibbp/ganymede/internal/database" ) @@ -66,10 +68,14 @@ func (s *Service) GetPlaylists(c echo.Context) ([]*ent.Playlist, error) { return playlists, nil } -func (s *Service) GetPlaylist(c echo.Context, playlistID uuid.UUID) (*ent.Playlist, error) { - rPlaylist, err := s.Store.Client.Playlist.Query().Where(playlist.ID(playlistID)).WithVods(func(q *ent.VodQuery) { +func (s *Service) GetPlaylist(c echo.Context, playlistID uuid.UUID, withMultistreamInfo bool) (*ent.Playlist, error) { + playlistQuery := s.Store.Client.Playlist.Query().Where(playlist.ID(playlistID)).WithVods(func(q *ent.VodQuery) { q.WithChannel() - }).Order(ent.Desc(playlist.FieldCreatedAt)).Only(c.Request().Context()) + }) + if withMultistreamInfo { + playlistQuery.WithMultistreamInfo(func(miq *ent.MultistreamInfoQuery) { miq.WithVod() }) + } + rPlaylist, err := playlistQuery.Order(ent.Desc(playlist.FieldCreatedAt)).Only(c.Request().Context()) // Order VODs by date streamed tmpVods := rPlaylist.Edges.Vods sort.Slice(tmpVods, func(i, j int) bool { @@ -124,3 +130,62 @@ func (s *Service) DeleteVodFromPlaylist(c echo.Context, playlistID uuid.UUID, vo return nil } + +func (s *Service) SetVodDelayOnPlaylist(c echo.Context, playlistID uuid.UUID, vodID uuid.UUID, delayMs int) error { + dbPlaylist, err := s.Store.Client.Playlist.Query().Where(playlist.ID(playlistID)).WithVods().Only(c.Request().Context()) + if err != nil { + return fmt.Errorf("playlist not found") + } + + // If one day, we need to store more than just the delay, we should remove the deletion here + if delayMs == 0 { + return s.deleteMultistreamInfo(c, playlistID, vodID) + } + + // Check if vod exists in playlist before creating new data + found := false + for _, vod := range dbPlaylist.Edges.Vods { + if vod.ID == vodID { + found = true + break + } + } + if !found { + return fmt.Errorf("vod not found in playlist") + } + + dbMultistreamInfo, err := s.Store.Client.MultistreamInfo.Query().Where( + multistreaminfo.And( + multistreaminfo.HasPlaylistWith(playlist.ID(playlistID)), + multistreaminfo.HasVodWith(vod.ID(vodID)), + ), + ).Only(c.Request().Context()) + + if err != nil && ent.IsNotFound(err) { + _, err = s.Store.Client.MultistreamInfo.Create().SetDelayMs(delayMs).SetPlaylistID(playlistID).SetVodID(vodID).Save(c.Request().Context()) + if err != nil { + return fmt.Errorf("error creating multistream info: %v", err) + } + } else { + _, err = s.Store.Client.MultistreamInfo.UpdateOne(dbMultistreamInfo).SetDelayMs(delayMs).Save(c.Request().Context()) + if err != nil { + return fmt.Errorf("error updating multistream info: %v", err) + } + } + + return nil +} + +func (s *Service) deleteMultistreamInfo(c echo.Context, playlistID uuid.UUID, vodID uuid.UUID) error { + _, err := s.Store.Client.MultistreamInfo.Delete().Where( + multistreaminfo.And( + multistreaminfo.HasPlaylistWith(playlist.ID(playlistID)), + multistreaminfo.HasVodWith(vod.ID(vodID)), + ), + ).Exec(c.Request().Context()) + + if err != nil { + return fmt.Errorf("error deleting multistream info: %v", err) + } + return nil +} diff --git a/internal/transport/http/handler.go b/internal/transport/http/handler.go index 9e1dd557..9f50ce1e 100644 --- a/internal/transport/http/handler.go +++ b/internal/transport/http/handler.go @@ -246,6 +246,7 @@ func groupV1Routes(e *echo.Group, h *Handler) { playlistGroup.POST("/:id", h.AddVodToPlaylist, auth.GuardMiddleware, auth.GetUserMiddleware, auth.UserRoleMiddleware(utils.EditorRole)) playlistGroup.DELETE("/:id/vod", h.DeleteVodFromPlaylist, auth.GuardMiddleware, auth.GetUserMiddleware, auth.UserRoleMiddleware(utils.EditorRole)) playlistGroup.DELETE("/:id", h.DeletePlaylist, auth.GuardMiddleware, auth.GetUserMiddleware, auth.UserRoleMiddleware(utils.EditorRole)) + playlistGroup.PUT("/:id/multistream/delay", h.SetVodDelayOnPlaylistMultistream, auth.GuardMiddleware, auth.GetUserMiddleware, auth.UserRoleMiddleware(utils.EditorRole)) playlistGroup.PUT("/:id", h.UpdatePlaylist, auth.GuardMiddleware, auth.GetUserMiddleware, auth.UserRoleMiddleware(utils.EditorRole)) // Exec diff --git a/internal/transport/http/playlist.go b/internal/transport/http/playlist.go index f3ff319c..ca38ddb5 100644 --- a/internal/transport/http/playlist.go +++ b/internal/transport/http/playlist.go @@ -13,8 +13,9 @@ type PlaylistService interface { CreatePlaylist(c echo.Context, playlistDto playlist.Playlist) (*ent.Playlist, error) AddVodToPlaylist(c echo.Context, playlistID uuid.UUID, vodID uuid.UUID) error GetPlaylists(c echo.Context) ([]*ent.Playlist, error) - GetPlaylist(c echo.Context, playlistID uuid.UUID) (*ent.Playlist, error) + GetPlaylist(c echo.Context, playlistID uuid.UUID, withMultistreamInfo bool) (*ent.Playlist, error) UpdatePlaylist(c echo.Context, playlistID uuid.UUID, playlistDto playlist.Playlist) (*ent.Playlist, error) + SetVodDelayOnPlaylist(c echo.Context, playlistID uuid.UUID, vodId uuid.UUID, delayMs int) error DeletePlaylist(c echo.Context, playlistID uuid.UUID) error DeleteVodFromPlaylist(c echo.Context, playlistID uuid.UUID, vodID uuid.UUID) error } @@ -28,6 +29,11 @@ type AddVodToPlaylistRequest struct { VodID string `json:"vod_id" validate:"required"` } +type SetVodDelayPlaylistRequest struct { + VodID string `json:"vod_id" validate:"required"` + DelayMs int `json:"delay_ms"` +} + // CreatePlaylist godoc // // @Summary Create playlist @@ -123,17 +129,18 @@ func (h *Handler) GetPlaylists(c echo.Context) error { // @Tags Playlist // @Accept json // @Produce json -// @Param id path string true "playlist id" -// @Success 200 {object} ent.Playlist -// @Failure 400 {object} utils.ErrorResponse -// @Failure 500 {object} utils.ErrorResponse +// @Param id path string true "playlist id" +// @Param with_multistream_info query boolean false "include multistream info" +// @Success 200 {object} ent.Playlist +// @Failure 400 {object} utils.ErrorResponse +// @Failure 500 {object} utils.ErrorResponse // @Router /playlist/{id} [get] func (h *Handler) GetPlaylist(c echo.Context) error { pID, err := uuid.Parse(c.Param("id")) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, "invalid playlist id") } - rPlaylist, err := h.Service.PlaylistService.GetPlaylist(c, pID) + rPlaylist, err := h.Service.PlaylistService.GetPlaylist(c, pID, c.QueryParams().Get("with_multistream_info") == "true") if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) } @@ -177,6 +184,43 @@ func (h *Handler) UpdatePlaylist(c echo.Context) error { return c.JSON(http.StatusOK, updatedPlaylist) } +// SetVodDelayOnPlaylistMultistream godoc +// +// @Summary Set delay of vod in playlist for multistream +// @Description Set delay of vod in playlist for multistream +// @Tags Playlist +// @Accept json +// @Produce json +// @Param id path string true "playlist id" +// @Param delay body SetVodDelayPlaylistRequest true "delay" +// @Success 200 {object} string +// @Failure 400 {object} utils.ErrorResponse +// @Failure 500 {object} utils.ErrorResponse +// @Router /playlist/{id} [put] +// @Security ApiKeyCookieAuth +func (h *Handler) SetVodDelayOnPlaylistMultistream(c echo.Context) error { + pID, err := uuid.Parse(c.Param("id")) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, "invalid playlist id") + } + svdpr := new(SetVodDelayPlaylistRequest) + if err := c.Bind(svdpr); err != nil { + return echo.NewHTTPError(http.StatusBadRequest, err.Error()) + } + if err := c.Validate(svdpr); err != nil { + return echo.NewHTTPError(http.StatusBadRequest, err.Error()) + } + vID, err := uuid.Parse(svdpr.VodID) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, "invalid vod id") + } + err = h.Service.PlaylistService.SetVodDelayOnPlaylist(c, pID, vID, svdpr.DelayMs) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + } + return c.JSON(http.StatusOK, "ok") +} + // DeletePlaylist godoc // // @Summary Delete playlist