ingredient composition
This commit is contained in:
@@ -24,7 +24,11 @@ func (r *IngredientRepository) Create(ctx context.Context, ingredient *entities.
|
||||
|
||||
func (r *IngredientRepository) GetByID(ctx context.Context, id, organizationID uuid.UUID) (*entities.Ingredient, error) {
|
||||
var ingredient entities.Ingredient
|
||||
err := r.db.WithContext(ctx).Preload("Unit").Where("id = ? AND organization_id = ?", id, organizationID).First(&ingredient).Error
|
||||
err := r.db.WithContext(ctx).
|
||||
Preload("Unit").
|
||||
Preload("Compositions.ChildIngredient.Unit").
|
||||
Where("id = ? AND organization_id = ?", id, organizationID).
|
||||
First(&ingredient).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -57,7 +61,13 @@ func (r *IngredientRepository) GetAll(ctx context.Context, organizationID uuid.U
|
||||
|
||||
// Get paginated results with Unit preloaded
|
||||
offset := (page - 1) * limit
|
||||
err := query.Preload("Unit").Order("created_at DESC").Limit(limit).Offset(offset).Find(&ingredients).Error
|
||||
err := query.
|
||||
Preload("Unit").
|
||||
Preload("Compositions.ChildIngredient.Unit").
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&ingredients).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user