diff --git a/src/modules/restaurants/controllers/public-restaurant.controller.ts b/src/modules/restaurants/controllers/public-restaurant.controller.ts new file mode 100644 index 0000000..fe7acb2 --- /dev/null +++ b/src/modules/restaurants/controllers/public-restaurant.controller.ts @@ -0,0 +1,20 @@ +import { Controller, Get, Param } from '@nestjs/common'; +import { RestaurantsService } from '../providers/restaurants.service'; +import { RestaurantSpecificationDto } from '../dto/restaurant-specification.dto'; +import { ApiTags, ApiOperation, ApiOkResponse, ApiParam, ApiNotFoundResponse } from '@nestjs/swagger'; + +@ApiTags('restaurants') +@Controller('restaurants') +export class PublicRestaurantController { + constructor(private readonly restaurantsService: RestaurantsService) {} + + @Get(':slug') + @ApiOperation({ summary: 'Get restaurant specification by slug' }) + @ApiParam({ name: 'slug', required: true, description: 'Restaurant slug' }) + @ApiOkResponse({ type: RestaurantSpecificationDto, description: 'Restaurant specification found' }) + @ApiNotFoundResponse({ description: 'Restaurant not found' }) + findBySlug(@Param('slug') slug: string): Promise { + return this.restaurantsService.getRestaurantSpecification(slug); + } +} + diff --git a/src/modules/restaurants/dto/restaurant-specification.dto.ts b/src/modules/restaurants/dto/restaurant-specification.dto.ts new file mode 100644 index 0000000..a0f70d8 --- /dev/null +++ b/src/modules/restaurants/dto/restaurant-specification.dto.ts @@ -0,0 +1,67 @@ +import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; + +export class RestaurantSpecificationDto { + @ApiProperty({ example: '550e8400-e29b-41d4-a716-446655440000', description: 'Restaurant ID' }) + id!: string; + + @ApiProperty({ example: 'کافه ژیوان', description: 'Restaurant name' }) + name!: string; + + @ApiProperty({ example: 'zhivan', description: 'Restaurant slug' }) + slug!: string; + + @ApiPropertyOptional({ example: 'https://example.com/logo.png', description: 'Logo URL' }) + logo?: string; + + @ApiPropertyOptional({ example: 'تهران، خیابان ولیعصر پلاک ۱۲۳', description: 'Address' }) + address?: string; + + @ApiPropertyOptional({ example: '#ff6600', description: 'Menu color (hex)' }) + menuColor?: string; + + @ApiPropertyOptional({ example: 35.6892, description: 'Latitude' }) + latitude?: number; + + @ApiPropertyOptional({ example: 51.389, description: 'Longitude' }) + longitude?: number; + + @ApiPropertyOptional({ example: 5000, description: 'Service area in meters' }) + serviceArea?: number; + + @ApiPropertyOptional({ example: 2020, description: 'Established year' }) + establishedYear?: number; + + @ApiPropertyOptional({ example: '+989123456789', description: 'Phone number' }) + phoneNumber?: string; + + @ApiPropertyOptional({ example: 'https://instagram.com/cafemorteza', description: 'Instagram URL' }) + instagram?: string; + + @ApiPropertyOptional({ example: 'https://t.me/cafemorteza', description: 'Telegram URL' }) + telegram?: string; + + @ApiPropertyOptional({ example: 'https://wa.me/989123456789', description: 'WhatsApp URL' }) + whatsapp?: string; + + @ApiPropertyOptional({ example: 'محل دنج با بهترین قهوه شهر.', description: 'Description' }) + description?: string; + + @ApiPropertyOptional({ example: 'بهترین کافه تهران', description: 'SEO title' }) + seoTitle?: string; + + @ApiPropertyOptional({ example: 'کافه مرتضی ارائه‌دهنده قهوه با کیفیت بالا.', description: 'SEO description' }) + seoDescription?: string; + + @ApiPropertyOptional({ example: ['قهوه', 'صبحانه', 'کافه'], description: 'Tag names', type: [String] }) + tagNames?: string[]; + + @ApiPropertyOptional({ + example: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'], + description: 'Image URLs', + type: [String], + }) + images?: string[]; + + @ApiPropertyOptional({ example: 0.09, description: 'VAT rate (e.g., 0.09 for 9%)' }) + vat?: number; +} diff --git a/src/modules/restaurants/providers/restaurants.service.ts b/src/modules/restaurants/providers/restaurants.service.ts index 0b71744..8ef2030 100644 --- a/src/modules/restaurants/providers/restaurants.service.ts +++ b/src/modules/restaurants/providers/restaurants.service.ts @@ -1,6 +1,7 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { CreateRestaurantDto } from '../dto/create-restaurant.dto'; import { UpdateRestaurantDto } from '../dto/update-restaurant.dto'; +import { RestaurantSpecificationDto } from '../dto/restaurant-specification.dto'; import { Restaurant } from '../entities/restaurant.entity'; import { EntityManager } from '@mikro-orm/postgresql'; import { RestRepository } from '../repositories/rest.repository'; @@ -37,6 +38,35 @@ export class RestaurantsService { return restaurant; } + async getRestaurantSpecification(slug: string): Promise { + const restaurant = await this.findBySlug(slug); + + const specification: RestaurantSpecificationDto = { + id: restaurant.id, + name: restaurant.name, + slug: restaurant.slug, + logo: restaurant.logo, + address: restaurant.address, + menuColor: restaurant.menuColor, + latitude: restaurant.latitude, + longitude: restaurant.longitude, + serviceArea: restaurant.serviceArea, + establishedYear: restaurant.establishedYear, + phoneNumber: restaurant.phoneNumber, + instagram: restaurant.instagram, + telegram: restaurant.telegram, + whatsapp: restaurant.whatsapp, + description: restaurant.description, + seoTitle: restaurant.seoTitle, + seoDescription: restaurant.seoDescription, + tagNames: restaurant.tagNames, + images: restaurant.images, + vat: restaurant.vat, + }; + + return specification; + } + async update(id: string, dto: UpdateRestaurantDto): Promise { const restaurant = await this.restRepository.findOne({ id }); diff --git a/src/modules/restaurants/restaurants.module.ts b/src/modules/restaurants/restaurants.module.ts index b9d9121..af2106c 100644 --- a/src/modules/restaurants/restaurants.module.ts +++ b/src/modules/restaurants/restaurants.module.ts @@ -1,6 +1,7 @@ import { Module, forwardRef } from '@nestjs/common'; import { RestaurantsService } from './providers/restaurants.service'; import { RestaurantsController } from './controllers/restaurants.controller'; +import { PublicRestaurantController } from './controllers/public-restaurant.controller'; import { MikroOrmModule } from '@mikro-orm/nestjs'; import { Restaurant } from './entities/restaurant.entity'; import { RestRepository } from './repositories/rest.repository'; @@ -12,7 +13,7 @@ import { JwtModule } from '@nestjs/jwt'; import { AuthModule } from '../auth/auth.module'; @Module({ - controllers: [RestaurantsController, ScheduleController], + controllers: [RestaurantsController, PublicRestaurantController, ScheduleController], providers: [RestaurantsService, RestRepository, ScheduleRepository, ScheduleService], imports: [MikroOrmModule.forFeature([Restaurant, Schedule]), JwtModule, forwardRef(() => AuthModule)], exports: [RestRepository, ScheduleRepository, ScheduleService],