From 006c8e6ddcedd0faec92577d27f171c6a1e8a88c Mon Sep 17 00:00:00 2001 From: yang Date: Wed, 27 Nov 2024 16:08:11 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20User=20=EA=B2=80=EC=83=89=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/server/src/account/account.module.ts | 3 ++- apps/server/src/account/user.controller.ts | 14 ++++++++++++++ apps/server/src/account/user.service.ts | 11 ++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 apps/server/src/account/user.controller.ts diff --git a/apps/server/src/account/account.module.ts b/apps/server/src/account/account.module.ts index f8236c8..471538e 100644 --- a/apps/server/src/account/account.module.ts +++ b/apps/server/src/account/account.module.ts @@ -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, diff --git a/apps/server/src/account/user.controller.ts b/apps/server/src/account/user.controller.ts new file mode 100644 index 0000000..2894ba2 --- /dev/null +++ b/apps/server/src/account/user.controller.ts @@ -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); + } +} diff --git a/apps/server/src/account/user.service.ts b/apps/server/src/account/user.service.ts index 5b83f4c..39afc2d 100644 --- a/apps/server/src/account/user.service.ts +++ b/apps/server/src/account/user.service.ts @@ -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'; @@ -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'], + }); + } }