agent and category Dto creation
This commit is contained in:
176
src/agents/agents.controller.ts
Normal file
176
src/agents/agents.controller.ts
Normal file
@@ -0,0 +1,176 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
ParseUUIDPipe,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiBearerAuth,
|
||||
} from '@nestjs/swagger';
|
||||
import { AgentsService } from './agents.service';
|
||||
import {
|
||||
CreateAgentProfileDto,
|
||||
UpdateAgentProfileDto,
|
||||
SearchAgentsDto,
|
||||
} from './dto';
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { RolesGuard } from '../auth/guards/roles.guard';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import { UserRole } from '@prisma/client';
|
||||
|
||||
@ApiTags('agents')
|
||||
@Controller('agents')
|
||||
export class AgentsController {
|
||||
constructor(private readonly agentsService: AgentsService) {}
|
||||
|
||||
// Public endpoints
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Search and list agents' })
|
||||
@ApiResponse({ status: 200, description: 'Agents retrieved successfully' })
|
||||
async searchAgents(@Query() dto: SearchAgentsDto) {
|
||||
return this.agentsService.searchAgents(dto);
|
||||
}
|
||||
|
||||
@Get('featured')
|
||||
@ApiOperation({ summary: 'Get featured agents' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Featured agents retrieved successfully',
|
||||
})
|
||||
async getFeaturedAgents(@Query('limit') limit?: number) {
|
||||
return this.agentsService.getFeaturedAgents(limit || 10);
|
||||
}
|
||||
|
||||
@Get('top-rated')
|
||||
@ApiOperation({ summary: 'Get top rated agents' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Top rated agents retrieved successfully',
|
||||
})
|
||||
async getTopRatedAgents(@Query('limit') limit?: number) {
|
||||
return this.agentsService.getTopRatedAgents(limit || 10);
|
||||
}
|
||||
|
||||
// Authenticated endpoints - must come before :id route
|
||||
|
||||
@Get('profile/me')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get current user agent profile' })
|
||||
@ApiResponse({ status: 200, description: 'Profile retrieved successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Profile not found' })
|
||||
async getMyProfile(@CurrentUser('id') userId: string) {
|
||||
return this.agentsService.getProfile(userId);
|
||||
}
|
||||
|
||||
// Parameterized route - must come after specific routes
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get agent profile by ID' })
|
||||
@ApiResponse({ status: 200, description: 'Agent profile retrieved successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Agent profile not found' })
|
||||
async getAgentById(@Param('id', ParseUUIDPipe) id: string) {
|
||||
return this.agentsService.getProfileById(id);
|
||||
}
|
||||
|
||||
@Post('profile')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Create agent profile' })
|
||||
@ApiResponse({ status: 201, description: 'Profile created successfully' })
|
||||
@ApiResponse({ status: 409, description: 'Profile already exists' })
|
||||
async createProfile(
|
||||
@CurrentUser('id') userId: string,
|
||||
@Body() dto: CreateAgentProfileDto,
|
||||
) {
|
||||
return this.agentsService.createProfile(userId, dto);
|
||||
}
|
||||
|
||||
@Put('profile')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Update current user agent profile' })
|
||||
@ApiResponse({ status: 200, description: 'Profile updated successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Profile not found' })
|
||||
async updateProfile(
|
||||
@CurrentUser('id') userId: string,
|
||||
@Body() dto: UpdateAgentProfileDto,
|
||||
) {
|
||||
return this.agentsService.updateProfile(userId, dto);
|
||||
}
|
||||
|
||||
// Admin endpoints
|
||||
|
||||
@Get('admin/list')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Admin: List all agents' })
|
||||
@ApiResponse({ status: 200, description: 'Agents retrieved successfully' })
|
||||
async adminListAgents(@Query() dto: SearchAgentsDto) {
|
||||
return this.agentsService.getAllAgentsAdmin(dto);
|
||||
}
|
||||
|
||||
@Put('admin/:id')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Admin: Update agent profile' })
|
||||
@ApiResponse({ status: 200, description: 'Profile updated successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Profile not found' })
|
||||
async adminUpdateProfile(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
@Body() dto: UpdateAgentProfileDto,
|
||||
) {
|
||||
return this.agentsService.adminUpdateProfile(id, dto);
|
||||
}
|
||||
|
||||
@Delete('admin/:id')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Admin: Delete agent profile' })
|
||||
@ApiResponse({ status: 200, description: 'Profile deleted successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Profile not found' })
|
||||
async adminDeleteProfile(@Param('id', ParseUUIDPipe) id: string) {
|
||||
return this.agentsService.adminDeleteProfile(id);
|
||||
}
|
||||
|
||||
@Put('admin/:id/verify')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Admin: Verify/unverify agent' })
|
||||
@ApiResponse({ status: 200, description: 'Verification status updated' })
|
||||
@ApiResponse({ status: 404, description: 'Profile not found' })
|
||||
async adminVerifyAgent(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
@Body('isVerified') isVerified: boolean,
|
||||
) {
|
||||
return this.agentsService.adminVerifyAgent(id, isVerified);
|
||||
}
|
||||
|
||||
@Put('admin/:id/featured')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Admin: Set agent as featured' })
|
||||
@ApiResponse({ status: 200, description: 'Featured status updated' })
|
||||
@ApiResponse({ status: 404, description: 'Profile not found' })
|
||||
async adminSetFeatured(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
@Body('isFeatured') isFeatured: boolean,
|
||||
) {
|
||||
return this.agentsService.adminSetFeatured(id, isFeatured);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user