gameshielduserip.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package repository
  2. import (
  3. "context"
  4. "github.com/go-nunu/nunu-layout-advanced/internal/model"
  5. )
  6. type GameShieldUserIpRepository interface {
  7. GetGameShieldUserIp(ctx context.Context, id int64) (*model.GameShieldUserIp, error)
  8. GetGameShieldUserIpByUid(ctx context.Context, uid int64) (int, error)
  9. AddGameShieldUserIp(ctx context.Context, req *model.GameShieldUserIp) error
  10. UpdateGameShieldUserIp(ctx context.Context, req *model.GameShieldUserIp) error
  11. DeleteGameShieldUserIp(ctx context.Context, id int64) error
  12. }
  13. func NewGameShieldUserIpRepository(
  14. repository *Repository,
  15. ) GameShieldUserIpRepository {
  16. return &gameShieldUserIpRepository{
  17. Repository: repository,
  18. }
  19. }
  20. type gameShieldUserIpRepository struct {
  21. *Repository
  22. }
  23. func (r *gameShieldUserIpRepository) GetGameShieldUserIp(ctx context.Context, id int64) (*model.GameShieldUserIp, error) {
  24. var gameShieldUserIp model.GameShieldUserIp
  25. return &gameShieldUserIp, nil
  26. }
  27. func (r *gameShieldUserIpRepository) GetGameShieldUserIpByUid(ctx context.Context, uid int64) (int, error) {
  28. var ipId int
  29. if err := r.DB(ctx).Model(&model.GameShieldUserIp{}).Select("ip_id").Where("uid = ?", uid).Scan(&ipId).Error; err != nil {
  30. return 0, err
  31. }
  32. return ipId, nil
  33. }
  34. func (r *gameShieldUserIpRepository) AddGameShieldUserIp(ctx context.Context, req *model.GameShieldUserIp) error {
  35. if err := r.DB(ctx).Create(req).Error; err != nil {
  36. return err
  37. }
  38. return nil
  39. }
  40. func (r *gameShieldUserIpRepository) UpdateGameShieldUserIp(ctx context.Context, req *model.GameShieldUserIp) error {
  41. if err := r.DB(ctx).Updates(req).Error; err != nil {
  42. return err
  43. }
  44. return nil
  45. }
  46. func (r *gameShieldUserIpRepository) DeleteGameShieldUserIp(ctx context.Context, id int64) error {
  47. if err := r.DB(ctx).Where("id = ?", id).Delete(&model.GameShieldUserIp{}).Error; err != nil {
  48. return err
  49. }
  50. return nil
  51. }