package repository import ( "context" "next-terminal/server/model" ) var AgentGatewayRepository = new(agentGatewayRepository) type agentGatewayRepository struct { baseRepository } func (r agentGatewayRepository) FindAll(c context.Context) (o []model.AgentGateway, err error) { err = r.GetDB(c).Order("sort asc, created asc").Find(&o).Error return } func (r agentGatewayRepository) Find(c context.Context, pageIndex, pageSize int, name string) (o []model.AgentGatewayForPage, total int64, err error) { db := r.GetDB(c).Table("agent_gateways") dbCounter := r.GetDB(c).Table("agent_gateways") if len(name) > 0 { db = db.Where("name like ?", "%"+name+"%") dbCounter = dbCounter.Where("name like ?", "%"+name+"%") } err = dbCounter.Count(&total).Error if err != nil { return nil, 0, err } err = db.Order("sort asc, created asc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error if o == nil { o = make([]model.AgentGatewayForPage, 0) } return } func (r agentGatewayRepository) Create(c context.Context, o *model.AgentGateway) error { return r.GetDB(c).Create(o).Error } func (r agentGatewayRepository) UpdateById(c context.Context, o *model.AgentGateway, id string) error { o.ID = id return r.GetDB(c).Updates(o).Error } func (r agentGatewayRepository) UpdateSort(c context.Context, id, sort string) error { return r.GetDB(c).Table("agent_gateways").Where("id = ?", id).Update("sort", sort).Error } func (r agentGatewayRepository) DeleteById(c context.Context, id string) error { return r.GetDB(c).Where("id = ?", id).Delete(&model.AgentGateway{}).Error } func (r agentGatewayRepository) FindById(c context.Context, id string) (o model.AgentGateway, err error) { err = r.GetDB(c).Where("id = ?", id).First(&o).Error return }