Files
kontor/kontor-gin/internal/repository/vendor.go
T
Thomas Peetz f5abb44466
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
WIP: Export Kontor DB
2026-09-30 18:55:59 +02:00

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
}