import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { JwtPayload } from '../../common/interfaces/jwt-payload.interface';
import { PostQueryDto } from './dto/post-query.dto';
import { PostsService } from './posts.service';

@ApiTags('Users')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('users')
export class PostsUsersController {
  constructor(private readonly postsService: PostsService) {}

  @Get(':userId/posts')
  async findUserPosts(
    @CurrentUser() user: JwtPayload,
    @Param('userId') userId: string,
    @Query() query: PostQueryDto,
  ) {
    return this.postsService.findUserPosts(userId, query, user.sub);
  }
}
