Skip to content

Commit

Permalink
added group search
Browse files Browse the repository at this point in the history
  • Loading branch information
omersafakbebek committed Dec 23, 2023
1 parent 331b177 commit eeff73f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ludos/backend/src/controllers/search.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions ludos/backend/src/dtos/search/response/search.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] })
Expand All @@ -17,4 +18,8 @@ export class SearchResponseDto {
@Type(() => PostListResponseDto)
@Expose()
posts: PostListResponseDto[];
@ApiProperty({ type: () => [GroupListResponseDto] })
@Type(() => GroupListResponseDto)
@Expose()
groups: GroupListResponseDto[];
}
12 changes: 12 additions & 0 deletions ludos/backend/src/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ 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 {
constructor(
private readonly userRepository: UserRepository,
private readonly gameRepository: GameRepository,
private readonly postRepository: PostRepository,
private readonly groupRepository: GroupRepository,
) {}
public async search(
searchKey: string,
Expand Down Expand Up @@ -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,
};
}
}

0 comments on commit eeff73f

Please sign in to comment.