From eeff73f3448ddaeb99780710ab4b66fd9813bcf3 Mon Sep 17 00:00:00 2001 From: omersafakbebek Date: Sat, 23 Dec 2023 19:40:18 +0300 Subject: [PATCH] added group search --- ludos/backend/src/controllers/search.controller.ts | 2 +- .../src/dtos/search/response/search.response.dto.ts | 5 +++++ ludos/backend/src/services/search.service.ts | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ludos/backend/src/controllers/search.controller.ts b/ludos/backend/src/controllers/search.controller.ts index 6f3b7c92..285cf591 100644 --- a/ludos/backend/src/controllers/search.controller.ts +++ b/ludos/backend/src/controllers/search.controller.ts @@ -20,7 +20,7 @@ export class SearchController { }) @ApiBearerAuth() @ApiOperation({ - summary: 'Search for users, games and posts', + summary: 'Search for users, games, groups and posts', }) @UseInterceptors(new SerializerInterceptor(SearchResponseDto)) @Get('/:searchKey') diff --git a/ludos/backend/src/dtos/search/response/search.response.dto.ts b/ludos/backend/src/dtos/search/response/search.response.dto.ts index 3da31f75..062cadf9 100644 --- a/ludos/backend/src/dtos/search/response/search.response.dto.ts +++ b/ludos/backend/src/dtos/search/response/search.response.dto.ts @@ -3,6 +3,7 @@ import { GameListResponseDto } from '../../game/response/list.response'; import { PostListResponseDto } from '../../post/response/list.response.dto'; import { UserInOtherResponsesDto } from '../../user/response/user-in-other-responses.dto'; import { Expose, Type } from 'class-transformer'; +import { GroupListResponseDto } from '../../group/response/list.response.dto'; export class SearchResponseDto { @ApiProperty({ type: () => [UserInOtherResponsesDto] }) @@ -17,4 +18,8 @@ export class SearchResponseDto { @Type(() => PostListResponseDto) @Expose() posts: PostListResponseDto[]; + @ApiProperty({ type: () => [GroupListResponseDto] }) + @Type(() => GroupListResponseDto) + @Expose() + groups: GroupListResponseDto[]; } diff --git a/ludos/backend/src/services/search.service.ts b/ludos/backend/src/services/search.service.ts index 0ebe0871..e4950983 100644 --- a/ludos/backend/src/services/search.service.ts +++ b/ludos/backend/src/services/search.service.ts @@ -3,6 +3,7 @@ import { UserRepository } from '../repositories/user.repository'; import { GameRepository } from '../repositories/game.repository'; import { PostRepository } from '../repositories/post.repository'; import { SearchResponseDto } from '../dtos/search/response/search.response.dto'; +import { GroupRepository } from '../repositories/group.repository'; @Injectable() export class SearchService { @@ -10,6 +11,7 @@ export class SearchService { private readonly userRepository: UserRepository, private readonly gameRepository: GameRepository, private readonly postRepository: PostRepository, + private readonly groupRepository: GroupRepository, ) {} public async search( searchKey: string, @@ -37,10 +39,20 @@ export class SearchService { undefined, userId, ); + const groups = await this.groupRepository.findGroups( + 1, + 100, + searchKey, + undefined, + undefined, + undefined, + userId, + ) return { users: users.items, games: games.items, posts: posts.items, + groups: groups.items, }; } }