38 lines
883 B
Go
38 lines
883 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type VendorRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewVendorRepository(db *gorm.DB) *VendorRepository {
|
|
repo := &VendorRepository{db: db}
|
|
return repo
|
|
}
|
|
|
|
func (repository *VendorRepository) FindAll(context context.Context) ([]models.Vendor, error) {
|
|
var vendors []models.Vendor
|
|
|
|
result := repository.db.Find(&vendors)
|
|
slog.Info("VendorRepository#FindAll", "count", result.RowsAffected)
|
|
|
|
return vendors, nil
|
|
}
|
|
|
|
func (repository *VendorRepository) GetById(context context.Context, id string) (models.Vendor, error) {
|
|
var vendor = models.Vendor{ID: id}
|
|
slog.Info("VendorRepository#GetById", "id", id)
|
|
result := repository.db.First(&vendor)
|
|
if result.Error != nil {
|
|
slog.Info("VendorRepository#GetById", "error", result.Error.Error())
|
|
}
|
|
return vendor, result.Error
|
|
}
|