migrate database

This commit is contained in:
Alireza Ahmadi
2024-12-22 11:53:44 +01:00
parent ecd9348a0f
commit 7a047daf6f
14 changed files with 567 additions and 113 deletions
+34
View File
@@ -0,0 +1,34 @@
package service
import (
"s-ui/database"
"s-ui/database/model"
"gorm.io/gorm"
)
type InboundService struct{}
func (s *InboundService) GetAll() ([]model.Inbound, error) {
db := database.GetDB()
inbounds := []model.Inbound{}
err := db.Model(model.Inbound{}).Scan(&inbounds).Error
if err != nil {
return nil, err
}
return inbounds, nil
}
func (s *InboundService) FromIds(ids []uint) ([]*model.Inbound, error) {
db := database.GetDB()
inbounds := []*model.Inbound{}
err := db.Model(model.Inbound{}).Where("id in ?", ids).Scan(&inbounds).Error
if err != nil {
return nil, err
}
return inbounds, nil
}
func (s *InboundService) Save(db *gorm.DB, inbounds []*model.Inbound) error {
return db.Save(inbounds).Error
}