mirror of
https://github.com/gowvp/gb28181.git
synced 2026-04-22 23:17:19 +08:00
108 lines
3.6 KiB
Go
Executable File
108 lines
3.6 KiB
Go
Executable File
// Code generated by godddx, DO AVOID EDIT.
|
|
package proxy
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/gowvp/gb28181/internal/core/bz"
|
|
"github.com/ixugo/goddd/pkg/orm"
|
|
"github.com/ixugo/goddd/pkg/reason"
|
|
"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) {
|
|
query := orm.NewQuery(1)
|
|
query.OrderBy("created_at desc")
|
|
|
|
items := make([]*StreamProxy, 0)
|
|
total, err := c.store.StreamProxy().Find(ctx, &items, in, query.Encode()...)
|
|
if err != nil {
|
|
return nil, 0, reason.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, reason.ErrNotFound.Withf(`Get err[%s]`, err.Error())
|
|
}
|
|
return nil, reason.ErrDB.Withf(`Get err[%s]`, err.Error())
|
|
}
|
|
return &out, nil
|
|
}
|
|
|
|
func (c *Core) GetStreamProxyByAppStream(ctx context.Context, app, stream string) (*StreamProxy, error) {
|
|
var out StreamProxy
|
|
if err := c.store.StreamProxy().Get(ctx, &out, orm.Where("app=? AND stream=?", app, stream)); err != nil {
|
|
if orm.IsErrRecordNotFound(err) {
|
|
return nil, reason.ErrNotFound.Withf(`Get err[%s]`, err.Error())
|
|
}
|
|
return nil, reason.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.ErrorContext(ctx, "Copy", "err", err)
|
|
}
|
|
out.ID = c.uniqueID.UniqueID(bz.IDPrefixRTSP)
|
|
out.Stream = out.ID
|
|
out.App = "rtp"
|
|
if err := c.store.StreamProxy().Add(ctx, &out); err != nil {
|
|
if orm.IsDuplicatedKey(err) {
|
|
return nil, reason.ErrDB.SetMsg("stream 重复,请勿重复添加")
|
|
}
|
|
return nil, reason.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.ErrorContext(ctx, "Copy", "err", err)
|
|
}
|
|
}, orm.Where("id=?", id)); err != nil {
|
|
return nil, reason.ErrDB.Withf(`Edit err[%s]`, err.Error())
|
|
}
|
|
return &out, nil
|
|
}
|
|
|
|
func (c *Core) EditStreamProxyKey(ctx context.Context, streamKey, id string) (*StreamProxy, error) {
|
|
var out StreamProxy
|
|
if err := c.store.StreamProxy().Edit(ctx, &out, func(b *StreamProxy) {
|
|
out.StreamKey = streamKey
|
|
}, orm.Where("id=?", id)); err != nil {
|
|
return nil, reason.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, reason.ErrDB.Withf(`Del err[%s]`, err.Error())
|
|
}
|
|
return &out, nil
|
|
}
|