Skip to content

Commit

Permalink
Merge pull request #667 from bounswe/be-622/user-keyword-search
Browse files Browse the repository at this point in the history
username keyword search is added
  • Loading branch information
batuhancetin authored Dec 22, 2023
2 parents b44740c + e8035be commit 76b5023
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/backend/src/poll/poll.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class PollController {
return await this.pollService.syncVectorStore();
}

@UseGuards(AuthGuard, VerificationGuard)
@ApiResponse({
status: 200,
description: 'Polls are searched successfully.',
Expand Down
11 changes: 11 additions & 0 deletions app/backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Req,
Put,
NotFoundException,
Query,
} from '@nestjs/common';
import { UserService } from './user.service';

Expand Down Expand Up @@ -40,6 +41,16 @@ export class UserController {
return await this.userService.findAll();
}

@Get('search/:username')
@ApiResponse({ status: 200, description: 'Users are fetched successfully.', type: [GetUserResponseDto] })
@ApiResponse({
status: 500,
description: 'Internal server error, contact with backend team.',
})
public async searchUsernames(@Query('username') username: string): Promise<GetUserResponseDto[]> {
return await this.userService.searchUsernames(username);
}

@ApiResponse({ status: 200, description: 'User is fetched successfully.', type: GetUserResponseDto })
@ApiResponse({ status: 404, description: 'User is not found.' })
@ApiResponse({
Expand Down
7 changes: 7 additions & 0 deletions app/backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ export class UserService {
await this.userRepository.save(user);
}

public async searchUsernames(query: string): Promise<User[]> {
return this.userRepository
.createQueryBuilder('user')
.where('user.username ILIKE :query', { query: `%${query}%` })
.getMany();
}

public generateCode(): number {
return Math.floor(Math.random() * 9000 + 1000);
}
Expand Down

0 comments on commit 76b5023

Please sign in to comment.