mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 16:03:11 +02:00
feat: added rest of components
This commit is contained in:
parent
3d3c45e048
commit
ed1586a207
@ -1,4 +1,33 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Put, Delete, Param, Body } from '@nestjs/common';
|
||||
import { DanieService } from './danie.service';
|
||||
import { Danie } from '@prisma/client';
|
||||
|
||||
@Controller('danie')
|
||||
export class DanieController {}
|
||||
export class DanieController {
|
||||
constructor(private readonly danieService: DanieService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(): Promise<Danie[]> {
|
||||
return this.danieService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('id') id: string): Promise<Danie | null> {
|
||||
return this.danieService.findOne(+id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() data: { cena: number; kategoria: string; nazwa: string }): Promise<Danie> {
|
||||
return this.danieService.create(data);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(@Param('id') id: string, @Body() data: Partial<Danie>): Promise<Danie> {
|
||||
return this.danieService.update(+id, data);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param('id') id: string): Promise<Danie> {
|
||||
return this.danieService.delete(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DanieService } from './danie.service';
|
||||
import { DanieController } from './danie.controller';
|
||||
import { DatabaseService } from '../database/database.service';
|
||||
|
||||
@Module({
|
||||
providers: [DanieService],
|
||||
providers: [DanieService, DatabaseService],
|
||||
controllers: [DanieController],
|
||||
})
|
||||
export class DanieModule {}
|
||||
|
||||
@ -1,4 +1,37 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Danie } from '@prisma/client';
|
||||
import { DatabaseService } from '../database/database.service';
|
||||
|
||||
@Injectable()
|
||||
export class DanieService {}
|
||||
export class DanieService {
|
||||
constructor(private prisma: DatabaseService) {}
|
||||
|
||||
async findAll(): Promise<Danie[]> {
|
||||
return this.prisma.danie.findMany();
|
||||
}
|
||||
|
||||
async findOne(id: number): Promise<Danie | null> {
|
||||
return this.prisma.danie.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
|
||||
async create(data: { cena: number; kategoria: string; nazwa: string }): Promise<Danie> {
|
||||
return this.prisma.danie.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
async update(id: number, data: Partial<Danie>): Promise<Danie> {
|
||||
return this.prisma.danie.update({
|
||||
where: { id },
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
async delete(id: number): Promise<Danie> {
|
||||
return this.prisma.danie.delete({
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,20 @@
|
||||
import { Route } from '@angular/router';
|
||||
import { RestauracjaComponent } from './restauracja/restauracja.component';
|
||||
import { RecenzjaComponent } from './recenzja/recenzja.component';
|
||||
import { UzytkownikComponent } from './uzytkownik/uzytkownik.component';
|
||||
import { ZamowienieComponent } from './zamowienie/zamowienie.component';
|
||||
import { ZamowioneDanieComponent } from './zamowione-danie/zamowione-danie.component';
|
||||
import { ZnizkaComponent } from './znizka/znizka.component';
|
||||
import { HistoriaZamowienComponent } from './historia-zamowien/historia-zamowien.component';
|
||||
import { DanieComponent } from './danie/danie.component';
|
||||
|
||||
export const appRoutes: Route[] = [
|
||||
{path: 'restauracja', component: RestauracjaComponent}
|
||||
{path: 'restauracja', component: RestauracjaComponent},
|
||||
{path: 'uzytkownik', component: UzytkownikComponent},
|
||||
{path: 'zamowienie', component: ZamowienieComponent},
|
||||
{path: 'zamowione-danie', component: ZamowioneDanieComponent},
|
||||
{path: 'znizka', component: ZnizkaComponent},
|
||||
{path: 'historia-zamowien', component: HistoriaZamowienComponent},
|
||||
{path: 'danie', component: DanieComponent},
|
||||
{path: 'recenzja', component: RecenzjaComponent}
|
||||
];
|
||||
|
||||
@ -1 +1,27 @@
|
||||
<p>danie works!</p>
|
||||
<!-- src/app/danie/danie.component.html -->
|
||||
<div>
|
||||
<h2>Dania List</h2>
|
||||
<ul>
|
||||
<li *ngFor="let danie of dania">
|
||||
{{ danie.nazwa }} - {{ danie.kategoria }} - {{ danie.cena }} PLN
|
||||
<button (click)="startEdit(danie)">Edit</button>
|
||||
<button (click)="deleteDanie(danie.id!)">Delete</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Create Danie</h2>
|
||||
<input [(ngModel)]="newDanie.nazwa" placeholder="Nazwa">
|
||||
<input [(ngModel)]="newDanie.kategoria" placeholder="Kategoria">
|
||||
<input [(ngModel)]="newDanie.cena" placeholder="Cena" type="number">
|
||||
<button (click)="createDanie()">Create</button>
|
||||
|
||||
<div *ngIf="editDanie">
|
||||
<h2>Edit Danie</h2>
|
||||
<input [(ngModel)]="editDanie.nazwa" placeholder="Nazwa">
|
||||
<input [(ngModel)]="editDanie.kategoria" placeholder="Kategoria">
|
||||
<input [(ngModel)]="editDanie.cena" placeholder="Cena" type="number">
|
||||
<button (click)="updateDanie()">Update</button>
|
||||
<button (click)="cancelEdit()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,68 @@
|
||||
import { Component } from '@angular/core';
|
||||
// src/app/danie/danie.component.ts
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
interface Danie {
|
||||
id?: number;
|
||||
cena: number;
|
||||
kategoria: string;
|
||||
nazwa: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-danie',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, HttpClientModule, FormsModule],
|
||||
templateUrl: './danie.component.html',
|
||||
styleUrl: './danie.component.css',
|
||||
})
|
||||
export class DanieComponent {}
|
||||
export class DanieComponent {
|
||||
dania: Danie[] = [];
|
||||
newDanie: Danie = { cena: 0, kategoria: '', nazwa: '' };
|
||||
editDanie: Danie | null = null;
|
||||
private apiUrl = 'http://localhost:3000/api/danie';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadDania();
|
||||
}
|
||||
|
||||
loadDania(): void {
|
||||
this.http.get<Danie[]>(this.apiUrl).subscribe(data => {
|
||||
this.dania = data;
|
||||
});
|
||||
}
|
||||
|
||||
createDanie(): void {
|
||||
this.http.post<Danie>(this.apiUrl, this.newDanie).subscribe(data => {
|
||||
this.dania.push(data);
|
||||
this.newDanie = { cena: 0, kategoria: '', nazwa: '' };
|
||||
});
|
||||
}
|
||||
|
||||
updateDanie(): void {
|
||||
if (this.editDanie && this.editDanie.id) {
|
||||
this.http.put<Danie>(`${this.apiUrl}/${this.editDanie.id}`, this.editDanie).subscribe(data => {
|
||||
this.loadDania();
|
||||
this.editDanie = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteDanie(id: number): void {
|
||||
this.http.delete<Danie>(`${this.apiUrl}/${id}`).subscribe(() => {
|
||||
this.dania = this.dania.filter(d => d.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
startEdit(danie: Danie): void {
|
||||
this.editDanie = { ...danie };
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.editDanie = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1,23 @@
|
||||
<p>historia-zamowien works!</p>
|
||||
<!-- src/app/historia-zamowien/historia-zamowien.component.html -->
|
||||
<div>
|
||||
<h2>Historia Zamowien List</h2>
|
||||
<ul>
|
||||
<li *ngFor="let historia of historiaZamowien">
|
||||
{{ historia.data_zamowienia }}
|
||||
<button (click)="startEdit(historia)">Edit</button>
|
||||
<button (click)="deleteHistoriaZamowien(historia.id!)">Delete</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Create Historia Zamowien</h2>
|
||||
<input [(ngModel)]="newHistoriaZamowien.data_zamowienia" placeholder="Data Zamowienia" type="date">
|
||||
<button (click)="createHistoriaZamowien()">Create</button>
|
||||
|
||||
<div *ngIf="editHistoriaZamowien">
|
||||
<h2>Edit Historia Zamowien</h2>
|
||||
<input [(ngModel)]="editHistoriaZamowien.data_zamowienia" placeholder="Data Zamowienia" type="date">
|
||||
<button (click)="updateHistoriaZamowien()">Update</button>
|
||||
<button (click)="cancelEdit()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,67 @@
|
||||
import { Component } from '@angular/core';
|
||||
// src/app/historia-zamowien/historia-zamowien.component.ts
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
interface HistoriaZamowien {
|
||||
id?: number;
|
||||
data_zamowienia: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-historia-zamowien',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, HttpClientModule, FormsModule],
|
||||
templateUrl: './historia-zamowien.component.html',
|
||||
styleUrl: './historia-zamowien.component.css',
|
||||
})
|
||||
export class HistoriaZamowienComponent {}
|
||||
export class HistoriaZamowienComponent {
|
||||
historiaZamowien: HistoriaZamowien[] = [];
|
||||
newHistoriaZamowien: HistoriaZamowien = { data_zamowienia: '' };
|
||||
editHistoriaZamowien: HistoriaZamowien | null = null;
|
||||
private apiUrl = 'http://localhost:3000/api/historia-zamowien';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadHistoriaZamowien();
|
||||
}
|
||||
|
||||
loadHistoriaZamowien(): void {
|
||||
this.http.get<HistoriaZamowien[]>(this.apiUrl).subscribe(data => {
|
||||
this.historiaZamowien = data;
|
||||
});
|
||||
}
|
||||
|
||||
createHistoriaZamowien(): void {
|
||||
this.http.post<HistoriaZamowien>(this.apiUrl, this.newHistoriaZamowien).subscribe(data => {
|
||||
this.historiaZamowien.push(data);
|
||||
this.newHistoriaZamowien = { data_zamowienia: '' };
|
||||
});
|
||||
}
|
||||
|
||||
updateHistoriaZamowien(): void {
|
||||
if (this.editHistoriaZamowien && this.editHistoriaZamowien.id) {
|
||||
this.http.put<HistoriaZamowien>(`${this.apiUrl}/${this.editHistoriaZamowien.id}`, this.editHistoriaZamowien).subscribe(data => {
|
||||
this.loadHistoriaZamowien();
|
||||
this.editHistoriaZamowien = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteHistoriaZamowien(id: number): void {
|
||||
this.http.delete<HistoriaZamowien>(`${this.apiUrl}/${id}`).subscribe(() => {
|
||||
this.historiaZamowien = this.historiaZamowien.filter(h => h.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
startEdit(historia: HistoriaZamowien): void {
|
||||
this.editHistoriaZamowien = { ...historia };
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.editHistoriaZamowien = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1 +1,29 @@
|
||||
<p>recenzja works!</p>
|
||||
<!-- src/app/recenzja/recenzja.component.html -->
|
||||
<div>
|
||||
<h2>Recenzja List</h2>
|
||||
<ul>
|
||||
<li *ngFor="let recenzja of recenzje">
|
||||
<strong>{{ recenzja.wartosc }}</strong> - {{ recenzja.tekst }} (Restauracja ID: {{ recenzja.restauracjaId }}, Uzytkownik ID: {{ recenzja.uzytkownikId }})
|
||||
<button (click)="startEdit(recenzja)">Edit</button>
|
||||
<button (click)="deleteRecenzja(recenzja.id!)">Delete</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Create Recenzja</h2>
|
||||
<textarea [(ngModel)]="newRecenzja.tekst" placeholder="Tekst"></textarea>
|
||||
<input [(ngModel)]="newRecenzja.wartosc" placeholder="Wartosc" type="number">
|
||||
<input [(ngModel)]="newRecenzja.restauracjaId" placeholder="Restauracja ID" type="number">
|
||||
<input [(ngModel)]="newRecenzja.uzytkownikId" placeholder="Uzytkownik ID" type="number">
|
||||
<button (click)="createRecenzja()">Create</button>
|
||||
|
||||
<div *ngIf="editRecenzja">
|
||||
<h2>Edit Recenzja</h2>
|
||||
<textarea [(ngModel)]="editRecenzja.tekst" placeholder="Tekst"></textarea>
|
||||
<input [(ngModel)]="editRecenzja.wartosc" placeholder="Wartosc" type="number">
|
||||
<input [(ngModel)]="editRecenzja.restauracjaId" placeholder="Restauracja ID" type="number">
|
||||
<input [(ngModel)]="editRecenzja.uzytkownikId" placeholder="Uzytkownik ID" type="number">
|
||||
<button (click)="updateRecenzja()">Update</button>
|
||||
<button (click)="cancelEdit()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,67 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
interface Recenzja {
|
||||
id?: number;
|
||||
tekst: string;
|
||||
wartosc: number;
|
||||
restauracjaId: number;
|
||||
uzytkownikId: number;
|
||||
}
|
||||
@Component({
|
||||
selector: 'app-recenzja',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, FormsModule, HttpClientModule],
|
||||
templateUrl: './recenzja.component.html',
|
||||
styleUrl: './recenzja.component.css',
|
||||
})
|
||||
export class RecenzjaComponent {}
|
||||
export class RecenzjaComponent {
|
||||
recenzje: Recenzja[] = [];
|
||||
newRecenzja: Recenzja = { tekst: '', wartosc: 0, restauracjaId: 0, uzytkownikId: 0 };
|
||||
editRecenzja: Recenzja | null = null;
|
||||
private apiUrl = 'http://localhost:3000/api/recenzja';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadRecenzje();
|
||||
}
|
||||
|
||||
loadRecenzje(): void {
|
||||
this.http.get<Recenzja[]>(this.apiUrl).subscribe(data => {
|
||||
this.recenzje = data;
|
||||
});
|
||||
}
|
||||
|
||||
createRecenzja(): void {
|
||||
this.http.post<Recenzja>(this.apiUrl, this.newRecenzja).subscribe(data => {
|
||||
this.recenzje.push(data);
|
||||
this.newRecenzja = { tekst: '', wartosc: 0, restauracjaId: 0, uzytkownikId: 0 };
|
||||
});
|
||||
}
|
||||
|
||||
updateRecenzja(): void {
|
||||
if (this.editRecenzja && this.editRecenzja.id) {
|
||||
this.http.put<Recenzja>(`${this.apiUrl}/${this.editRecenzja.id}`, this.editRecenzja).subscribe(data => {
|
||||
this.loadRecenzje();
|
||||
this.editRecenzja = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteRecenzja(id: number): void {
|
||||
this.http.delete<Recenzja>(`${this.apiUrl}/${id}`).subscribe(() => {
|
||||
this.recenzje = this.recenzje.filter(r => r.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
startEdit(recenzja: Recenzja): void {
|
||||
this.editRecenzja = { ...recenzja };
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.editRecenzja = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1,29 @@
|
||||
<p>uzytkownik works!</p>
|
||||
<!-- src/app/uzytkownik/uzytkownik.component.html -->
|
||||
<div>
|
||||
<h2>Uzytkownik List</h2>
|
||||
<ul>
|
||||
<li *ngFor="let uzytkownik of uzytkownicy">
|
||||
{{ uzytkownik.imie }} {{ uzytkownik.nazwisko }} - {{ uzytkownik.adres }} (Historia Zamowien ID: {{ uzytkownik.Historia_zamowienId }})
|
||||
<button (click)="startEdit(uzytkownik)">Edit</button>
|
||||
<button (click)="deleteUzytkownik(uzytkownik.id!)">Delete</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Create Uzytkownik</h2>
|
||||
<input [(ngModel)]="newUzytkownik.imie" placeholder="Imie">
|
||||
<input [(ngModel)]="newUzytkownik.nazwisko" placeholder="Nazwisko">
|
||||
<input [(ngModel)]="newUzytkownik.adres" placeholder="Adres">
|
||||
<input [(ngModel)]="newUzytkownik.Historia_zamowienId" placeholder="Historia Zamowien ID" type="number">
|
||||
<button (click)="createUzytkownik()">Create</button>
|
||||
|
||||
<div *ngIf="editUzytkownik">
|
||||
<h2>Edit Uzytkownik</h2>
|
||||
<input [(ngModel)]="editUzytkownik.imie" placeholder="Imie">
|
||||
<input [(ngModel)]="editUzytkownik.nazwisko" placeholder="Nazwisko">
|
||||
<input [(ngModel)]="editUzytkownik.adres" placeholder="Adres">
|
||||
<input [(ngModel)]="editUzytkownik.Historia_zamowienId" placeholder="Historia Zamowien ID" type="number">
|
||||
<button (click)="updateUzytkownik()">Update</button>
|
||||
<button (click)="cancelEdit()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,69 @@
|
||||
import { Component } from '@angular/core';
|
||||
// src/app/uzytkownik/uzytkownik.component.ts
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
interface Uzytkownik {
|
||||
id?: number;
|
||||
imie: string;
|
||||
nazwisko: string;
|
||||
adres: string;
|
||||
Historia_zamowienId: number;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-uzytkownik',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, FormsModule, HttpClientModule],
|
||||
templateUrl: './uzytkownik.component.html',
|
||||
styleUrl: './uzytkownik.component.css',
|
||||
})
|
||||
export class UzytkownikComponent {}
|
||||
export class UzytkownikComponent {
|
||||
uzytkownicy: Uzytkownik[] = [];
|
||||
newUzytkownik: Uzytkownik = { imie: '', nazwisko: '', adres: '', Historia_zamowienId: 0 };
|
||||
editUzytkownik: Uzytkownik | null = null;
|
||||
private apiUrl = 'http://localhost:3000/api/uzytkownik';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadUzytkownicy();
|
||||
}
|
||||
|
||||
loadUzytkownicy(): void {
|
||||
this.http.get<Uzytkownik[]>(this.apiUrl).subscribe(data => {
|
||||
this.uzytkownicy = data;
|
||||
});
|
||||
}
|
||||
|
||||
createUzytkownik(): void {
|
||||
this.http.post<Uzytkownik>(this.apiUrl, this.newUzytkownik).subscribe(data => {
|
||||
this.uzytkownicy.push(data);
|
||||
this.newUzytkownik = { imie: '', nazwisko: '', adres: '', Historia_zamowienId: 0 };
|
||||
});
|
||||
}
|
||||
|
||||
updateUzytkownik(): void {
|
||||
if (this.editUzytkownik && this.editUzytkownik.id) {
|
||||
this.http.put<Uzytkownik>(`${this.apiUrl}/${this.editUzytkownik.id}`, this.editUzytkownik).subscribe(data => {
|
||||
this.loadUzytkownicy();
|
||||
this.editUzytkownik = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteUzytkownik(id: number): void {
|
||||
this.http.delete<Uzytkownik>(`${this.apiUrl}/${id}`).subscribe(() => {
|
||||
this.uzytkownicy = this.uzytkownicy.filter(u => u.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
startEdit(uzytkownik: Uzytkownik): void {
|
||||
this.editUzytkownik = { ...uzytkownik };
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.editUzytkownik = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1,23 @@
|
||||
<p>zamowienie works!</p>
|
||||
<!-- src/app/zamowienie/zamowienie.component.html -->
|
||||
<div>
|
||||
<h2>Zamowienia List</h2>
|
||||
<ul>
|
||||
<li *ngFor="let zamowienie of zamowienia">
|
||||
{{ zamowienie.status }}
|
||||
<button (click)="startEdit(zamowienie)">Edit</button>
|
||||
<button (click)="deleteZamowienie(zamowienie.id!)">Delete</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Create Zamowienie</h2>
|
||||
<input [(ngModel)]="newZamowienie.status" placeholder="Status">
|
||||
<button (click)="createZamowienie()">Create</button>
|
||||
|
||||
<div *ngIf="editZamowienie">
|
||||
<h2>Edit Zamowienie</h2>
|
||||
<input [(ngModel)]="editZamowienie.status" placeholder="Status">
|
||||
<button (click)="updateZamowienie()">Update</button>
|
||||
<button (click)="cancelEdit()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,67 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
interface Zamowienie {
|
||||
id?: number;
|
||||
status: string;
|
||||
}
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-zamowienie',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, HttpClientModule, FormsModule],
|
||||
templateUrl: './zamowienie.component.html',
|
||||
styleUrl: './zamowienie.component.css',
|
||||
})
|
||||
export class ZamowienieComponent {}
|
||||
export class ZamowienieComponent {
|
||||
zamowienia: Zamowienie[] = [];
|
||||
newZamowienie: Zamowienie = { status: '' };
|
||||
editZamowienie: Zamowienie | null = null;
|
||||
private apiUrl = 'http://localhost:3000/api/zamowienie';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadZamowienia();
|
||||
}
|
||||
|
||||
loadZamowienia(): void {
|
||||
this.http.get<Zamowienie[]>(this.apiUrl).subscribe(data => {
|
||||
this.zamowienia = data;
|
||||
});
|
||||
}
|
||||
|
||||
createZamowienie(): void {
|
||||
this.http.post<Zamowienie>(this.apiUrl, this.newZamowienie).subscribe(data => {
|
||||
this.zamowienia.push(data);
|
||||
this.newZamowienie = { status: '' };
|
||||
});
|
||||
}
|
||||
|
||||
updateZamowienie(): void {
|
||||
if (this.editZamowienie && this.editZamowienie.id) {
|
||||
this.http.put<Zamowienie>(`${this.apiUrl}/${this.editZamowienie.id}`, this.editZamowienie).subscribe(data => {
|
||||
this.loadZamowienia();
|
||||
this.editZamowienie = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteZamowienie(id: number): void {
|
||||
this.http.delete<Zamowienie>(`${this.apiUrl}/${id}`).subscribe(() => {
|
||||
this.zamowienia = this.zamowienia.filter(z => z.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
startEdit(zamowienie: Zamowienie): void {
|
||||
this.editZamowienie = { ...zamowienie };
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.editZamowienie = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1,23 @@
|
||||
<p>zamowione-danie works!</p>
|
||||
<!-- src/app/zamowione-danie/zamowione-danie.component.html -->
|
||||
<div>
|
||||
<h2>Zamowione Dania List</h2>
|
||||
<ul>
|
||||
<li *ngFor="let zamowioneDanie of zamowioneDania">
|
||||
Zamowienie ID: {{ zamowioneDanie.zamowienieId }}
|
||||
<button (click)="startEdit(zamowioneDanie)">Edit</button>
|
||||
<button (click)="deleteZamowioneDanie(zamowioneDanie.id!)">Delete</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Create Zamowione Danie</h2>
|
||||
<input [(ngModel)]="newZamowioneDanie.zamowienieId" placeholder="Zamowienie ID" type="number">
|
||||
<button (click)="createZamowioneDanie()">Create</button>
|
||||
|
||||
<div *ngIf="editZamowioneDanie">
|
||||
<h2>Edit Zamowione Danie</h2>
|
||||
<input [(ngModel)]="editZamowioneDanie.zamowienieId" placeholder="Zamowienie ID" type="number">
|
||||
<button (click)="updateZamowioneDanie()">Update</button>
|
||||
<button (click)="cancelEdit()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,66 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
|
||||
interface ZamowioneDanie {
|
||||
id?: number;
|
||||
zamowienieId: number;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-zamowione-danie',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, HttpClientModule, FormsModule],
|
||||
templateUrl: './zamowione-danie.component.html',
|
||||
styleUrl: './zamowione-danie.component.css',
|
||||
})
|
||||
export class ZamowioneDanieComponent {}
|
||||
export class ZamowioneDanieComponent {
|
||||
zamowioneDania: ZamowioneDanie[] = [];
|
||||
newZamowioneDanie: ZamowioneDanie = { zamowienieId: 0 };
|
||||
editZamowioneDanie: ZamowioneDanie | null = null;
|
||||
private apiUrl = 'http://localhost:3000/api/zamowione-danie';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadZamowioneDania();
|
||||
}
|
||||
|
||||
loadZamowioneDania(): void {
|
||||
this.http.get<ZamowioneDanie[]>(this.apiUrl).subscribe(data => {
|
||||
this.zamowioneDania = data;
|
||||
});
|
||||
}
|
||||
|
||||
createZamowioneDanie(): void {
|
||||
this.http.post<ZamowioneDanie>(this.apiUrl, this.newZamowioneDanie).subscribe(data => {
|
||||
this.zamowioneDania.push(data);
|
||||
this.newZamowioneDanie = { zamowienieId: 0 };
|
||||
});
|
||||
}
|
||||
|
||||
updateZamowioneDanie(): void {
|
||||
if (this.editZamowioneDanie && this.editZamowioneDanie.id) {
|
||||
this.http.put<ZamowioneDanie>(`${this.apiUrl}/${this.editZamowioneDanie.id}`, this.editZamowioneDanie).subscribe(data => {
|
||||
this.loadZamowioneDania();
|
||||
this.editZamowioneDanie = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteZamowioneDanie(id: number): void {
|
||||
this.http.delete<ZamowioneDanie>(`${this.apiUrl}/${id}`).subscribe(() => {
|
||||
this.zamowioneDania = this.zamowioneDania.filter(z => z.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
startEdit(zamowioneDanie: ZamowioneDanie): void {
|
||||
this.editZamowioneDanie = { ...zamowioneDanie };
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.editZamowioneDanie = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1,29 @@
|
||||
<p>znizka works!</p>
|
||||
<!-- src/app/znizka/znizka.component.html -->
|
||||
<div>
|
||||
<h2>Znizki List</h2>
|
||||
<ul>
|
||||
<li *ngFor="let znizka of znizki">
|
||||
{{ znizka.kod }} - {{ znizka.wartosc }} PLN - {{ znizka.czy_dostepna ? 'Dostepna' : 'Niedostepna' }} - Restauracja ID: {{ znizka.restauracjaId }}
|
||||
<button (click)="startEdit(znizka)">Edit</button>
|
||||
<button (click)="deleteZnizka(znizka.id!)">Delete</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Create Znizka</h2>
|
||||
<input [(ngModel)]="newZnizka.kod" placeholder="Kod">
|
||||
<input [(ngModel)]="newZnizka.wartosc" placeholder="Wartosc" type="number">
|
||||
<input [(ngModel)]="newZnizka.czy_dostepna" type="checkbox"> Dostepna
|
||||
<input [(ngModel)]="newZnizka.restauracjaId" placeholder="Restauracja ID" type="number">
|
||||
<button (click)="createZnizka()">Create</button>
|
||||
|
||||
<div *ngIf="editZnizka">
|
||||
<h2>Edit Znizka</h2>
|
||||
<input [(ngModel)]="editZnizka.kod" placeholder="Kod">
|
||||
<input [(ngModel)]="editZnizka.wartosc" placeholder="Wartosc" type="number">
|
||||
<input [(ngModel)]="editZnizka.czy_dostepna" type="checkbox"> Dostepna
|
||||
<input [(ngModel)]="editZnizka.restauracjaId" placeholder="Restauracja ID" type="number">
|
||||
<button (click)="updateZnizka()">Update</button>
|
||||
<button (click)="cancelEdit()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,69 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
interface Znizka {
|
||||
id?: number;
|
||||
kod: string;
|
||||
wartosc: number;
|
||||
czy_dostepna: boolean;
|
||||
restauracjaId: number;
|
||||
}
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-znizka',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, FormsModule, HttpClientModule],
|
||||
templateUrl: './znizka.component.html',
|
||||
styleUrl: './znizka.component.css',
|
||||
})
|
||||
export class ZnizkaComponent {}
|
||||
export class ZnizkaComponent {
|
||||
znizki: Znizka[] = [];
|
||||
newZnizka: Znizka = { kod: '', wartosc: 0, czy_dostepna: true, restauracjaId: 0 };
|
||||
editZnizka: Znizka | null = null;
|
||||
private apiUrl = 'http://localhost:3000/api/znizka';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadZnizki();
|
||||
}
|
||||
|
||||
loadZnizki(): void {
|
||||
this.http.get<Znizka[]>(this.apiUrl).subscribe(data => {
|
||||
this.znizki = data;
|
||||
});
|
||||
}
|
||||
|
||||
createZnizka(): void {
|
||||
this.http.post<Znizka>(this.apiUrl, this.newZnizka).subscribe(data => {
|
||||
this.znizki.push(data);
|
||||
this.newZnizka = { kod: '', wartosc: 0, czy_dostepna: true, restauracjaId: 0 };
|
||||
});
|
||||
}
|
||||
|
||||
updateZnizka(): void {
|
||||
if (this.editZnizka && this.editZnizka.id) {
|
||||
this.http.put<Znizka>(`${this.apiUrl}/${this.editZnizka.id}`, this.editZnizka).subscribe(data => {
|
||||
this.loadZnizki();
|
||||
this.editZnizka = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteZnizka(id: number): void {
|
||||
this.http.delete<Znizka>(`${this.apiUrl}/${id}`).subscribe(() => {
|
||||
this.znizki = this.znizki.filter(z => z.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
startEdit(znizka: Znizka): void {
|
||||
this.editZnizka = { ...znizka };
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.editZnizka = null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user