import { Controller, Get, Post, Body, Param, UseGuards, Request, Query } from '@nestjs/common';
import { LocationsService } from './locations.service';
import { CreateLocationDto } from './dto/create-location.dto';
import { AuthGuard } from '@nestjs/passport';

@Controller('locations')
@UseGuards(AuthGuard('jwt'))
export class LocationsController {
  constructor(private readonly locationsService: LocationsService) {}

  @Post()
  create(@Request() req, @Body() createLocationDto: CreateLocationDto) {
    return this.locationsService.create(req.user.id, createLocationDto);
  }

  @Get()
  findAll(@Request() req, @Query('date') date?: string) {
    return this.locationsService.findAll(req.user, date);
  }

  @Get('user/:userId')
  findByUser(@Param('userId') userId: string, @Request() req, @Query('date') date?: string) {
    return this.locationsService.findByUser(userId, req.user, date);
  }
}
