renamed models, added mapper for recipes
This commit is contained in:
parent
7a6f5b5bcd
commit
8027fce80d
21 changed files with 164 additions and 61 deletions
5
frontend/src/api/dtos/AbstractDto.ts
Normal file
5
frontend/src/api/dtos/AbstractDto.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export abstract class AbstractDto {
|
||||
id?: string;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
import { AbstractDto } from "./AbstractDto.js";
|
||||
import { AbstractDto } from "./AbstractDto.ts";
|
||||
import { RecipeIngredientGroupDto } from "./RecipeIngredientGroupDto.js";
|
||||
import { RecipeInstructionStepDto } from "./RecipeInstructionStepDto.js";
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { AbstractDto } from "./AbstractDto.js";
|
||||
import { AbstractDto } from "./AbstractDto.ts";
|
||||
|
||||
export class RecipeIngredientDto extends AbstractDto{
|
||||
name!: string;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { AbstractDto } from "./AbstractDto.js";
|
||||
import { AbstractDto } from "./AbstractDto.ts";
|
||||
import { RecipeIngredientDto } from "./RecipeIngredientDto.js";
|
||||
|
||||
export class RecipeIngredientGroupDto extends AbstractDto{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { UUID } from "crypto";
|
||||
import { AbstractDto } from "./AbstractDto.js";
|
||||
import { AbstractDto } from "./AbstractDto.ts";
|
||||
|
||||
export class RecipeInstructionStepDto extends AbstractDto{
|
||||
text!: string;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { AbstractDto } from "./AbstractDto.js";
|
||||
import { AbstractDto } from "./AbstractDto.ts";
|
||||
|
||||
export class UserDto extends AbstractDto {
|
||||
firstName?: string;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Recipe } from "../../types/recipe"
|
||||
import type { LoginRequestDto } from "../dtos/LoginRequestDto";
|
||||
import type { LoginResponseDto } from "../dtos/LoginResponseDto";
|
||||
import { get, postJson, putJson } from "../utils/requests";
|
||||
import { postJson } from "../utils/requests";
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { Recipe } from "../../types/recipe"
|
||||
import { get, postJson, putJson } from "../utils/requests";
|
||||
import type { RecipeModel } from "../../models/RecipeModel"
|
||||
import { get } from "../utils/requests";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -18,7 +18,7 @@ const RECIPE_URL = `${BASE_URL}/compact-recipe`
|
|||
* @param searchString Search string for filtering recipeList
|
||||
* @returns Array of recipe
|
||||
*/
|
||||
export async function fetchRecipeList(searchString : string): Promise<Recipe[]> {
|
||||
export async function fetchRecipeList(searchString : string): Promise<RecipeModel[]> {
|
||||
let url : string = RECIPE_URL;
|
||||
// if there's a search string add it as query parameter
|
||||
if(searchString && searchString !== ""){
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { Recipe } from "../../types/recipe"
|
||||
import type { RecipeDto } from "../dtos/RecipeDto";
|
||||
import { get, postJson, putJson } from "../utils/requests";
|
||||
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ const RECIPE_URL = `${BASE_URL}/recipe`
|
|||
* @param id ID of the recipe to load
|
||||
* @returns A single recipe
|
||||
*/
|
||||
export async function fetchRecipe(id: string): Promise<Recipe> {
|
||||
export async function fetchRecipe(id: string): Promise<RecipeDto> {
|
||||
const res = await get(`${RECIPE_URL}/${id}`)
|
||||
return res.json()
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ export async function fetchRecipe(id: string): Promise<Recipe> {
|
|||
* @param recipe Recipe to create
|
||||
* @returns Saved recipe
|
||||
*/
|
||||
export async function createRecipe(recipe: Recipe): Promise<Recipe> {
|
||||
export async function createRecipe(recipe: RecipeDto): Promise<RecipeDto> {
|
||||
const res = await postJson(RECIPE_URL, JSON.stringify(recipe));
|
||||
return res.json();
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ export async function createRecipe(recipe: Recipe): Promise<Recipe> {
|
|||
* @param recipe Recipe to save. This recipe must have an ID!
|
||||
* @returns Saved recipe
|
||||
*/
|
||||
export async function updateRecipe(recipe: Recipe): Promise<Recipe> {
|
||||
export async function updateRecipe(recipe: RecipeDto): Promise<RecipeDto> {
|
||||
const res = await putJson(`${RECIPE_URL}/${recipe.id}`, JSON.stringify(recipe));
|
||||
return res.json();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
const BASE_URL = import.meta.env.VITE_API_BASE;
|
||||
|
||||
export function createBasicHeader() : Headers {
|
||||
const headers = new Headers();
|
||||
//headers.set('Access-Control-Allow-Origin', '*');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue