// Code generated by gowebx, DO AVOID EDIT. package proxy import ( "context" "log/slog" "github.com/gowvp/gb28181/internal/core/bz" "github.com/ixugo/goweb/pkg/orm" "github.com/ixugo/goweb/pkg/web" "github.com/jinzhu/copier" ) // StreamProxyStorer Instantiation interface type StreamProxyStorer interface { Find(context.Context, *[]*StreamProxy, orm.Pager, ...orm.QueryOption) (int64, error) Get(context.Context, *StreamProxy, ...orm.QueryOption) error Add(context.Context, *StreamProxy) error Edit(context.Context, *StreamProxy, func(*StreamProxy), ...orm.QueryOption) error Del(context.Context, *StreamProxy, ...orm.QueryOption) error } // FindStreamProxy Paginated search func (c *Core) FindStreamProxy(ctx context.Context, in *FindStreamProxyInput) ([]*StreamProxy, int64, error) { items := make([]*StreamProxy, 0) total, err := c.store.StreamProxy().Find(ctx, &items, in) if err != nil { return nil, 0, web.ErrDB.Withf(`Find err[%s]`, err.Error()) } return items, total, nil } // GetStreamProxy Query a single object func (c *Core) GetStreamProxy(ctx context.Context, id string) (*StreamProxy, error) { var out StreamProxy if err := c.store.StreamProxy().Get(ctx, &out, orm.Where("id=?", id)); err != nil { if orm.IsErrRecordNotFound(err) { return nil, web.ErrNotFound.Withf(`Get err[%s]`, err.Error()) } return nil, web.ErrDB.Withf(`Get err[%s]`, err.Error()) } return &out, nil } // AddStreamProxy Insert into database func (c *Core) AddStreamProxy(ctx context.Context, in *AddStreamProxyInput) (*StreamProxy, error) { var out StreamProxy if err := copier.Copy(&out, in); err != nil { slog.Error("Copy", "err", err) } out.ID = c.uniqueID.UniqueID(bz.IDPrefixRTSP) if err := c.store.StreamProxy().Add(ctx, &out); err != nil { if orm.IsDuplicatedKey(err) { return nil, web.ErrDB.Msg("stream 重复,请勿重复添加") } return nil, web.ErrDB.Withf(`Add err[%s]`, err.Error()) } return &out, nil } // EditStreamProxy Update object information func (c *Core) EditStreamProxy(ctx context.Context, in *EditStreamProxyInput, id string) (*StreamProxy, error) { var out StreamProxy if err := c.store.StreamProxy().Edit(ctx, &out, func(b *StreamProxy) { if err := copier.Copy(b, in); err != nil { slog.Error("Copy", "err", err) } }, orm.Where("id=?", id)); err != nil { return nil, web.ErrDB.Withf(`Edit err[%s]`, err.Error()) } return &out, nil } // DelStreamProxy Delete object func (c *Core) DelStreamProxy(ctx context.Context, id string) (*StreamProxy, error) { var out StreamProxy if err := c.store.StreamProxy().Del(ctx, &out, orm.Where("id=?", id)); err != nil { return nil, web.ErrDB.Withf(`Del err[%s]`, err.Error()) } return &out, nil }