123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package repository
- import (
- "context"
- "github.com/go-nunu/nunu-layout-advanced/internal/model"
- )
- type GameShieldRepository interface {
- GetGameShieldById(ctx context.Context, id int64) (*model.GameShield, error)
- GetGameShieldDuplicateName(ctx context.Context, appName string, uid int) (int64, error)
- AddGameShield(ctx context.Context, gameShield *model.GameShield) error
- UpdateGameShield(ctx context.Context, gameShield *model.GameShield) error
- DeleteGameShield(ctx context.Context, ruleId int) error
- GetGameShieldIsBuy(ctx context.Context, uid int64) (int64, error)
- GetGameShieldNextduedate(ctx context.Context, uid int64, productID string) (string, error)
- GetGameShieldExistingIps(ctx context.Context, ip string) ([]string, error)
- GetGameShieldNameByDunName(ctx context.Context, appName string) (string, error)
- GetGameShieldIdByDunName(ctx context.Context, id int64) (string, error)
- GetGameShieldRuleIdByAppName(ctx context.Context, appName string) (int, error)
- }
- func NewGameShieldRepository(
- repository *Repository,
- ) GameShieldRepository {
- return &gameShieldRepository{
- Repository: repository,
- }
- }
- type gameShieldRepository struct {
- *Repository
- }
- func (r *gameShieldRepository) GetGameShieldById(ctx context.Context, id int64) (*model.GameShield, error) {
- var res model.GameShield
- if err := r.DB(ctx).Where("id = ?", id).First(&res).Error; err != nil {
- return nil, err
- }
- return &res, nil
- }
- func (r *gameShieldRepository) GetGameShieldDuplicateName(ctx context.Context, appName string, uid int) (int64, error) {
- var count int64
- if err := r.DB(ctx).Model(&model.GameShield{}).Where("app_name = ?", appName).Where("uid = ?", uid).Count(&count).Error; err != nil {
- return 0, err
- }
- return count, nil
- }
- func (r *gameShieldRepository) AddGameShield(ctx context.Context, gameShield *model.GameShield) error {
- if err := r.DB(ctx).Create(gameShield).Error; err != nil {
- return err
- }
- return nil
- }
- func (r *gameShieldRepository) UpdateGameShield(ctx context.Context, gameShield *model.GameShield) error {
- if err := r.DB(ctx).Where("rule_id", gameShield.RuleId).Updates(gameShield).Error; err != nil {
- return err
- }
- return nil
- }
- func (r *gameShieldRepository) DeleteGameShield(ctx context.Context, ruleId int) error {
- if err := r.DB(ctx).Where("rule_id = ?", ruleId).Delete(&model.GameShield{}).Error; err != nil {
- return err
- }
- return nil
- }
- func (r *gameShieldRepository) GetGameShieldIsBuy(ctx context.Context, uid int64) (int64, error) {
- var count int64
- if err := r.DB(ctx).Table("shd_host").
- Where("domainstatus = ?", "Active").
- Where("productid = ?", 67).
- Where("uid = ?", uid).
- Count(&count).Error; err != nil {
- return 0, err
- }
- return count, nil
- }
- func (r *gameShieldRepository) GetGameShieldNextduedate(ctx context.Context, uid int64, productID string) (string, error) {
- var nextDueDate string
- err := r.DB(ctx).Table("shd_host").
- Select("nextduedate").
- Where("id = ?", productID).
- Where("uid = ?", uid).
- Scan(&nextDueDate).Error
- if err != nil {
- return "", err
- }
- return nextDueDate, nil
- }
- func (r *gameShieldRepository) GetGameShieldExistingIps(ctx context.Context, ip string) ([]string, error) {
- var res []string
- if err := r.DB(ctx).Model(&model.GameShield{}).
- Where("app_ip LIKE ?", ip+"%").
- Pluck("app_ip", &res).Error; err != nil {
- return nil, err
- }
- return res, nil
- }
- func (r *gameShieldRepository) GetGameShieldNameByDunName(ctx context.Context, appName string) (string, error) {
- var res string
- if err := r.DB(ctx).Model(&model.GameShield{}).
- Where("app_name = ?", appName).
- Pluck("dun_name", &res).Error; err != nil {
- return "", err
- }
- return res, nil
- }
- func (r *gameShieldRepository) GetGameShieldIdByDunName(ctx context.Context, id int64) (string, error) {
- var res string
- if err := r.DB(ctx).Model(&model.GameShield{}).
- Where("id = ?", id).
- Pluck("dun_name", &res).Error; err != nil {
- return "", err
- }
- return res, nil
- }
- func (r *gameShieldRepository) GetGameShieldRuleIdByAppName(ctx context.Context, appName string) (int, error) {
- var res int
- if err := r.DB(ctx).Model(&model.GameShield{}).
- Where("app_name = ?", appName).
- Pluck("rule_id", &res).Error; err != nil {
- return 0, err
- }
- return res, nil
- }
|