mirror of
https://github.com/gowvp/gb28181.git
synced 2025-09-26 19:41:19 +08:00
83 lines
2.7 KiB
Go
Executable File
83 lines
2.7 KiB
Go
Executable File
// Code generated by gowebx, DO AVOID EDIT.
|
|
package sms
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/ixugo/goweb/pkg/orm"
|
|
"github.com/ixugo/goweb/pkg/web"
|
|
"github.com/jinzhu/copier"
|
|
)
|
|
|
|
// MediaServerStorer Instantiation interface
|
|
type MediaServerStorer interface {
|
|
Find(context.Context, *[]*MediaServer, orm.Pager, ...orm.QueryOption) (int64, error)
|
|
Get(context.Context, *MediaServer, ...orm.QueryOption) error
|
|
Add(context.Context, *MediaServer) error
|
|
Edit(context.Context, *MediaServer, func(*MediaServer), ...orm.QueryOption) error
|
|
Del(context.Context, *MediaServer, ...orm.QueryOption) error
|
|
}
|
|
|
|
// FindMediaServer Paginated search
|
|
func (c *Core) FindMediaServer(ctx context.Context, in *FindMediaServerInput) ([]*MediaServer, int64, error) {
|
|
items := make([]*MediaServer, 0)
|
|
total, err := c.storer.MediaServer().Find(ctx, &items, in)
|
|
if err != nil {
|
|
return nil, 0, web.ErrDB.Withf(`Find err[%s]`, err.Error())
|
|
}
|
|
return items, total, nil
|
|
}
|
|
|
|
// GetMediaServer Query a single object
|
|
func (c *Core) GetMediaServer(ctx context.Context, id string) (*MediaServer, error) {
|
|
var out MediaServer
|
|
if err := c.storer.MediaServer().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
|
|
}
|
|
|
|
// AddMediaServer Insert into database
|
|
func (c *Core) AddMediaServer(ctx context.Context, in *AddMediaServerInput) (*MediaServer, error) {
|
|
var out MediaServer
|
|
if err := copier.Copy(&out, in); err != nil {
|
|
slog.Error("Copy", "err", err)
|
|
}
|
|
if err := c.storer.MediaServer().Add(ctx, &out); err != nil {
|
|
return nil, web.ErrDB.Withf(`Add err[%s]`, err.Error())
|
|
}
|
|
return &out, nil
|
|
}
|
|
|
|
// EditMediaServer Update object information
|
|
func (c *Core) EditMediaServer(ctx context.Context, in *EditMediaServerInput, id string, serverPort int) (*MediaServer, error) {
|
|
var out MediaServer
|
|
if err := c.storer.MediaServer().Edit(ctx, &out, func(b *MediaServer) {
|
|
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())
|
|
}
|
|
c.connection(&out, serverPort)
|
|
return &out, nil
|
|
}
|
|
|
|
// DelMediaServer Delete object
|
|
func (c *Core) DelMediaServer(ctx context.Context, id string) (*MediaServer, error) {
|
|
var out MediaServer
|
|
if err := c.storer.MediaServer().Del(ctx, &out, orm.Where("id=?", id)); err != nil {
|
|
return nil, web.ErrDB.Withf(`Del err[%s]`, err.Error())
|
|
}
|
|
return &out, nil
|
|
}
|
|
|
|
func (c *Core) getDefaultMediaServer(ctx context.Context) (*MediaServer, error) {
|
|
var out MediaServer
|
|
return &out, c.storer.MediaServer().Get(ctx, &out, orm.Where("id=?", DefaultMediaServerID))
|
|
}
|