structure
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
Delete,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
} from '@nestjs/common';
|
||||
import { ContactService } from '../providers/contact.service';
|
||||
import { CreateContactDto } from '../dto/create-contact.dto';
|
||||
import { FindContactsDto } from '../dto/find-contacts.dto';
|
||||
import { UpdateContactStatusDto } from '../dto/update-contact-status.dto';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiParam, ApiQuery } from '@nestjs/swagger';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
|
||||
@ApiTags('contact')
|
||||
@Controller()
|
||||
export class ContactController {
|
||||
constructor(private readonly contactService: ContactService) {}
|
||||
|
||||
@Post('public/contact')
|
||||
@ApiOperation({ summary: 'Create a new contact (public endpoint)' })
|
||||
@ApiResponse({ status: 201, description: 'Contact created successfully' })
|
||||
async create(@Body() createContactDto: CreateContactDto) {
|
||||
return this.contactService.create(createContactDto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('admin/contact')
|
||||
@ApiOperation({ summary: 'Get paginated list of contacts (admin only)' })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'search', required: false, type: String })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
@ApiQuery({ name: 'status', required: false, enum: ['new', 'seen'] })
|
||||
async findAllPaginated(@Query() dto: FindContactsDto) {
|
||||
return this.contactService.findAllPaginated(dto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('admin/contact/:id')
|
||||
@ApiOperation({ summary: 'Get contact details by ID (admin only)' })
|
||||
@ApiParam({ name: 'id', description: 'Contact ID' })
|
||||
async findOne(@Param('id') id: string) {
|
||||
return this.contactService.findOne(id);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Patch('admin/contact/:id/status')
|
||||
@ApiOperation({ summary: 'Update contact status (admin only)' })
|
||||
@ApiParam({ name: 'id', description: 'Contact ID' })
|
||||
async updateStatus(@Param('id') id: string, @Body() dto: UpdateContactStatusDto) {
|
||||
return this.contactService.updateStatus(id, dto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Delete('admin/contact/:id')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
@ApiOperation({ summary: 'Hard delete a contact (admin only)' })
|
||||
@ApiParam({ name: 'id', description: 'Contact ID' })
|
||||
async remove(@Param('id') id: string) {
|
||||
await this.contactService.remove(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user