Skip to content

Commit d7f7355

Browse files
Merge pull request #8 from beginwebdev2002/feat/api-integration-4669589981061929666
feat: integrate frontend with nestjs api and add swagger documentation
2 parents cdfb291 + 3bca132 commit d7f7355

20 files changed

Lines changed: 139 additions & 121 deletions

File tree

backend/src/modules/admin-settings/presentation/admin-settings.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
12
import { Controller, Get, Body, Put, Post, Delete } from '@nestjs/common';
23
import { AdminSettingsService } from '../application/admin-settings.service';
34
import { AdminSettings } from '../domain/admin-settings.entity';
45
import { UpdateAdminSettingsDto } from './dto/update-admin-settings.dto';
56
import { CreateAdminSettingsDto } from './dto/create-admin-settings.dto';
67

8+
@ApiTags('Admin Settings')
79
@Controller('admin-settings')
810
export class AdminSettingsController {
911
constructor(private readonly adminSettingsService: AdminSettingsService) {}
1012

13+
@ApiOperation({ summary: 'Get all' }) @ApiResponse({ status: 200 })
1114
@Get()
1215
async getSettings(): Promise<AdminSettings | null> {
1316
return this.adminSettingsService.getSettings();
1417
}
1518

19+
@ApiOperation({ summary: 'Create' }) @ApiResponse({ status: 201 })
1620
@Post()
1721
async createSettings(
1822
@Body() createAdminSettingsDto: CreateAdminSettingsDto,
@@ -24,6 +28,7 @@ export class AdminSettingsController {
2428
);
2529
}
2630

31+
@ApiOperation({ summary: 'Update' }) @ApiResponse({ status: 200 })
2732
@Put()
2833
async updateSettings(
2934
@Body() updateAdminSettingsDto: UpdateAdminSettingsDto,
@@ -37,6 +42,7 @@ export class AdminSettingsController {
3742
return this.adminSettingsService.updateSettings(settings);
3843
}
3944

45+
@ApiOperation({ summary: 'Delete' }) @ApiResponse({ status: 200 })
4046
@Delete()
4147
async deleteSettings(): Promise<boolean> {
4248
return this.adminSettingsService.deleteSettings();

backend/src/modules/admin-settings/presentation/dto/create-admin-settings.dto.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Type } from 'class-transformer';
2+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
23
import {
34
IsString,
45
IsNotEmpty,
@@ -14,80 +15,80 @@ import {
1415
} from '../../domain/interfaces/admin-settings.interface';
1516

1617
class LocationDto implements IAdminLocation {
17-
@IsString()
18+
@IsString() @ApiProperty()
1819
@IsNotEmpty()
1920
address: string;
2021

21-
@IsNumber()
22+
@IsNumber() @ApiProperty()
2223
latitude: number;
2324

24-
@IsNumber()
25+
@IsNumber() @ApiProperty()
2526
longitude: number;
2627
}
2728

2829
class OwnerInfoDto implements IOwnerInfo {
29-
@IsString()
30+
@IsString() @ApiProperty()
3031
@IsNotEmpty()
3132
name: string;
3233

33-
@IsString()
34+
@IsString() @ApiProperty()
3435
@IsNotEmpty()
3536
phoneNumber: string;
3637
}
3738

3839
export class CreateAdminSettingsDto {
39-
@ValidateNested()
40+
@ValidateNested() @ApiProperty()
4041
@Type(() => LocationDto)
4142
@IsNotEmpty()
4243
location: LocationDto;
4344

44-
@IsObject()
45+
@IsObject() @ApiPropertyOptional()
4546
@IsOptional()
4647
socialLinks: Record<string, string>;
4748

48-
@IsObject()
49+
@IsObject() @ApiPropertyOptional()
4950
@IsOptional()
5051
workHours: Record<string, string>;
5152

52-
@ValidateNested()
53+
@ValidateNested() @ApiProperty()
5354
@Type(() => OwnerInfoDto)
5455
@IsNotEmpty()
5556
ownerInfo: OwnerInfoDto;
5657

57-
@IsString()
58+
@IsString() @ApiProperty()
5859
@IsOptional()
5960
biography: string;
6061

61-
@IsString()
62+
@IsString() @ApiProperty()
6263
@IsOptional()
6364
philosophy: string;
6465

65-
@IsArray()
66+
@IsArray() @ApiPropertyOptional()
6667
@IsString({ each: true })
6768
@IsOptional()
6869
galleryCategories: string[];
6970

70-
@IsArray()
71+
@IsArray() @ApiPropertyOptional()
7172
@IsString({ each: true })
7273
@IsOptional()
7374
treatmentCategories: string[];
7475

75-
@IsArray()
76+
@IsArray() @ApiPropertyOptional()
7677
@IsString({ each: true })
7778
@IsOptional()
7879
veilSilhouettes: string[];
7980

80-
@IsArray()
81+
@IsArray() @ApiPropertyOptional()
8182
@IsString({ each: true })
8283
@IsOptional()
8384
veilFabrics: string[];
8485

85-
@IsArray()
86+
@IsArray() @ApiPropertyOptional()
8687
@IsString({ each: true })
8788
@IsOptional()
8889
veilTrainLengths: string[];
8990

90-
@IsArray()
91+
@IsArray() @ApiPropertyOptional()
9192
@IsString({ each: true })
9293
@IsOptional()
9394
veilNecklines: string[];

backend/src/modules/admin-settings/presentation/dto/update-admin-settings.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PartialType } from '@nestjs/mapped-types';
1+
import { PartialType } from '@nestjs/swagger';
22
import { CreateAdminSettingsDto } from './create-admin-settings.dto';
33

44
export class UpdateAdminSettingsDto extends PartialType(

backend/src/modules/gallery/presentation/gallery.controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
12
import {
23
Controller,
34
Get,
@@ -17,20 +18,24 @@ import { Gallery } from '../domain/gallery.entity';
1718
import { CreateGalleryDto } from './dto/create-gallery.dto';
1819
import { UpdateGalleryDto } from './dto/update-gallery.dto';
1920

21+
@ApiTags('Gallery')
2022
@Controller('gallery')
2123
export class GalleryController {
2224
constructor(private readonly galleryService: GalleryService) {}
2325

26+
@ApiOperation({ summary: 'Get all' }) @ApiResponse({ status: 200 })
2427
@Get()
2528
async findAll(): Promise<Gallery[]> {
2629
return this.galleryService.findAll();
2730
}
2831

32+
@ApiOperation({ summary: 'Get one' }) @ApiResponse({ status: 200 })
2933
@Get(':id')
3034
async findOne(@Param('id') id: string): Promise<Gallery> {
3135
return this.galleryService.findOne(id);
3236
}
3337

38+
@ApiOperation({ summary: 'Create' }) @ApiResponse({ status: 201 })
3439
@Post()
3540
@UseInterceptors(
3641
FilesInterceptor('files', 10, {
@@ -64,6 +69,7 @@ export class GalleryController {
6469
return this.galleryService.create(gallery);
6570
}
6671

72+
@ApiOperation({ summary: 'Update' }) @ApiResponse({ status: 200 })
6773
@Put(':id')
6874
@UseInterceptors(
6975
FilesInterceptor('files', 10, {
@@ -98,6 +104,7 @@ export class GalleryController {
98104
);
99105
}
100106

107+
@ApiOperation({ summary: 'Delete' }) @ApiResponse({ status: 200 })
101108
@Delete(':id')
102109
async remove(@Param('id') id: string): Promise<void> {
103110
return this.galleryService.remove(id);

backend/src/modules/treatments/presentation/dto/create-treatments.dto.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Type } from 'class-transformer';
2+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
23
import {
34
IsBoolean,
45
IsNotEmpty,
@@ -21,35 +22,35 @@ export enum TreatmentCategory {
2122

2223
export class CreateServiceDto {
2324
@IsNotEmpty()
24-
@IsString()
25+
@IsString() @ApiProperty()
2526
name: string;
2627

2728
@IsNotEmpty()
28-
@IsString()
29+
@IsString() @ApiProperty()
2930
description: string;
3031

3132
@IsNotEmpty()
3233
@Type(() => Number)
33-
@IsNumber()
34+
@IsNumber() @ApiProperty()
3435
@Min(1)
3536
price: number;
3637

3738
@IsOptional()
3839
@Type(() => Boolean)
39-
@IsBoolean()
40+
@IsBoolean() @ApiPropertyOptional()
4041
active: boolean;
4142

4243
@IsNotEmpty()
4344
@Type(() => Number)
44-
@IsNumber()
45+
@IsNumber() @ApiProperty()
4546
@Min(1)
4647
duration: number;
4748

4849
@IsNotEmpty()
49-
@IsString()
50+
@IsString() @ApiProperty()
5051
category: string;
5152

5253
@IsOptional()
53-
@IsString()
54+
@IsString() @ApiProperty()
5455
imageUrl: string;
5556
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PartialType } from '@nestjs/mapped-types';
1+
import { PartialType } from '@nestjs/swagger';
22
import { CreateServiceDto } from './create-treatments.dto';
33

44
export class UpdateServiceDto extends PartialType(CreateServiceDto) {}

backend/src/modules/treatments/presentation/treatments.controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
12
import {
23
CreateServiceDto as CreateTreatmentDto,
34
Treatments,
@@ -19,20 +20,24 @@ import { FilesInterceptor } from '@nestjs/platform-express';
1920
import { diskStorage } from 'multer';
2021
import { extname } from 'path';
2122

23+
@ApiTags('Treatments')
2224
@Controller('treatments')
2325
export class TreatmentsController {
2426
constructor(private readonly treatmentsService: TreatmentsService) {}
2527

28+
@ApiOperation({ summary: 'Get all' }) @ApiResponse({ status: 200 })
2629
@Get()
2730
async findAll(): Promise<Treatments[]> {
2831
return this.treatmentsService.findAll();
2932
}
3033

34+
@ApiOperation({ summary: 'Get one' }) @ApiResponse({ status: 200 })
3135
@Get(':id')
3236
async findOne(@Param('id') id: string): Promise<Treatments> {
3337
return this.treatmentsService.findOne(id);
3438
}
3539

40+
@ApiOperation({ summary: 'Create' }) @ApiResponse({ status: 201 })
3641
@Post()
3742
@UseInterceptors(
3843
FilesInterceptor('image', 10, {
@@ -63,6 +68,7 @@ export class TreatmentsController {
6368
);
6469
}
6570

71+
@ApiOperation({ summary: 'Update' }) @ApiResponse({ status: 200 })
6672
@Put(':id')
6773
@UseInterceptors(
6874
FilesInterceptor('image', 10, {
@@ -97,6 +103,7 @@ export class TreatmentsController {
97103
);
98104
}
99105

106+
@ApiOperation({ summary: 'Delete' }) @ApiResponse({ status: 200 })
100107
@Delete(':id')
101108
async remove(@Param('id') id: string): Promise<void> {
102109
return this.treatmentsService.remove(id);

frontend/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7+
"predev": "node scripts/setenv.cjs",
78
"dev": "ng serve --configuration=development",
9+
"prebuild": "node scripts/setenv.cjs",
810
"build": "ng build",
911
"preview": "ng serve --configuration=production",
1012
"test": "vitest"

frontend/scripts/setenv.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
require('dotenv').config({ path: path.resolve(__dirname, '../../.env') });
4+
5+
const envConfigFile = `export const environment = {
6+
production: ${process.env.NODE_ENV === 'production'},
7+
apiUrl: "${process.env.FRONTEND_URL || 'http://localhost:3000'}",
8+
telegramBotName: "${process.env.TELEGRAM_BOT_NAME || 'test_bot'}",
9+
};
10+
`;
11+
12+
const targetPath = path.resolve(__dirname, '../src/environments/environment.ts');
13+
const targetProdPath = path.resolve(__dirname, '../src/environments/environment.prod.ts');
14+
15+
fs.writeFileSync(targetPath, envConfigFile);
16+
fs.writeFileSync(targetProdPath, envConfigFile);
17+
console.log(`Environment files generated at ${targetPath}`);

0 commit comments

Comments
 (0)