service api, page home, affiche categ,

install btsrap
This commit is contained in:
Thomas Cardon 2022-01-19 00:20:14 +01:00
parent 4770bd2030
commit e8a924144a
18 changed files with 166 additions and 9 deletions

View file

@ -1,7 +1,11 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HomePageComponent } from './pages/home-page/home-page.component';
const routes: Routes = [];
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomePageComponent },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],

View file

@ -13,6 +13,8 @@ import { AvisRestoComponent } from './filter/components/avis-resto/avis-resto.co
import { CardCategoryComponent } from './card-category/card-category.component';
import { CardRestoComponent } from './card-resto/card-resto.component';
import { FooterComponent } from './footer/footer.component';
import { HomePageComponent } from './pages/home-page/home-page.component';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
@ -26,11 +28,13 @@ import { FooterComponent } from './footer/footer.component';
AvisRestoComponent,
CardCategoryComponent,
CardRestoComponent,
FooterComponent
FooterComponent,
HomePageComponent
],
imports: [
BrowserModule,
AppRoutingModule
AppRoutingModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]

View file

@ -1 +1,7 @@
<p>card-category works!</p>
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="..." alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{ categoryData.libelle }}</h5>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>

View file

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-card-category',
@ -7,6 +7,8 @@ import { Component, OnInit } from '@angular/core';
})
export class CardCategoryComponent implements OnInit {
@Input() categoryData : any;
constructor() { }
ngOnInit(): void {

View file

@ -0,0 +1,3 @@
<div *ngFor="let category of listCategories">
<app-card-category [categoryData]="category"></app-card-category>
</div>

View file

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HomePageComponent } from './home-page.component';
describe('HomePageComponent', () => {
let component: HomePageComponent;
let fixture: ComponentFixture<HomePageComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ HomePageComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(HomePageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -0,0 +1,31 @@
import { Component, OnInit } from '@angular/core';
import { ApiBackService } from 'src/app/services/api-back.service';
@Component({
selector: 'app-home-page',
templateUrl: './home-page.component.html',
styleUrls: ['./home-page.component.scss']
})
export class HomePageComponent implements OnInit {
listCategories : string[];
constructor(private apiBackService : ApiBackService) {
this.listCategories = [];
}
ngOnInit(): void {
this.apiBackService.getCategories().subscribe((listCategories: any[]) => {
console.log(listCategories);
// const listCategoriesLibelle = listCategories.map(
// (category) => category.libelle
// );
this.listCategories = listCategories;
});
}
}

View file

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

View file

@ -0,0 +1,23 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class ApiBackService {
constructor(private httpClient: HttpClient) { }
getRestaurants(): Observable<any[]> {
return this.httpClient.get<any[]>(`${environment.apiUrl}/restaurants`);
}
getCategories(): Observable<any[]>{
return this.httpClient.get<any[]>(`${environment.apiUrl}/types`);
}
}

View file

@ -1,3 +1,4 @@
export const environment = {
production: true
production: true,
apiUrl: ""
};

View file

@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
production: false,
apiUrl: "http://localhost:8080",
};
/*

View file

@ -1 +1,3 @@
/* You can add global styles to this file, and also import other style files */
@import '~bootstrap/scss/bootstrap.scss';
// le tilde agit comme un raccourci vers le node_modules