Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 📝 Add params in swagger for searchapplications #146

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
thomashbrnrd marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Loading