| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package service
- import (
- "gorm.io/gorm"
- "x-ui/database"
- "x-ui/database/model"
- )
- type InboundService struct {
- }
- func (s *InboundService) GetInbounds(userId int) ([]*model.Inbound, error) {
- db := database.GetDB()
- var inbounds []*model.Inbound
- err := db.Model(model.Inbound{}).Where("user_id = ?", userId).Find(&inbounds).Error
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, err
- }
- return inbounds, nil
- }
- func (s *InboundService) GetAllInbounds() ([]*model.Inbound, error) {
- db := database.GetDB()
- var inbounds []*model.Inbound
- err := db.Model(model.Inbound{}).Find(&inbounds).Error
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, err
- }
- return inbounds, nil
- }
- func (s *InboundService) AddInbound(inbound *model.Inbound) error {
- db := database.GetDB()
- return db.Save(inbound).Error
- }
- func (s *InboundService) DelInbound(id int) error {
- db := database.GetDB()
- return db.Delete(model.Inbound{}, id).Error
- }
|