Add RecipeService

pull/3/head
Clément FRÉVILLE 2 weeks ago
parent 9baca1c78c
commit 4b5b05f396

1
.gitignore vendored

@ -5,6 +5,7 @@
/tmp
/out-tsc
/bazel-out
target
# Node
/node_modules

@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { RouterOutlet, RouterLink, RouterLinkActive } from '@angular/router';
import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',

@ -1,10 +1,10 @@
import { Routes } from '@angular/router';
import {RecipesComponent} from './recipes/recipes.component'
import {RecipeComponent} from './recipe/recipe.component'
import {RecipeAddComponent} from './recipe-add/recipe-add.component'
import { RecipeAddComponent } from './recipe-add/recipe-add.component';
import { RecipeComponent } from './recipe/recipe.component';
import { RecipesComponent } from './recipes/recipes.component';
export const routes: Routes = [
{ path: 'recipes', component: RecipesComponent},
{ path: 'recipe/add', component: RecipeAddComponent},
{ path: 'recipe/:id', component: RecipeComponent}
{ path: 'recipes', component: RecipesComponent },
{ path: 'recipe/add', component: RecipeAddComponent },
{ path: 'recipe/:id', component: RecipeComponent },
];

@ -8,9 +8,9 @@ describe('RecipeAddComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RecipeAddComponent]
imports: [RecipeAddComponent],
})
.compileComponents();
.compileComponents();
fixture = TestBed.createComponent(RecipeAddComponent);
component = fixture.componentInstance;

@ -7,5 +7,4 @@ import { Component } from '@angular/core';
templateUrl: './recipe-add.component.html',
})
export class RecipeAddComponent {
}

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { RecipeService } from './recipe.service';
describe('RecipeService', () => {
let service: RecipeService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(RecipeService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { Recipe } from '../cookbook/type';
@Injectable({
providedIn: 'root',
})
export class RecipeService {
#recipes: Recipe[] = [];
constructor() {}
getAll(): Promise<Recipe[]> {
return Promise.resolve(this.#recipes);
}
get(id: number): Recipe | null {
return this.#recipes.find((recipe) => recipe.id === id) || null;
}
}

@ -8,9 +8,9 @@ describe('RecipeComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RecipeComponent]
imports: [RecipeComponent],
})
.compileComponents();
.compileComponents();
fixture = TestBed.createComponent(RecipeComponent);
component = fixture.componentInstance;

@ -7,11 +7,7 @@ import { Component, Input } from '@angular/core';
templateUrl: './recipe.component.html',
})
export class RecipeComponent {
@Input()
set id(id: string) {
}
}

@ -8,9 +8,9 @@ describe('RecipesComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RecipesComponent]
imports: [RecipesComponent],
})
.compileComponents();
.compileComponents();
fixture = TestBed.createComponent(RecipesComponent);
component = fixture.componentInstance;

@ -7,5 +7,4 @@ import { Component } from '@angular/core';
templateUrl: './recipes.component.html',
})
export class RecipesComponent {
}

@ -1,9 +1,9 @@
type Ingredient = {
export type Ingredient = {
id: number;
name: string;
};
type Recipe = {
export type Recipe = {
id: number;
name: string;
description: string;
@ -11,7 +11,7 @@ type Recipe = {
ingredients: IngredientEntry[];
};
type IngredientEntry = {
export type IngredientEntry = {
idIngredient: number;
idRecipe: number;
quantity: number;

Loading…
Cancel
Save