save recipes

This commit is contained in:
Anika Raemer 2025-09-28 12:24:59 +02:00
parent 3a887d8dbb
commit 380eb4cd21
18 changed files with 412 additions and 87 deletions

View file

@ -1,17 +1,34 @@
import { RecipeDto } from "../dtos/RecipeDto.js";
import { RecipeEntity } from "../entities/RecipeEntity.js";
import { ValidationError } from "../errors/httpErrors.js";
import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js";
import { RecipeIngredientGroupDtoEntityMapper } from "./RecipeIngredientGroupDtoEntityMapper.js";
import { RecipeInstructionStepDtoEntityMapper } from "./RecipeInstructionStepDtoEntityMapper.js";
export class RecipeDtoEntityMapper extends AbstractDtoEntityMapper<RecipeEntity,RecipeDto>{
constructor(
private instructionStepMapper : RecipeInstructionStepDtoEntityMapper,
private ingredientGroupMapper : RecipeIngredientGroupDtoEntityMapper
){
super();
}
toDto(entity: RecipeEntity): RecipeDto {
const dto = new RecipeDto();
this.mapBaseEntityToDto(entity, dto);
dto.title = entity.title;
dto.amount = entity.amount
dto.amountDescription = dto.amountDescription;
dto.amountDescription = entity.amountDescription;
// map instructions
const instructionStepEntities = entity.instructionSteps;
const instructionStepDtos = instructionStepEntities.map((stepEntity) => this.instructionStepMapper.toDto(stepEntity));
dto.instructions = instructionStepDtos;
// map ingredient groups
const ingredientGroupEntities = entity.ingredientGroups;
const ingredientGroupDtos = ingredientGroupEntities.map((groupEntity) => this.ingredientGroupMapper.toDto(groupEntity));
dto.ingredientGroups = ingredientGroupDtos;
return dto;
}
@ -20,11 +37,20 @@ export class RecipeDtoEntityMapper extends AbstractDtoEntityMapper<RecipeEntity,
const entity = new RecipeEntity();
this.mapBaseDtoToEntity(dto, entity);
entity.title = dto.title;
entity.amount = dto.amount
entity.amountDescription = dto.amountDescription;
// map instructions
const instructionStepDtos = dto.instructions;
const instructionStepEntities = instructionStepDtos.map((stepDto) => this.instructionStepMapper.toEntity(stepDto));
entity.instructionSteps = instructionStepEntities;
// map ingredient groups
const ingredientGroupDtos = dto.ingredientGroups;
const ingredientGroupEntities = ingredientGroupDtos.map((ingredientGroupDto) => this.ingredientGroupMapper.toEntity(ingredientGroupDto));
entity.ingredientGroups = ingredientGroupEntities;
return entity;
}