Skip to content

Commit

Permalink
feat: User 검색 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchef1 committed Nov 28, 2024
1 parent 0a94fcf commit 006c8e6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion apps/server/src/account/account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { RefreshTokenGuard } from '@/account/guard/refreshToken.guard';
import { AuthService } from '@/account/auth.service';
import { Account } from '@/account/entity/account.entity';
import { UserService } from './user.service';
import { UserController } from './user.controller';

@Module({
imports: [JwtModule.register({ global: true }), TypeOrmModule.forFeature([Account])],
controllers: [AuthController],
controllers: [AuthController, UserController],
providers: [
AuthService,
UserService,
Expand Down
14 changes: 14 additions & 0 deletions apps/server/src/account/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Controller, Get, Query } from '@nestjs/common';
import { UserService } from './user.service';
import { ResponseMessage } from '@/common/decorator/response-message.decorator';

@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}

@Get()
@ResponseMessage('유저 정보가 성공적으로 조회되었습니다.')
async searchUsers(@Query('search') query: string) {
return this.userService.searchUsers(query);
}
}
11 changes: 10 additions & 1 deletion apps/server/src/account/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { Like, Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Account } from './entity/account.entity';

Expand All @@ -16,4 +16,13 @@ export class UserService {
user.profileImage = profileImage;
return this.userRepository.save(user);
}

async searchUsers(query: string) {
return this.userRepository.find({
where: {
username: Like(`${query}%`),
},
select: ['id', 'username', 'profileImage'],
});
}
}

0 comments on commit 006c8e6

Please sign in to comment.