Total Complexity | 3 |
Complexity/F | 1 |
Lines of Code | 37 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | 8 | import { Controller, Post, Body, Get, UseGuards, Req } from '@nestjs/common'; |
|
2 | 8 | import { AuthService } from './auth.service'; |
|
3 | 8 | import { JwtAuthGuard } from './guards/jwt-auth.guard'; |
|
4 | 8 | import { TokenExchangeDto } from './dto/token-exchange.dto/token-exchange.dto'; |
|
5 | 8 | import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger'; |
|
6 | |||
7 | @ApiTags('auth') |
||
8 | @Controller({ path: 'auth', version: '1' }) |
||
9 | 8 | export class AuthController { |
|
10 | 11 | constructor(private readonly authService: AuthService) {} |
|
11 | |||
12 | @Post('token') |
||
13 | @ApiOperation({ summary: 'Exchange GitHub code for access token' }) |
||
14 | @ApiResponse({ status: 200, description: 'Token exchange successful' }) |
||
15 | 8 | async exchangeToken(@Body() tokenExchangeDto: TokenExchangeDto) { |
|
16 | 2 | return this.authService.exchangeGithubCode(tokenExchangeDto.code); |
|
17 | } |
||
18 | |||
19 | @Get('me') |
||
20 | @UseGuards(JwtAuthGuard) |
||
21 | @ApiBearerAuth() |
||
22 | @ApiOperation({ summary: 'Get current user information' }) |
||
23 | @ApiResponse({ status: 200, description: 'Returns user information' }) |
||
24 | 8 | async getMe(@Req() req) { |
|
25 | 1 | return req.user; |
|
26 | } |
||
27 | |||
28 | @Get('status') |
||
29 | @UseGuards(JwtAuthGuard) |
||
30 | @ApiBearerAuth() |
||
31 | @ApiOperation({ summary: 'Check authentication status' }) |
||
32 | @ApiResponse({ status: 200, description: 'Returns authentication status' }) |
||
33 | 8 | async getStatus(@Req() req) { |
|
34 | 1 | return this.authService.getStatus(req.user); |
|
35 | } |
||
36 | } |
||
37 |