1Panel/backend/app/repo/website_acme_account.go

59 lines
1.7 KiB
Go
Raw Normal View History

2022-11-11 09:41:39 +00:00
package repo
import (
"github.com/1Panel-dev/1Panel/backend/app/model"
"gorm.io/gorm"
)
2022-11-11 09:41:39 +00:00
type IAcmeAccountRepo interface {
Page(page, size int, opts ...DBOption) (int64, []model.WebsiteAcmeAccount, error)
GetFirst(opts ...DBOption) (*model.WebsiteAcmeAccount, error)
Create(account model.WebsiteAcmeAccount) error
Save(account model.WebsiteAcmeAccount) error
DeleteBy(opts ...DBOption) error
WithEmail(email string) DBOption
}
func NewIAcmeAccountRepo() IAcmeAccountRepo {
return &WebsiteAcmeAccountRepo{}
}
2022-11-11 09:41:39 +00:00
type WebsiteAcmeAccountRepo struct {
}
func (w *WebsiteAcmeAccountRepo) WithEmail(email string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("email = ?", email)
}
}
func (w *WebsiteAcmeAccountRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteAcmeAccount, error) {
2022-11-11 09:41:39 +00:00
var accounts []model.WebsiteAcmeAccount
db := getDb(opts...).Model(&model.WebsiteAcmeAccount{})
count := int64(0)
db = db.Count(&count)
2023-02-09 08:13:06 +00:00
err := db.Limit(size).Offset(size * (page - 1)).Find(&accounts).Error
2022-11-11 09:41:39 +00:00
return count, accounts, err
}
func (w *WebsiteAcmeAccountRepo) GetFirst(opts ...DBOption) (*model.WebsiteAcmeAccount, error) {
2022-11-16 02:31:35 +00:00
var account model.WebsiteAcmeAccount
db := getDb(opts...).Model(&model.WebsiteAcmeAccount{})
if err := db.First(&account).Error; err != nil {
return nil, err
2022-11-16 02:31:35 +00:00
}
return &account, nil
2022-11-16 02:31:35 +00:00
}
func (w *WebsiteAcmeAccountRepo) Create(account model.WebsiteAcmeAccount) error {
2022-11-11 09:41:39 +00:00
return getDb().Create(&account).Error
}
func (w *WebsiteAcmeAccountRepo) Save(account model.WebsiteAcmeAccount) error {
2022-11-11 09:41:39 +00:00
return getDb().Save(&account).Error
}
func (w *WebsiteAcmeAccountRepo) DeleteBy(opts ...DBOption) error {
2022-11-11 09:41:39 +00:00
return getDb(opts...).Debug().Delete(&model.WebsiteAcmeAccount{}).Error
}