updates
This commit is contained in:
28
server/internal/repository/nutrient_repository.go
Normal file
28
server/internal/repository/nutrient_repository.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go-server/internal/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type NutrientRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewNutrientRepository(db *gorm.DB) *NutrientRepository {
|
||||
return &NutrientRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *NutrientRepository) GetAll(ctx context.Context) ([]*models.Nutrient, error) {
|
||||
var nutrients []*models.Nutrient
|
||||
err := r.db.WithContext(ctx).
|
||||
Preload("Categories").
|
||||
Find(&nutrients).
|
||||
Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nutrients, nil
|
||||
}
|
||||
Reference in New Issue
Block a user