inbound.go 956 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package service
  2. import (
  3. "gorm.io/gorm"
  4. "x-ui/database"
  5. "x-ui/database/model"
  6. )
  7. type InboundService struct {
  8. }
  9. func (s *InboundService) GetInbounds(userId int) ([]*model.Inbound, error) {
  10. db := database.GetDB()
  11. var inbounds []*model.Inbound
  12. err := db.Model(model.Inbound{}).Where("user_id = ?", userId).Find(&inbounds).Error
  13. if err != nil && err != gorm.ErrRecordNotFound {
  14. return nil, err
  15. }
  16. return inbounds, nil
  17. }
  18. func (s *InboundService) GetAllInbounds() ([]*model.Inbound, error) {
  19. db := database.GetDB()
  20. var inbounds []*model.Inbound
  21. err := db.Model(model.Inbound{}).Find(&inbounds).Error
  22. if err != nil && err != gorm.ErrRecordNotFound {
  23. return nil, err
  24. }
  25. return inbounds, nil
  26. }
  27. func (s *InboundService) AddInbound(inbound *model.Inbound) error {
  28. db := database.GetDB()
  29. return db.Save(inbound).Error
  30. }
  31. func (s *InboundService) DelInbound(id int) error {
  32. db := database.GetDB()
  33. return db.Delete(model.Inbound{}, id).Error
  34. }