Skip to content

Commit

Permalink
feat: 📝 Add parmas in swagger for searchapplications
Browse files Browse the repository at this point in the history
  • Loading branch information
Carolinedanslesnuages committed Dec 10, 2024
1 parent 97ee0fd commit 39c1270
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
2 changes: 0 additions & 2 deletions client/src/views/GlobalSearch.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<script setup lang="ts">
import ExportApplications from "@/components/ExportApplications.vue";
import SearchApplications from "@/components/SearchApplications.vue";
</script>

<template>
<div>
<h2>Rechercher une Application</h2>
<ExportApplications />
<SearchApplications />
</div>
</template>
18 changes: 15 additions & 3 deletions server/src/application/application.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import {
import { ApplicationService } from './application.service';
import { CreateApplicationDto } from './dto/create-application.dto';
import { UpdateApplicationDto } from './dto/update-application.dto';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiExcludeEndpoint,
} from '@nestjs/swagger';
import { SearchApplicationDto } from './dto/search-application.dto';
import { GetApplicationDto } from './dto/get-application.dto';
import { ExportService } from './export.service';
Expand Down Expand Up @@ -60,14 +65,21 @@ export class ApplicationController {
}

@Get('search')
async searchApplications(@Query() query: SearchApplicationDto) {
return await this.applicationService.searchApplications(query);
@ApiOperation({ summary: 'Rechercher des applications' })
@ApiResponse({
status: 200,
description:
'Liste des applications correspondant aux critères de recherche.',
})
async searchApplications(@Query() searchParams: SearchApplicationDto) {
return await this.applicationService.searchApplications(searchParams);
}

@Get('export')
@ApiOperation({ summary: 'Exporter les applications' })
@ApiResponse({ status: 200, description: 'Export réalisé avec succès.' })
@ApiResponse({ status: 400, description: "Erreur lors de l'exportation." })
@ApiExcludeEndpoint()
async exportApplications(
@Query() query: SearchApplicationDto,
@Response() res,
Expand Down
7 changes: 5 additions & 2 deletions server/src/application/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ApplicationService {
}

public async searchApplications(searchParams: SearchApplicationDto) {
const { label } = searchParams;
const { label, page = 1, limit = 12 } = searchParams;

const whereClause: Prisma.ApplicationWhereInput = {
...(label
Expand All @@ -109,11 +109,14 @@ export class ApplicationService {
},
};

const skip = (page - 1) * limit;

try {
const applications = await this.prisma.application.findMany({
where: whereClause,
orderBy: orderByClause,
take: 12,
take: limit,
skip: skip,
include: {
lifecycle: true,
actors: true,
Expand Down
30 changes: 29 additions & 1 deletion server/src/application/dto/search-application.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import { IsOptional, IsString } from 'class-validator';
// src/application/dto/search-application.dto.ts

import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsNumber, IsOptional, IsString, Min } from 'class-validator';
import { Type } from 'class-transformer';

export class SearchApplicationDto {
@ApiPropertyOptional({
description: "Filtrer par label de l'application",
example: 'Mon Application',
})
@IsOptional()
@IsString()
label?: string;

@ApiPropertyOptional({
description: 'Numéro de la page pour la pagination',
example: 1,
})
@IsOptional()
@Type(() => Number) // Transformation en nombre
@IsNumber({}, { message: 'Le champ page doit être un nombre valide.' })
@Min(1, { message: 'Le champ page doit être au moins 1.' })
page?: number;

@ApiPropertyOptional({
description: "Nombre d'éléments par page",
example: 12,
})
@IsOptional()
@Type(() => Number) // Transformation en nombre
@IsNumber({}, { message: 'Le champ limit doit être un nombre valide.' })
@Min(1, { message: 'Le champ limit doit être au moins 1.' })
limit?: number;
}

0 comments on commit 39c1270

Please sign in to comment.