food comments
This commit is contained in:
@@ -9,7 +9,6 @@ import {
|
||||
ApiResponse,
|
||||
ApiCreatedResponse,
|
||||
ApiOkResponse,
|
||||
ApiNotFoundResponse,
|
||||
ApiQuery,
|
||||
ApiBody,
|
||||
ApiParam,
|
||||
@@ -18,6 +17,7 @@ import {
|
||||
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { UserId } from 'src/common/decorators/user-id.decorator';
|
||||
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
||||
|
||||
@ApiTags('food-comments')
|
||||
@Controller()
|
||||
@@ -34,37 +34,41 @@ export class FoodCommentController {
|
||||
return this.foodCommentService.create(userId, createFoodCommentDto);
|
||||
}
|
||||
|
||||
@Get('public/food-comments')
|
||||
@Get('public/food-comments/:foodId')
|
||||
@ApiOperation({ summary: 'Get all food comments (public - only approved)' })
|
||||
@ApiOkResponse({ description: 'List of approved food comments' })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'foodId', required: false, type: String })
|
||||
@ApiParam({ name: 'foodId', required: true, type: String })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
findAll(@Query() dto: FindFoodCommentsDto) {
|
||||
findAll(@Query() dto: FindFoodCommentsDto, @Param('foodId') foodId: string) {
|
||||
// Only show approved comments for public endpoint
|
||||
return this.foodCommentService.findAll({ ...dto, isApproved: true });
|
||||
return this.foodCommentService.findAll({ ...dto, isApproved: true, foodId });
|
||||
}
|
||||
|
||||
@Get('public/food-comments/:id')
|
||||
@ApiOperation({ summary: 'Get a food comment by id' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiOkResponse({ description: 'The food comment' })
|
||||
@ApiNotFoundResponse({ description: 'Comment not found' })
|
||||
findById(@Param('id') id: string) {
|
||||
return this.foodCommentService.findById(id);
|
||||
}
|
||||
// @Get('public/food-comments/:id')
|
||||
// @ApiOperation({ summary: 'Get a food comment by id' })
|
||||
// @ApiParam({ name: 'id', required: true })
|
||||
// @ApiOkResponse({ description: 'The food comment' })
|
||||
// @ApiNotFoundResponse({ description: 'Comment not found' })
|
||||
// findById(@Param('id') id: string) {
|
||||
// return this.foodCommentService.findById(id);
|
||||
// }
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Patch('public/food-comments/:id')
|
||||
@Patch('public/food-comments/:foodCommentId')
|
||||
@ApiOperation({ summary: 'Update a food comment (own comments only)' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiParam({ name: 'foodCommentId', required: true })
|
||||
@ApiBody({ type: UpdateFoodCommentDto })
|
||||
@ApiOkResponse({ description: 'The updated comment' })
|
||||
update(@Param('id') id: string, @Body() updateFoodCommentDto: UpdateFoodCommentDto, @UserId() userId: string) {
|
||||
return this.foodCommentService.update(id, userId, updateFoodCommentDto, false);
|
||||
update(
|
||||
@Param('foodCommentId') foodCommentId: string,
|
||||
@Body() updateFoodCommentDto: UpdateFoodCommentDto,
|
||||
@UserId() userId: string,
|
||||
) {
|
||||
return this.foodCommentService.update(foodCommentId, userId, updateFoodCommentDto, false);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@@ -89,8 +93,8 @@ export class FoodCommentController {
|
||||
@ApiQuery({ name: 'isApproved', required: false, type: Boolean })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
findAllAdmin(@Query() dto: FindFoodCommentsDto) {
|
||||
return this.foodCommentService.findAll(dto);
|
||||
findAllAdmin(@Query() dto: FindFoodCommentsDto, @RestId() restId: string) {
|
||||
return this.foodCommentService.findAll({ ...dto, restId });
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@@ -99,7 +103,6 @@ export class FoodCommentController {
|
||||
@ApiOperation({ summary: 'Update a food comment (admin - can change approval status)' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiBody({ type: UpdateFoodCommentDto })
|
||||
@ApiOkResponse({ description: 'The updated comment' })
|
||||
updateAdmin(@Param('id') id: string, @Body() updateFoodCommentDto: UpdateFoodCommentDto, @UserId() userId: string) {
|
||||
return this.foodCommentService.update(id, userId, updateFoodCommentDto, true);
|
||||
}
|
||||
@@ -114,4 +117,3 @@ export class FoodCommentController {
|
||||
return this.foodCommentService.remove(id, userId, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user