Skip to content

Commit

Permalink
Merge pull request #15 from DISIC/dev
Browse files Browse the repository at this point in the history
fix(pencil): ajout de la documention des APIs avec Swagger
  • Loading branch information
youssefElMkhantar authored Apr 17, 2024
2 parents 954aef4 + 7a02e63 commit da75a03
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 27 deletions.
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@nestjs/mongoose": "^10.0.2",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.3.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^10.0.2",
"@types/moment": "^2.13.0",
Expand Down
7 changes: 1 addition & 6 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Controller, Get } from '@nestjs/common';
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
return this.appService.getHello();
}
}
6 changes: 1 addition & 5 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return '';
}
}
export class AppService {}
9 changes: 9 additions & 0 deletions src/authentication/DTOs/LoginCallbackDTO.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Injectable } from '@nestjs/common';
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

@Injectable()
export class LoginCallbackDTO {
@IsString()
@ApiProperty({
type: String,
description: "le code 'state' envoyé par le fournisseur d'identité",
})
state: string;
@IsString()
@ApiProperty({
type: String,
description: "le 'code' envoyé par le fournisseur d'identité",
})
code: string;
}
5 changes: 5 additions & 0 deletions src/authentication/DTOs/LogoutCallbackDTO.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Injectable } from '@nestjs/common';
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

@Injectable()
export class LogoutCallbackDTO {
@IsString()
@ApiProperty({
type: String,
description: "le code 'state' envoyé par le fournisseur d'identité",
})
state: string;
}
29 changes: 28 additions & 1 deletion src/authentication/authentication.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import { JwtService } from '@nestjs/jwt';
import * as moment from 'moment';
import { LoginCallbackDTO } from './DTOs/LoginCallbackDTO';
import { LogoutCallbackDTO } from './DTOs/LogoutCallbackDTO';
import {
ApiOkResponse,
ApiUnauthorizedResponse,
ApiNotFoundResponse,
ApiResponse,
} from '@nestjs/swagger';

@Controller('authentication')
export class AuthenticationController {
Expand All @@ -28,12 +34,16 @@ export class AuthenticationController {
) {}

@Get('whereami')
@ApiOkResponse({ description: "retoune 'RIE' ou 'INTERNET' " })
whereami(@Headers('webconf-user-region') userAgent: string) {
return userAgent;
}

@Get('login_authorize')
@Redirect('', 302)
@ApiOkResponse({
description: "retourne l'url de redirection",
})
loginAuthorize(
@Res({ passthrough: true }) response: Response,
@Query('room') room: string,
Expand All @@ -54,6 +64,16 @@ export class AuthenticationController {
}

@Get('login_callback')
@ApiOkResponse({
description: 'retourne un objet {roomName, jwt, accessToken}',
})
@ApiUnauthorizedResponse({
description: "le paramètre state recu n'est pas le meme envoyé",
})
@ApiNotFoundResponse({
description:
"erreur lors de récupération de l'accessToken ou userinfo d'agentConnect",
})
async loginCallback(
@Query() query: LoginCallbackDTO,
@Req() request: Request,
Expand Down Expand Up @@ -97,6 +117,7 @@ export class AuthenticationController {

@Get('logout')
@Redirect('', 302)
@ApiResponse({ status: 302, description: 'redirection vers cerbère' })
logout(
@Req() request: Request,
@Res({ passthrough: true }) response: Response,
Expand All @@ -114,7 +135,11 @@ export class AuthenticationController {
}

@Get('logout_callback')
// @Redirect('', 302)
@ApiOkResponse({ description: "retourne l'url /" })
@ApiUnauthorizedResponse({
description:
"le state de retour n'est pas la meme que celle qui a été envoyé",
})
logoutCallback(
@Query() query: LogoutCallbackDTO,
@Req() request: Request,
Expand All @@ -135,6 +160,8 @@ export class AuthenticationController {
}

@Get('refreshToken')
@ApiOkResponse({ description: 'retourne { accessToken }' })
@ApiUnauthorizedResponse({ description: 'veuillez vous authentifier' })
async refreshToken(
@Req() request: Request,
@Res({ passthrough: true }) response: Response,
Expand Down
2 changes: 1 addition & 1 deletion src/authentication/authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class AuthenticationService {
"la variable state envoyé n'est pas celle reçue {/authentication/login_callback} route",
);
throw new UnauthorizedException(
"le paramètre state recu n'est pas le meme envoyé",
"le paramètre state reçu n'est pas le meme envoyé",
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/conference/DTOs/byEmail.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, Matches } from 'class-validator';

@Injectable()
Expand All @@ -13,8 +14,10 @@ export class ByEmailDTO {
),
{ message: "le nom de conférence n'est pas valide" },
)
@ApiProperty({ type: String })
roomName: string;

@IsEmail()
@ApiProperty({ type: String })
email: string;
}
2 changes: 2 additions & 0 deletions src/conference/DTOs/conference.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import { ApiProperty } from '@nestjs/swagger';
import { Matches } from 'class-validator';

@Injectable()
Expand All @@ -13,5 +14,6 @@ export class roomNameDTO {
),
{ message: "le nom de conférence n'est pas valide" },
)
@ApiProperty({ type: String, description: 'nom de la conférence' })
roomName: string;
}
Loading

0 comments on commit da75a03

Please sign in to comment.