Files
terminal/server/repository/website_group.go
T

51 lines
1.5 KiB
Go

package repository
import (
"context"
"next-terminal/server/common"
"next-terminal/server/model"
)
var WebsiteGroupRepository = new(websiteGroupRepository)
type websiteGroupRepository struct {
baseRepository
}
func (r websiteGroupRepository) FindAll(c context.Context) (o []model.WebsiteGroup, err error) {
err = r.GetDB(c).Order("sort asc, name asc").Find(&o).Error
return
}
func (r websiteGroupRepository) FindById(c context.Context, id string) (o model.WebsiteGroup, err error) {
err = r.GetDB(c).Where("id = ?", id).First(&o).Error
return
}
func (r websiteGroupRepository) Create(c context.Context, o *model.WebsiteGroup) error {
o.Created = common.NowJsonTime()
return r.GetDB(c).Create(o).Error
}
func (r websiteGroupRepository) UpdateById(c context.Context, o *model.WebsiteGroup) error {
return r.GetDB(c).Updates(o).Error
}
func (r websiteGroupRepository) DeleteById(c context.Context, id string) error {
return r.GetDB(c).Where("id = ?", id).Delete(&model.WebsiteGroup{}).Error
}
func (r websiteGroupRepository) DeleteByParentId(c context.Context, parentId string) error {
return r.GetDB(c).Where("parent_id = ?", parentId).Delete(&model.WebsiteGroup{}).Error
}
func (r websiteGroupRepository) CountByParentId(c context.Context, parentId string) (total int64, err error) {
err = r.GetDB(c).Model(&model.WebsiteGroup{}).Where("parent_id = ?", parentId).Count(&total).Error
return
}
func (r websiteGroupRepository) DeleteAll(c context.Context) error {
return r.GetDB(c).Where("1 = 1").Delete(&model.WebsiteGroup{}).Error
}