import { Controller, Get, Post, Body, Param, Query, UseGuards, Req } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
import { ProductsService } from './products.service';
import { CreateProductDto } from './dto/create-product.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
@ApiTags('WalsFab Products & Media')
@Controller('api/v1/products')
export class ProductsController {
constructor(private readonly productsService: ProductsService) {}
@Get()
@ApiOperation({ summary: 'Get filtered WalsFab products and video reels' })
@ApiQuery({ name: 'category', required: false })
@ApiQuery({ name: 'type', required: false })
async findAll(
@Query('category') category?: string,
@Query('type') type?: string,
@Query('search') search?: string,
) {
return this.productsService.findAll({ category, type, search });
}
@Get(':id')
@ApiOperation({ summary: 'Get product item by ID' })
async findOne(@Param('id') id: string) {
return this.productsService.findOne(id);
}
@Post()
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Create new couture item (Protected endpoint)' })
async create(@Body() dto: CreateProductDto, @Req() req: any) {
return this.productsService.create(dto, req.user);
}
}
import { Controller, Post, Body, Get, UseGuards, Req } from '@nestjs/common';
import { AuthService } from './auth.service';
import { LoginDto } from './dto/login.dto';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
@Controller('api/v1/auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('login')
async login(@Body() loginDto: LoginDto) {
return this.authService.login(loginDto);
}
@Get('profile')
@UseGuards(JwtAuthGuard)
async getProfile(@Req() req: any) {
return req.user;
}
}
import { Injectable, NotFoundException } from '@nestjs/common';
@Injectable()
export class ProductsService {
private products = [/* WalsFab dynamic catalog dataset */];
async findAll(filter: { category?: string; type?: string; search?: string }) {
let result = this.products;
if (filter.type && filter.type !== 'all') {
result = result.filter(item => item.type === filter.type);
}
if (filter.category && filter.category !== 'all') {
result = result.filter(item => item.category === filter.category);
}
if (filter.search) {
const q = filter.search.toLowerCase();
result = result.filter(item => item.title.toLowerCase().includes(q));
}
return { statusCode: 200, count: result.length, data: result };
}
}
import { IsString, IsNumber, IsEnum, IsPositive } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class CreateProductDto {
@ApiProperty({ example: 'WalsFab Velvet Blazer' })
@IsString()
title: string;
@ApiProperty({ example: 299.99 })
@IsNumber()
@IsPositive()
price: number;
@ApiProperty({ enum: ['product', 'video'] })
@IsEnum(['product', 'video'])
type: string;
}