60 lines
1.2 KiB
Go
60 lines
1.2 KiB
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
|
|
|
|
GetByID(id string) (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
|
|
}
|
|
|
|
func (r *devicePortRepo) GetByID(id string) (entity.DevicePort, error) {
|
|
var devicePort entity.DevicePort
|
|
err := r.db.Where("id = ?", id).First(&devicePort).Error
|
|
if err != nil {
|
|
return devicePort, err
|
|
}
|
|
|
|
return devicePort, nil
|
|
} |