diff --git a/src/app/app.component.html b/src/app/app.component.html index 0680b43..86ddd42 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1 +1 @@ - + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 18c70af..79dce0a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -14,12 +14,13 @@ import { QualifikatonBearbeitenViewComponent } from "./components/qualifikaton-bearbeiten-view/qualifikaton-bearbeiten-view.component"; import {QualifikatonDetailComponent} from "./components/qualifikaton-detail/qualifikaton-detail.component"; +import {EmployeeListComponent} from "./components/employee-list/employee-list.component"; @Component({ selector: 'app-root', standalone: true, - imports: [RouterOutlet, NavigationBarComponent, EmployeeDetailComponent, LoginViewComponent, MitarbeiterverwaltungViewComponent, MitarbeiterBearbeitenViewComponent, QualifikatonBearbeitenViewComponent, QualifikatonDetailComponent], + imports: [RouterOutlet, NavigationBarComponent, EmployeeDetailComponent, LoginViewComponent, MitarbeiterverwaltungViewComponent, MitarbeiterBearbeitenViewComponent, QualifikatonBearbeitenViewComponent, QualifikatonDetailComponent, EmployeeListComponent], templateUrl: './app.component.html', styleUrl: './app.component.css' }) diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index d0683e9..361a73b 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -4,7 +4,8 @@ import { MitarbeiterverwaltungViewComponent } from "./components/mitarbeiterverw import { EmployeeDetailComponent } from "./components/employee-detail/employee-detail.component"; import { QualifikatonBearbeitenViewComponent } from "./components/qualifikaton-bearbeiten-view/qualifikaton-bearbeiten-view.component"; import { KeycloakAuthGuard } from "keycloak-angular"; -import { AuthGuard } from "./service/auth.service"; +import { AuthGuard } from "/Users/mehdiboudjoudi/WebstormProjects/employeeService/src/app/data_layer/service/auth.service"; +import {EmployeeListComponent} from "./components/employee-list/employee-list.component"; export const routes: Routes = [ { @@ -16,6 +17,11 @@ export const routes: Routes = [ component: MitarbeiterverwaltungViewComponent, canActivate: [AuthGuard], }, + { + path: "mitarbeiterHeidemann", + component: EmployeeListComponent, + canActivate: [AuthGuard], + }, { path: "mitarbeiterdetails", component: EmployeeDetailComponent, diff --git a/src/app/components/employee-list/employee-list.component.css b/src/app/components/employee-list/employee-list.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/employee-list/employee-list.component.html b/src/app/components/employee-list/employee-list.component.html new file mode 100644 index 0000000..217b9d0 --- /dev/null +++ b/src/app/components/employee-list/employee-list.component.html @@ -0,0 +1,9 @@ +

LF10-Starter

+Wenn Sie in der EmployeeListComponent.ts ein gültiges Bearer-Token eintragen, sollten hier die Namen der in der Datenbank gespeicherten Mitarbeiter angezeigt werden! + diff --git a/src/app/components/employee-list/employee-list.component.spec.ts b/src/app/components/employee-list/employee-list.component.spec.ts new file mode 100644 index 0000000..081f497 --- /dev/null +++ b/src/app/components/employee-list/employee-list.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EmployeeListComponent } from './employee-list.component'; + +describe('EmployeeListComponent', () => { + let component: EmployeeListComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [EmployeeListComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(EmployeeListComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/employee-list/employee-list.component.ts b/src/app/components/employee-list/employee-list.component.ts new file mode 100644 index 0000000..918dbc0 --- /dev/null +++ b/src/app/components/employee-list/employee-list.component.ts @@ -0,0 +1,30 @@ + import { Component } from '@angular/core'; + import { CommonModule } from '@angular/common'; + import {Observable, of} from "rxjs"; + import {HttpClient, HttpHeaders} from "@angular/common/http"; + import {Employee} from "../../data_layer/model/employee"; + + @Component({ + selector: 'app-employee-list', + standalone: true, + imports: [CommonModule], + templateUrl: './employee-list.component.html', + styleUrl: './employee-list.component.css' + }) + export class EmployeeListComponent { + bearer = 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICIzUFQ0dldiNno5MnlQWk1EWnBqT1U0RjFVN0lwNi1ELUlqQWVGczJPbGU0In0'; + employees$: Observable; + + constructor(private http: HttpClient) { + this.employees$ = of([]); + this.fetchData(); + } + + fetchData() { + this.employees$ = this.http.get('http://localhost:8089/employees', { + headers: new HttpHeaders() + .set('Content-Type', 'application/json') + .set('Authorization', `Bearer ${this.bearer}`) + }); + } + } diff --git a/src/app/components/mitarbeiterverwaltung-view/mitarbeiterverwaltung-view.component.html b/src/app/components/mitarbeiterverwaltung-view/mitarbeiterverwaltung-view.component.html index baea199..8136fb2 100644 --- a/src/app/components/mitarbeiterverwaltung-view/mitarbeiterverwaltung-view.component.html +++ b/src/app/components/mitarbeiterverwaltung-view/mitarbeiterverwaltung-view.component.html @@ -1,30 +1,18 @@

Employees

+
- diff --git a/src/app/components/mitarbeiterverwaltung-view/mitarbeiterverwaltung-view.component.ts b/src/app/components/mitarbeiterverwaltung-view/mitarbeiterverwaltung-view.component.ts index 3a8f197..e50a6f6 100644 --- a/src/app/components/mitarbeiterverwaltung-view/mitarbeiterverwaltung-view.component.ts +++ b/src/app/components/mitarbeiterverwaltung-view/mitarbeiterverwaltung-view.component.ts @@ -1,12 +1,33 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { EmployeeService } from '../../data_layer/service/mitarbeiter_data_service'; +import { Employee } from '../../data_layer/model/employee'; +import { CommonModule } from '@angular/common'; +import { HttpClientModule } from '@angular/common/http'; @Component({ selector: 'app-mitarbeiterverwaltung-view', - standalone: true, - imports: [], templateUrl: './mitarbeiterverwaltung-view.component.html', - styleUrl: './mitarbeiterverwaltung-view.component.css' + styleUrls: ['./mitarbeiterverwaltung-view.component.css'], + standalone: true, + imports: [CommonModule, HttpClientModule] }) -export class MitarbeiterverwaltungViewComponent { +export class MitarbeiterverwaltungViewComponent implements OnInit { + employees: Employee[] = []; + constructor(private employeeService: EmployeeService) {} + + ngOnInit(): void { + this.fetchEmployees(); + } + + fetchEmployees(): void { + this.employeeService.getAllEmployees().subscribe( + (data: Employee[]) => { + this.employees = data; + }, + (error: any) => { + console.error('Error fetching employees', error); + } + ); + } } diff --git a/src/app/data_layer/model/employee.ts b/src/app/data_layer/model/employee.ts new file mode 100644 index 0000000..e930ff2 --- /dev/null +++ b/src/app/data_layer/model/employee.ts @@ -0,0 +1,13 @@ +export class Employee { + constructor( + public id?: number, + public lastName?: string, + public firstName?: string, + public street?: string, + public postcode?: string, + public city?: string, + public phone?: string, + public skills?: [] + ) { + } +} diff --git a/src/app/service/auth.service.ts b/src/app/data_layer/service/auth.service.ts similarity index 100% rename from src/app/service/auth.service.ts rename to src/app/data_layer/service/auth.service.ts diff --git a/src/app/data_layer/service/mitarbeiter_data_service.ts b/src/app/data_layer/service/mitarbeiter_data_service.ts new file mode 100644 index 0000000..b11d57b --- /dev/null +++ b/src/app/data_layer/service/mitarbeiter_data_service.ts @@ -0,0 +1,24 @@ +// EmployeeService (data_layer/service/mitarbeiter_data_service.ts) +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { Employee } from '../model/employee'; + +@Injectable({ + providedIn: 'root' +}) +export class EmployeeService { + private baseUrl = 'https://employee.szut.dev/api'; + private bearerToken = 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICIzUFQ0dldiNno5MnlQWk1EWnBqT1U0RjFVN0lwNi1ELUlqQWVGczJPbGU0In0'; + + constructor(private http: HttpClient) {} + + getAllEmployees(): Observable { + const endpoint = `${this.baseUrl}/employees`; + const headers = new HttpHeaders({ + 'Authorization': `Bearer ${this.bearerToken}`, + 'Content-Type': 'application/json' + }); + return this.http.get(endpoint, { headers }); + } +} diff --git a/src/app/data_layer/service/qualifikationen_data_service.ts b/src/app/data_layer/service/qualifikationen_data_service.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/main.ts b/src/main.ts index 35b00f3..c684fa1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ +import { HttpClientModule } from '@angular/common/http'; import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; -bootstrapApplication(AppComponent, appConfig) +bootstrapApplication(AppComponent , appConfig,) .catch((err) => console.error(err));