mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 17:43:03 +02:00
feat: generated fake data, created menu for routing
This commit is contained in:
parent
ed1586a207
commit
e5a98255cb
1
monorepo/apps/backend/.env_template
Normal file
1
monorepo/apps/backend/.env_template
Normal file
@ -0,0 +1 @@
|
|||||||
|
DATABASE_URL="postgresql://postgres:password@localhost:5432/mydb?schema=public"
|
||||||
@ -1,10 +1,19 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
|
import { FakeDataService } from './fake-data/fake-data.service';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController {
|
export class AppController {
|
||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly appService: AppService,
|
||||||
|
private readonly fakeDataService: FakeDataService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Get('generate-fake-data')
|
||||||
|
async generateFakeData() {
|
||||||
|
await this.fakeDataService.generateFakeData();
|
||||||
|
return { message: 'Fake data generated successfully' };
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
getData() {
|
getData() {
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { DanieModule } from './danie/danie.module';
|
|||||||
import { ZamowioneDanieModule } from './zamowione-danie/zamowione-danie.module';
|
import { ZamowioneDanieModule } from './zamowione-danie/zamowione-danie.module';
|
||||||
import { ZamowienieModule } from './zamowienie/zamowienie.module';
|
import { ZamowienieModule } from './zamowienie/zamowienie.module';
|
||||||
import { ZnizkaModule } from './znizka/znizka.module';
|
import { ZnizkaModule } from './znizka/znizka.module';
|
||||||
|
import { FakeDataService } from './fake-data/fake-data.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@ -25,6 +26,6 @@ import { ZnizkaModule } from './znizka/znizka.module';
|
|||||||
ZnizkaModule,
|
ZnizkaModule,
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService, FakeDataService],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { FakeDataService } from './fake-data.service';
|
||||||
|
|
||||||
|
describe('FakeDataService', () => {
|
||||||
|
let service: FakeDataService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [FakeDataService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<FakeDataService>(FakeDataService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
90
monorepo/apps/backend/src/app/fake-data/fake-data.service.ts
Normal file
90
monorepo/apps/backend/src/app/fake-data/fake-data.service.ts
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { DatabaseService } from '../database/database.service';
|
||||||
|
import { faker } from '@faker-js/faker';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class FakeDataService {
|
||||||
|
constructor(private prisma: DatabaseService) {}
|
||||||
|
|
||||||
|
async generateFakeData() {
|
||||||
|
// Generate fake Restauracja
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
await this.prisma.restauracja.create({
|
||||||
|
data: {
|
||||||
|
adres: faker.location.streetAddress(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate fake Uzytkownik and Historia_zamowien
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
const historia = await this.prisma.historia_zamowien.create({
|
||||||
|
data: {
|
||||||
|
data_zamowienia: faker.date.past(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.prisma.uzytkownik.create({
|
||||||
|
data: {
|
||||||
|
imie: faker.person.firstName(),
|
||||||
|
nazwisko: faker.person.lastName(),
|
||||||
|
adres: faker.location.streetAddress(),
|
||||||
|
Historia_zamowienId: historia.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate fake Danie
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
await this.prisma.danie.create({
|
||||||
|
data: {
|
||||||
|
cena: faker.number.int({ min: 10, max: 100 }),
|
||||||
|
kategoria: faker.commerce.department(),
|
||||||
|
nazwa: faker.commerce.productName(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate fake Zamowienie and Zamowione_danie
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
const zamowienie = await this.prisma.zamowienie.create({
|
||||||
|
data: {
|
||||||
|
status: faker.helpers.arrayElement(['Pending', 'Completed', 'Cancelled']),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.prisma.zamowione_danie.create({
|
||||||
|
data: {
|
||||||
|
zamowienieId: zamowienie.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate fake Znizka
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
const restauracja = await this.prisma.restauracja.findFirst();
|
||||||
|
await this.prisma.znizka.create({
|
||||||
|
data: {
|
||||||
|
kod: faker.string.alphanumeric(10),
|
||||||
|
wartosc: faker.number.int({ min: 10, max: 50 }),
|
||||||
|
czy_dostepna: faker.datatype.boolean(),
|
||||||
|
restauracjaId: restauracja.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate fake Recenzja
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
const restauracja = await this.prisma.restauracja.findFirst();
|
||||||
|
const uzytkownik = await this.prisma.uzytkownik.findFirst();
|
||||||
|
await this.prisma.recenzja.create({
|
||||||
|
data: {
|
||||||
|
tekst: faker.lorem.sentences(),
|
||||||
|
wartosc: faker.number.int({ min: 1, max: 5 }),
|
||||||
|
restauracjaId: restauracja.id,
|
||||||
|
uzytkownikId: uzytkownik.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,16 +8,26 @@
|
|||||||
"targets": {
|
"targets": {
|
||||||
"build": {
|
"build": {
|
||||||
"executor": "@angular-devkit/build-angular:browser",
|
"executor": "@angular-devkit/build-angular:browser",
|
||||||
"outputs": ["{options.outputPath}"],
|
"outputs": [
|
||||||
|
"{options.outputPath}"
|
||||||
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"outputPath": "dist/apps/frontend",
|
"outputPath": "dist/apps/frontend",
|
||||||
"index": "apps/frontend/src/index.html",
|
"index": "apps/frontend/src/index.html",
|
||||||
"main": "apps/frontend/src/main.ts",
|
"main": "apps/frontend/src/main.ts",
|
||||||
"polyfills": ["zone.js"],
|
"polyfills": [
|
||||||
|
"zone.js"
|
||||||
|
],
|
||||||
"tsConfig": "apps/frontend/tsconfig.app.json",
|
"tsConfig": "apps/frontend/tsconfig.app.json",
|
||||||
"inlineStyleLanguage": "scss",
|
"inlineStyleLanguage": "scss",
|
||||||
"assets": ["apps/frontend/src/favicon.ico", "apps/frontend/src/assets"],
|
"assets": [
|
||||||
"styles": ["apps/frontend/src/styles.scss"],
|
"apps/frontend/src/favicon.ico",
|
||||||
|
"apps/frontend/src/assets"
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"@angular/material/prebuilt-themes/azure-blue.css",
|
||||||
|
"apps/frontend/src/styles.scss"
|
||||||
|
],
|
||||||
"scripts": []
|
"scripts": []
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
@ -70,7 +80,9 @@
|
|||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
"executor": "@nx/jest:jest",
|
"executor": "@nx/jest:jest",
|
||||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
"outputs": [
|
||||||
|
"{workspaceRoot}/coverage/{projectRoot}"
|
||||||
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"jestConfig": "apps/frontend/jest.config.ts"
|
"jestConfig": "apps/frontend/jest.config.ts"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +1,20 @@
|
|||||||
<router-outlet></router-outlet>
|
<div class="home-container">
|
||||||
|
<mat-toolbar color="primary">
|
||||||
|
<button mat-button [matMenuTriggerFor]="menu">
|
||||||
|
<mat-icon> menu </mat-icon>
|
||||||
|
<span> Menu </span>
|
||||||
|
</button>
|
||||||
|
<span class="spacer"></span>
|
||||||
|
<span>Smaczne.pl</span>
|
||||||
|
<mat-menu #menu="matMenu">
|
||||||
|
@for(item of menuItems; track item) {
|
||||||
|
<button mat-menu-item [routerLink]="item.path">
|
||||||
|
<mat-icon>{{ item.icon }}</mat-icon>
|
||||||
|
<span>{{ item.title }}</span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</mat-menu>
|
||||||
|
</mat-toolbar>
|
||||||
|
</div>
|
||||||
|
<router-outlet></router-outlet>
|
||||||
|
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
.home-container {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mat-toolbar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spacer {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mat-menu-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mat-menu-item mat-icon {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,13 +1,38 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { RouterModule } from '@angular/router';
|
import { RouterModule } from '@angular/router';
|
||||||
|
import {MatGridListModule} from '@angular/material/grid-list';
|
||||||
|
import {MatCardModule} from '@angular/material/card';
|
||||||
|
import { MatButtonModule } from '@angular/material/button'
|
||||||
|
import {MatTabsModule} from '@angular/material/tabs';
|
||||||
|
import {MatMenuModule} from '@angular/material/menu';
|
||||||
|
import { MatToolbarModule } from '@angular/material/toolbar'
|
||||||
|
import { MatIconModule } from '@angular/material/icon'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [RouterModule],
|
imports: [RouterModule, MatGridListModule, MatCardModule, MatButtonModule, MatTabsModule, MatMenuModule, MatToolbarModule,
|
||||||
|
MatIconModule
|
||||||
|
],
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
styleUrl: './app.component.scss',
|
styleUrl: './app.component.scss',
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
title = 'frontend';
|
title = 'frontend';
|
||||||
|
|
||||||
|
menuItems = [
|
||||||
|
{ title: 'Danie', path: '/danie', icon: 'restaurant' },
|
||||||
|
{ title: 'Historia Zamówien', path: '/historia-zamowien', icon: 'history' },
|
||||||
|
{ title: 'Recenzja', path: '/recenzja', icon: 'rate_review' },
|
||||||
|
{ title: 'Restauracja', path: '/restauracja', icon: 'store' },
|
||||||
|
{ title: 'Użytkownik', path: '/uzytkownik', icon: 'person' },
|
||||||
|
{ title: 'Zamówienie', path: '/zamowienie', icon: 'receipt' },
|
||||||
|
{ title: 'Zamówione Danie', path: '/zamowione-danie', icon: 'local_dining' },
|
||||||
|
{ title: 'Zniżka', path: '/znizka', icon: 'local_offer' }
|
||||||
|
];
|
||||||
|
|
||||||
|
activeLink = this.menuItems[0].path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { ApplicationConfig } from '@angular/core';
|
import { ApplicationConfig } from '@angular/core';
|
||||||
import { provideRouter } from '@angular/router';
|
import { provideRouter } from '@angular/router';
|
||||||
import { appRoutes } from './app.routes';
|
import { appRoutes } from './app.routes';
|
||||||
|
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [provideRouter(appRoutes)],
|
providers: [provideRouter(appRoutes), provideAnimationsAsync()],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,8 +6,10 @@
|
|||||||
<base href="/" />
|
<base href="/" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||||
</head>
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
|
||||||
<body>
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body class="mat-typography">
|
||||||
<app-root></app-root>
|
<app-root></app-root>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -1 +1,4 @@
|
|||||||
/* You can add global styles to this file, and also import other style files */
|
/* You can add global styles to this file, and also import other style files */
|
||||||
|
|
||||||
|
html, body { height: 100%; }
|
||||||
|
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
|
||||||
|
|||||||
41
monorepo/create_database.sh
Executable file
41
monorepo/create_database.sh
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Define variables
|
||||||
|
DB_USER="postgres"
|
||||||
|
DB_PASSWORD="password"
|
||||||
|
DB_NAME="mydb"
|
||||||
|
DB_SCHEMA="public"
|
||||||
|
DB_PORT="5432"
|
||||||
|
|
||||||
|
# Update the system and install PostgreSQL
|
||||||
|
sudo pacman -Syu --noconfirm
|
||||||
|
sudo pacman -S --noconfirm postgresql
|
||||||
|
|
||||||
|
# Initialize the database cluster
|
||||||
|
sudo -iu postgres initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'
|
||||||
|
|
||||||
|
# Start and enable PostgreSQL service
|
||||||
|
sudo systemctl start postgresql
|
||||||
|
sudo systemctl enable postgresql
|
||||||
|
|
||||||
|
# Switch to the postgres user to set up the database and user
|
||||||
|
sudo -iu postgres psql <<EOF
|
||||||
|
ALTER USER $DB_USER WITH PASSWORD '$DB_PASSWORD';
|
||||||
|
CREATE DATABASE $DB_NAME;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Modify pg_hba.conf to allow password authentication
|
||||||
|
sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = 'localhost'/g" /var/lib/postgres/data/postgresql.conf
|
||||||
|
sudo sed -i "s/peer/md5/g" /var/lib/postgres/data/pg_hba.conf
|
||||||
|
sudo sed -i "s/ident/md5/g" /var/lib/postgres/data/pg_hba.conf
|
||||||
|
|
||||||
|
# Restart PostgreSQL to apply changes
|
||||||
|
sudo systemctl restart postgresql
|
||||||
|
|
||||||
|
# Export the DATABASE_URL
|
||||||
|
export DATABASE_URL="postgresql://$DB_USER:$DB_PASSWORD@localhost:$DB_PORT/$DB_NAME?schema=$DB_SCHEMA"
|
||||||
|
|
||||||
|
# Print the DATABASE_URL to verify
|
||||||
|
echo "DATABASE_URL=\"$DATABASE_URL\""
|
||||||
|
|
||||||
|
echo "PostgreSQL setup is complete. The database is accessible at the specified URL."
|
||||||
@ -6,10 +6,12 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "18.0.1",
|
"@angular/animations": "18.0.1",
|
||||||
|
"@angular/cdk": "^18.0.3",
|
||||||
"@angular/common": "18.0.1",
|
"@angular/common": "18.0.1",
|
||||||
"@angular/compiler": "18.0.1",
|
"@angular/compiler": "18.0.1",
|
||||||
"@angular/core": "18.0.1",
|
"@angular/core": "18.0.1",
|
||||||
"@angular/forms": "18.0.1",
|
"@angular/forms": "18.0.1",
|
||||||
|
"@angular/material": "^18.0.3",
|
||||||
"@angular/platform-browser": "18.0.1",
|
"@angular/platform-browser": "18.0.1",
|
||||||
"@angular/platform-browser-dynamic": "18.0.1",
|
"@angular/platform-browser-dynamic": "18.0.1",
|
||||||
"@angular/router": "18.0.1",
|
"@angular/router": "18.0.1",
|
||||||
@ -35,6 +37,7 @@
|
|||||||
"@angular/cli": "~17.3.0",
|
"@angular/cli": "~17.3.0",
|
||||||
"@angular/compiler-cli": "18.0.1",
|
"@angular/compiler-cli": "18.0.1",
|
||||||
"@angular/language-service": "18.0.1",
|
"@angular/language-service": "18.0.1",
|
||||||
|
"@faker-js/faker": "^8.4.1",
|
||||||
"@nestjs/schematics": "^10.0.1",
|
"@nestjs/schematics": "^10.0.1",
|
||||||
"@nestjs/testing": "^10.0.2",
|
"@nestjs/testing": "^10.0.2",
|
||||||
"@nx/angular": "19.1.1",
|
"@nx/angular": "19.1.1",
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
cd apps/backend
|
||||||
|
npx prisma generate
|
||||||
|
cd ../../
|
||||||
nx run-many --target=serve --projects=frontend,backend --parallel
|
nx run-many --target=serve --projects=frontend,backend --parallel
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user