add CompactRecipePoint for loading recipe header data
This commit is contained in:
parent
380eb4cd21
commit
3638909761
8 changed files with 97 additions and 35 deletions
28
src/controllers/CompactRecipeController.ts
Normal file
28
src/controllers/CompactRecipeController.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
import { RecipeDto } from "../dtos/RecipeDto.js";
|
||||
import { RecipeDtoEntityMapper } from "../mappers/RecipeDtoEntityMapper.js";
|
||||
import { RecipeRepository } from "../repositories/RecipeRepository.js";
|
||||
import { RecipeEntity } from "../entities/RecipeEntity.js";
|
||||
import { ValidationError } from "../errors/httpErrors.js";
|
||||
import { RecipeInstructionStepDto } from "../dtos/RecipeInstructionStepDto.js";
|
||||
import { RecipeIngredientGroupDto } from "../dtos/RecipeIngredientGroupDto.js";
|
||||
import { RecipeIngredientDto } from "../dtos/RecipeIngredientDto.js";
|
||||
|
||||
/**
|
||||
* Controls all user specific actions
|
||||
* Controls all recipe specific actions
|
||||
*/
|
||||
export class RecipeController {
|
||||
constructor(
|
||||
|
|
@ -16,19 +15,6 @@ export class RecipeController {
|
|||
private mapper: RecipeDtoEntityMapper
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Load list of all recipes
|
||||
* @returns List of all recipes
|
||||
*/
|
||||
async getAllRecipes() {
|
||||
const recipeEntities : RecipeEntity[] = await this.repository.findAll();
|
||||
let recipeDtos: RecipeDto[] = [];
|
||||
recipeEntities.forEach(recipeEntity => {
|
||||
recipeDtos.push(this.mapper.toDto(recipeEntity));
|
||||
});
|
||||
return recipeDtos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new recipe
|
||||
* @param dto RecipeDto containing the new recipe
|
||||
|
|
@ -48,7 +34,7 @@ export class RecipeController {
|
|||
* @param dto RecipeDTO
|
||||
* @returns true if the recipe is valid
|
||||
*/
|
||||
protected isRecipeDtoValid(dto: RecipeDto): boolean {
|
||||
private isRecipeDtoValid(dto: RecipeDto): boolean {
|
||||
|
||||
return dto.title !== undefined
|
||||
&& dto.title.length !== 0
|
||||
|
|
@ -64,7 +50,7 @@ export class RecipeController {
|
|||
* @param ingredientGroups Array of ingredient groups
|
||||
* @returns true if all ingredient groups are valid
|
||||
*/
|
||||
protected isIngredientGroupsValid(ingredientGroups: RecipeIngredientGroupDto[] | undefined): boolean {
|
||||
private isIngredientGroupsValid(ingredientGroups: RecipeIngredientGroupDto[] | undefined): boolean {
|
||||
return ingredientGroups !== undefined
|
||||
&& ingredientGroups.length !== 0
|
||||
&& ingredientGroups.every(group => {
|
||||
|
|
@ -80,7 +66,7 @@ export class RecipeController {
|
|||
* @param ingredients Array if ingredients
|
||||
* @returns true if the ingredient list is valid
|
||||
*/
|
||||
isIngredientsValid(ingredients: RecipeIngredientDto[] | undefined): boolean {
|
||||
private isIngredientsValid(ingredients: RecipeIngredientDto[] | undefined): boolean {
|
||||
return ingredients !== undefined
|
||||
&& ingredients.length !== 0
|
||||
&& ingredients.every(ingredient => {
|
||||
|
|
@ -92,7 +78,7 @@ export class RecipeController {
|
|||
* @param ingredient RecipeIngredientDto
|
||||
* @returns true if the ingredient is valid
|
||||
*/
|
||||
isIngredientValid(ingredient: RecipeIngredientDto): boolean {
|
||||
private isIngredientValid(ingredient: RecipeIngredientDto): boolean {
|
||||
return ingredient !== null
|
||||
&& ingredient.sortOrder !== undefined
|
||||
&& ingredient.name !== undefined
|
||||
|
|
@ -106,7 +92,7 @@ export class RecipeController {
|
|||
* @param instructions Array if instruction step DTOs
|
||||
* @returns Boolean indicating whether the instruction steps are valid
|
||||
*/
|
||||
protected isInstructionsValid(instructions: RecipeInstructionStepDto[] | undefined): boolean {
|
||||
private isInstructionsValid(instructions: RecipeInstructionStepDto[] | undefined): boolean {
|
||||
return instructions !== undefined
|
||||
&& instructions.length !== 0
|
||||
&& instructions.every(step => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue