Add RecipeService
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@
|
|||||||
/tmp
|
/tmp
|
||||||
/out-tsc
|
/out-tsc
|
||||||
/bazel-out
|
/bazel-out
|
||||||
|
target
|
||||||
|
|
||||||
# Node
|
# Node
|
||||||
/node_modules
|
/node_modules
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { RouterOutlet, RouterLink, RouterLinkActive } from '@angular/router';
|
import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
import {RecipesComponent} from './recipes/recipes.component'
|
import { RecipeAddComponent } from './recipe-add/recipe-add.component';
|
||||||
import {RecipeComponent} from './recipe/recipe.component'
|
import { RecipeComponent } from './recipe/recipe.component';
|
||||||
import {RecipeAddComponent} from './recipe-add/recipe-add.component'
|
import { RecipesComponent } from './recipes/recipes.component';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{ path: 'recipes', component: RecipesComponent},
|
{ path: 'recipes', component: RecipesComponent },
|
||||||
{ path: 'recipe/add', component: RecipeAddComponent},
|
{ path: 'recipe/add', component: RecipeAddComponent },
|
||||||
{ path: 'recipe/:id', component: RecipeComponent}
|
{ path: 'recipe/:id', component: RecipeComponent },
|
||||||
];
|
];
|
||||||
|
@@ -8,9 +8,9 @@ describe('RecipeAddComponent', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [RecipeAddComponent]
|
imports: [RecipeAddComponent],
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(RecipeAddComponent);
|
fixture = TestBed.createComponent(RecipeAddComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
@@ -7,5 +7,4 @@ import { Component } from '@angular/core';
|
|||||||
templateUrl: './recipe-add.component.html',
|
templateUrl: './recipe-add.component.html',
|
||||||
})
|
})
|
||||||
export class RecipeAddComponent {
|
export class RecipeAddComponent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
16
src/app/recipe.service.spec.ts
Normal file
16
src/app/recipe.service.spec.ts
Normal file
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
19
src/app/recipe.service.ts
Normal file
19
src/app/recipe.service.ts
Normal file
@@ -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 () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [RecipeComponent]
|
imports: [RecipeComponent],
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(RecipeComponent);
|
fixture = TestBed.createComponent(RecipeComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
@@ -7,11 +7,7 @@ import { Component, Input } from '@angular/core';
|
|||||||
templateUrl: './recipe.component.html',
|
templateUrl: './recipe.component.html',
|
||||||
})
|
})
|
||||||
export class RecipeComponent {
|
export class RecipeComponent {
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set id(id: string) {
|
set id(id: string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,9 +8,9 @@ describe('RecipesComponent', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [RecipesComponent]
|
imports: [RecipesComponent],
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(RecipesComponent);
|
fixture = TestBed.createComponent(RecipesComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
@@ -7,5 +7,4 @@ import { Component } from '@angular/core';
|
|||||||
templateUrl: './recipes.component.html',
|
templateUrl: './recipes.component.html',
|
||||||
})
|
})
|
||||||
export class RecipesComponent {
|
export class RecipesComponent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
type Ingredient = {
|
export type Ingredient = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Recipe = {
|
export type Recipe = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
@@ -11,7 +11,7 @@ type Recipe = {
|
|||||||
ingredients: IngredientEntry[];
|
ingredients: IngredientEntry[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type IngredientEntry = {
|
export type IngredientEntry = {
|
||||||
idIngredient: number;
|
idIngredient: number;
|
||||||
idRecipe: number;
|
idRecipe: number;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
|
Reference in New Issue
Block a user