gameshieldsdkip.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package repository
  2. import (
  3. "context"
  4. "github.com/go-nunu/nunu-layout-advanced/internal/model"
  5. )
  6. type GameShieldSdkIpRepository interface {
  7. GetGameShieldSdkIp(ctx context.Context, id int64) (*model.GameShieldSdkIp, error)
  8. AddGameShieldSdkIp(ctx context.Context, req *model.GameShieldSdkIp) error
  9. UpdateGameShieldSdkIp(ctx context.Context, gameShieldSdkIp *model.GameShieldSdkIp) error
  10. DeleteGameShieldSdkIp(ctx context.Context, id int64) error
  11. GetGameShieldSdkIpByHostId(ctx context.Context, hostId int) (*model.GameShieldSdkIp, error)
  12. GetGameShieldSdkIpNewByHostId(ctx context.Context, hostId int) (string, error)
  13. GetGameShieldSdkIpCountByHostId(ctx context.Context, hostId int) (int64, error)
  14. }
  15. func NewGameShieldSdkIpRepository(
  16. repository *Repository,
  17. ) GameShieldSdkIpRepository {
  18. return &gameShieldSdkIpRepository{
  19. Repository: repository,
  20. }
  21. }
  22. type gameShieldSdkIpRepository struct {
  23. *Repository
  24. }
  25. func (r *gameShieldSdkIpRepository) GetGameShieldSdkIp(ctx context.Context, id int64) (*model.GameShieldSdkIp, error) {
  26. var res model.GameShieldSdkIp
  27. if err := r.DB(ctx).Where("id = ?", id).First(&res).Error; err != nil {
  28. return nil, err
  29. }
  30. return &res, nil
  31. }
  32. func (r *gameShieldSdkIpRepository) AddGameShieldSdkIp(ctx context.Context, req *model.GameShieldSdkIp) error {
  33. if err := r.DB(ctx).Create(req).Error; err != nil {
  34. return err
  35. }
  36. return nil
  37. }
  38. func (r *gameShieldSdkIpRepository) UpdateGameShieldSdkIp(ctx context.Context, gameShieldSdkIp *model.GameShieldSdkIp) error {
  39. if err := r.DB(ctx).Updates(gameShieldSdkIp).Error; err != nil {
  40. return err
  41. }
  42. return nil
  43. }
  44. func (r *gameShieldSdkIpRepository) DeleteGameShieldSdkIp(ctx context.Context, id int64) error {
  45. if err := r.DB(ctx).Where("id = ?", id).Delete(&model.GameShieldSdkIp{}).Error; err != nil {
  46. return err
  47. }
  48. return nil
  49. }
  50. func (r *gameShieldSdkIpRepository) GetGameShieldSdkIpByHostId(ctx context.Context, hostId int) (*model.GameShieldSdkIp, error) {
  51. var res model.GameShieldSdkIp
  52. if err := r.DB(ctx).Where("host_id = ?", hostId).Select(&model.GameShieldSdkIp{}).Error; err != nil {
  53. return nil, err
  54. }
  55. return &res, nil
  56. }
  57. func (r *gameShieldSdkIpRepository) GetGameShieldSdkIpNewByHostId(ctx context.Context, hostId int) (string, error) {
  58. var res model.GameShieldSdkIp
  59. if err := r.DB(ctx).Where("host_id = ?", hostId).Order("id DESC").First(&model.GameShieldSdkIp{}).Error; err != nil {
  60. return "", err
  61. }
  62. return res.SdkIp, nil
  63. }
  64. func (r *gameShieldSdkIpRepository) GetGameShieldSdkIpCountByHostId(ctx context.Context, hostId int) (int64, error) {
  65. var res int64
  66. if err := r.DB(ctx).Model(&model.GameShieldSdkIp{}).Where("host_id = ?", hostId).Count(&res).Error; err != nil {
  67. return 0, err
  68. }
  69. return res, nil
  70. }