-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d16170
commit 39dfc35
Showing
13 changed files
with
188 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { RouterModule } from '@angular/router'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
|
||
import { RecipeListComponent } from './recipe-list/recipe-list.component'; | ||
import { RecipeService } from './recipe.service'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
RecipeListComponent, | ||
], | ||
imports: [ | ||
BrowserModule, | ||
RouterModule.forRoot([]), | ||
HttpClientModule, | ||
ReactiveFormsModule, | ||
], | ||
providers: [ | ||
RecipeService, | ||
], | ||
bootstrap: [RecipeListComponent], | ||
}) | ||
export class AppModule {} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<article> | ||
<img class="recipe-photo" [src]="recipe?.photo" alt="Exterior photo of {{recipe?.name}}"/> | ||
<section class="recipe-description"> | ||
<h2 class="recipe-heading">{{recipe?.name}}</h2> | ||
<p class="recipe-category">{{recipe?.category}}</p> | ||
</section> | ||
<section> | ||
<p class="recipe-location">{{recipe?.ingredients}}</p> | ||
<p class="recipe-location">{{recipe?.method}}</p> | ||
</section> | ||
<section class="recipe-apply"> | ||
<h2 class="recipe-feedback">We would appreciate your feedback on this dish:</h2> | ||
<form [formGroup]="applyForm" (submit)="submitApplication()"> | ||
<label for="first-name">First Name:</label> | ||
<input id="first-name" type="text" formControlName="firstName"> | ||
|
||
<label for="last-name">Last Name:</label> | ||
<input id="last-name" type="text" formControlName="lastName"> | ||
|
||
<label for="email">Email:</label> | ||
<input id="email" type="email" formControlName="email"> | ||
|
||
<label for="feedback">Feedback:</label> | ||
<input id="feedback" type="text" formControlName="feedback"> | ||
<button type="submit" class="primary">Apply now</button> | ||
</form> | ||
</section> | ||
</article> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { RecipeService } from '../recipe.service'; | ||
import { Recipe } from '../recipe.model'; | ||
import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'app-recipe-list', | ||
templateUrl: './recipe-list.component.html', | ||
styleUrls: ['./recipe-list.component.css'] | ||
}) | ||
export class RecipeListComponent implements OnInit { | ||
recipe: Recipe | undefined; | ||
|
||
|
||
applyForm = new FormGroup({ | ||
firstName: new FormControl('', Validators.required), | ||
lastName: new FormControl('', Validators.required), | ||
email: new FormControl('', [Validators.required, Validators.email]), | ||
feedback: new FormControl('') | ||
}); | ||
|
||
constructor(private route: ActivatedRoute, private recipeService: RecipeService) {} | ||
|
||
ngOnInit(): void { | ||
const recipesLocationId = parseInt(this.route.snapshot.params['id'], 10); | ||
this.recipeService.getRecipeById(recipesLocationId).subscribe( | ||
(recipe: Recipe) => { | ||
this.recipe = recipe; | ||
}, | ||
(error) => { | ||
console.error('Error fetching recipe details:', error); | ||
} | ||
); | ||
} | ||
|
||
submitApplication(): void { | ||
if (this.applyForm.valid) { | ||
const firstName = this.applyForm.value.firstName as string; | ||
const lastName = this.applyForm.value.lastName as string; | ||
const email = this.applyForm.value.email as string; | ||
const feedback = this.applyForm.value.feedback as string; | ||
|
||
this.recipeService.submitApplication(firstName, lastName, email, feedback).subscribe( | ||
() => { | ||
console.log('Feedback submitted successfully'); | ||
this.applyForm.reset(); | ||
}, | ||
(error) => { | ||
console.error('Error submitting feedback:', error); | ||
} | ||
); | ||
} else { | ||
console.error('Form is invalid. Please fill in all required fields.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { Recipe } from './recipe.model'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class RecipeService { | ||
|
||
private apiUrl = 'http://localhost:8080/api/recipes'; | ||
|
||
constructor(private http: HttpClient) { } | ||
|
||
getAllRecipes(): Observable<Recipe[]> { | ||
return this.http.get<Recipe[]>(this.apiUrl); | ||
} | ||
|
||
getRecipeById(id: number): Observable<Recipe> { | ||
return this.http.get<Recipe>(`${this.apiUrl}/${id}`); | ||
} | ||
|
||
createRecipe(recipe: Recipe): Observable<Recipe> { | ||
return this.http.post<Recipe>(this.apiUrl, recipe); | ||
} | ||
|
||
updateRecipe(id: number, recipe: Recipe): Observable<Recipe> { | ||
return this.http.put<Recipe>(`${this.apiUrl}/${id}`, recipe); | ||
} | ||
|
||
deleteRecipe(id: number): Observable<void> { | ||
return this.http.delete<void>(`${this.apiUrl}/${id}`); | ||
} | ||
|
||
submitApplication(firstName: string, lastName: string, email: string, feedback: string): Observable<any> { | ||
const application = { firstName, lastName, email, feedback }; | ||
return this.http.post(`${this.apiUrl}/feedback`, application); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.