28 lines
No EOL
1,003 B
TypeScript
28 lines
No EOL
1,003 B
TypeScript
import { CompactRecipeDto } from "../dtos/CompactRecipeDto.js";
|
|
import { RecipeEntity } from "../entities/RecipeEntity.js";
|
|
import { CompactRecipeDtoEntityMapper } from "../mappers/CompactRecipeDtoEntityMapper.js";
|
|
import { RecipeRepository } from "../repositories/RecipeRepository.js";
|
|
|
|
/**
|
|
* Responsible for loading recipe header data
|
|
*/
|
|
export class CompactRecipeController {
|
|
constructor(
|
|
private repository: RecipeRepository,
|
|
private mapper: CompactRecipeDtoEntityMapper
|
|
) {}
|
|
|
|
/**
|
|
* Load list of all recipes
|
|
* @returns List of all recipes
|
|
*/
|
|
async getAllCompactRecipes() {
|
|
const recipeEntities: RecipeEntity[] = await this.repository.findAll();
|
|
// @todo load instruction steps, ingredient groups and ingredients before mapping!
|
|
let recipeDtos: CompactRecipeDto[] = [];
|
|
recipeEntities.forEach(recipeEntity => {
|
|
recipeDtos.push(this.mapper.toDto(recipeEntity));
|
|
});
|
|
return recipeDtos;
|
|
}
|
|
} |