From d94251dea40f2f20e9ca631f84a62be6ac0d080c Mon Sep 17 00:00:00 2001 From: Anika Raemer Date: Sat, 27 Sep 2025 18:21:10 +0200 Subject: [PATCH] add dtos and fix entities including migrations --- src/dtos/RecipeDto.ts | 15 ++++++ src/dtos/RecipeIngredientDto.ts | 11 +++++ src/dtos/RecipeIngredientGroupDto.ts | 10 ++++ src/dtos/RecipeInstructionStepDto.ts | 8 +++ src/entities/RecipeIngredientEntity.ts | 11 ++++- src/entities/RecipeIngredientGroupEntity.ts | 4 +- .../1758988727469-UpdateIngredientTable.ts | 49 +++++++++++++++++++ ...8273-DropNotNullForIngredientGroupTitle.ts | 12 +++++ src/repositories/RecipeRepository.ts | 8 +++ 9 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 src/dtos/RecipeDto.ts create mode 100644 src/dtos/RecipeIngredientDto.ts create mode 100644 src/dtos/RecipeIngredientGroupDto.ts create mode 100644 src/dtos/RecipeInstructionStepDto.ts create mode 100644 src/migrations/1758988727469-UpdateIngredientTable.ts create mode 100644 src/migrations/1758988748273-DropNotNullForIngredientGroupTitle.ts create mode 100644 src/repositories/RecipeRepository.ts diff --git a/src/dtos/RecipeDto.ts b/src/dtos/RecipeDto.ts new file mode 100644 index 0000000..8cd632f --- /dev/null +++ b/src/dtos/RecipeDto.ts @@ -0,0 +1,15 @@ + +import { AbstractDto } from "./AbstractDto.js"; +import { RecipeIngredientGroupDto } from "./RecipeIngredientGroupDto.js"; +import { RecipeInstructionStepDto } from "./RecipeInstructionStepDto.js"; +/** + * DTO describing a recipe + */ + +export class RecipeDto extends AbstractDto { + title?: string; + amount?: number + amountDescription?: string; + instructions?: RecipeInstructionStepDto[]; + ingredientGroups?: RecipeIngredientGroupDto[]; +} \ No newline at end of file diff --git a/src/dtos/RecipeIngredientDto.ts b/src/dtos/RecipeIngredientDto.ts new file mode 100644 index 0000000..a50b161 --- /dev/null +++ b/src/dtos/RecipeIngredientDto.ts @@ -0,0 +1,11 @@ +import { UUID } from "crypto"; +import { AbstractDto } from "./AbstractDto.js"; + +export class RecipeIngredientDto extends AbstractDto{ + name?: string; + subtext?: string; + amount?: number; + unit?: string; + sortOrder?: number; + ingredientGroupId?: UUID; +} \ No newline at end of file diff --git a/src/dtos/RecipeIngredientGroupDto.ts b/src/dtos/RecipeIngredientGroupDto.ts new file mode 100644 index 0000000..36342f4 --- /dev/null +++ b/src/dtos/RecipeIngredientGroupDto.ts @@ -0,0 +1,10 @@ +import { UUID } from "crypto"; +import { AbstractDto } from "./AbstractDto.js"; +import { RecipeIngredientDto } from "./RecipeIngredientDto.js"; + +export class RecipeIngredientGroupDto extends AbstractDto{ + title?: string; + sortOrder?: string; + recipeId?: UUID; + ingredients?: RecipeIngredientDto[]; +} \ No newline at end of file diff --git a/src/dtos/RecipeInstructionStepDto.ts b/src/dtos/RecipeInstructionStepDto.ts new file mode 100644 index 0000000..c4bd86c --- /dev/null +++ b/src/dtos/RecipeInstructionStepDto.ts @@ -0,0 +1,8 @@ +import { UUID } from "crypto"; +import { AbstractDto } from "./AbstractDto.js"; + +export class RecipeInstructionStepDto extends AbstractDto{ + text?: string; + sortOrder?: number; + recipeId?: UUID; +} \ No newline at end of file diff --git a/src/entities/RecipeIngredientEntity.ts b/src/entities/RecipeIngredientEntity.ts index 1a7197d..93639b4 100644 --- a/src/entities/RecipeIngredientEntity.ts +++ b/src/entities/RecipeIngredientEntity.ts @@ -8,7 +8,16 @@ import { RecipeIngredientGroupEntity } from "./RecipeIngredientGroupEntity.js"; @Entity({ name: "recipe_ingredient" }) export class RecipeIngredientEntity extends AbstractEntity { @Column({ nullable: false }) - title!: string; + name!: string; + + @Column({nullable: true}) + subtext?: string; + + @Column({nullable: true}) + amount?: number; + + @Column({nullable: true}) + unit?: string; @Column({ nullable: false }) sortOrder!: number; diff --git a/src/entities/RecipeIngredientGroupEntity.ts b/src/entities/RecipeIngredientGroupEntity.ts index 746ba8d..1a7119a 100644 --- a/src/entities/RecipeIngredientGroupEntity.ts +++ b/src/entities/RecipeIngredientGroupEntity.ts @@ -8,8 +8,8 @@ import { RecipeIngredientEntity } from "./RecipeIngredientEntity.js"; */ @Entity({ name: "recipe_ingredient_group" }) export class RecipeIngredientGroupEntity extends AbstractEntity { - @Column({ nullable: false }) - title!: string; + @Column({ nullable: true }) + title?: string; @Column({ nullable: false }) sortOrder!: number; diff --git a/src/migrations/1758988727469-UpdateIngredientTable.ts b/src/migrations/1758988727469-UpdateIngredientTable.ts new file mode 100644 index 0000000..3baca04 --- /dev/null +++ b/src/migrations/1758988727469-UpdateIngredientTable.ts @@ -0,0 +1,49 @@ +import { MigrationInterface, QueryRunner, Table, TableColumn } from "typeorm"; + +export class UpdateIngredientTable1758988727469 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + // rename title column to name + await queryRunner.renameColumn( + "recipe_ingredient", + "title", + "name" + ) + // add missing columns + await queryRunner.addColumns( + "recipe_ingredient", + [ + new TableColumn({ + name: "amount", + type: "numeric", + isNullable: true, + }), + new TableColumn({ + name: "unit", + type: "varchar", + isNullable: true, + }), + new TableColumn({ + name: "subtext", + type: "varchar", + isNullable: true, + }) + ] + ) + } + + public async down(queryRunner: QueryRunner): Promise { + // rename name column to title + await queryRunner.renameColumn( + "recipe_ingredient", + "name", + "title" + ) + // remove columns + await queryRunner.dropColumns( + "recipe_ingredient", + ["amount", "unit", "subtext"] + ) + } + +} diff --git a/src/migrations/1758988748273-DropNotNullForIngredientGroupTitle.ts b/src/migrations/1758988748273-DropNotNullForIngredientGroupTitle.ts new file mode 100644 index 0000000..7b7c642 --- /dev/null +++ b/src/migrations/1758988748273-DropNotNullForIngredientGroupTitle.ts @@ -0,0 +1,12 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class DropNotNullForIngredientGroupTitle1758988748273 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query("ALTER TABLE recipe_ingredient_group ALTER COLUMN title DROP NOT NULL") + } + + public async down(queryRunner: QueryRunner): Promise { + } + +} diff --git a/src/repositories/RecipeRepository.ts b/src/repositories/RecipeRepository.ts new file mode 100644 index 0000000..eaf3dd5 --- /dev/null +++ b/src/repositories/RecipeRepository.ts @@ -0,0 +1,8 @@ +import { AbstractRepository } from "./AbstractRepository.js"; +import { RecipeEntity } from "../entities/RecipeEntity.js"; + +export class RecipeRepository extends AbstractRepository { + constructor() { + super(RecipeEntity); + } +} \ No newline at end of file