NAM-APJATEL-BACKEND/repository/devicePort_repo.go

48 lines
906 B
Go

package repository
import (
"users_management/m/model/entity"
"gorm.io/gorm"
)
type DevicePortRepo interface {
Post(devicePort entity.DevicePort) error
GetAll() ([]entity.DevicePort, error)
Update(devicePort entity.DevicePort) error
}
type devicePortRepo struct {
db *gorm.DB
}
func NewDevicePortRepo(db *gorm.DB) DevicePortRepo {
return &devicePortRepo{
db: db,
}
}
func (r *devicePortRepo) Post(devicePort entity.DevicePort) error {
err := r.db.Create(&devicePort).Error
if err != nil {
return err
}
return nil
}
func (r *devicePortRepo) GetAll() ([]entity.DevicePort, error) {
var devicePorts []entity.DevicePort
err := r.db.Find(&devicePorts).Error
if err != nil {
return devicePorts, err
}
return devicePorts, nil
}
func (r *devicePortRepo) Update(devicePort entity.DevicePort) error {
err := r.db.Save(&devicePort).Error
if err != nil {
return err
}
return nil
}