From 915c7a7a647d54b78e3ce42ee77c8150bcfed151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=AA=E1=86=BC=E1=84=92?= =?UTF-8?q?=E1=85=AE=E1=86=AB?= Date: Thu, 23 Nov 2023 23:38:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[BE]=20Feat=20:=20GET=20/block/users=20API?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/entities/blockUser.entity.ts | 2 +- BE/src/users-block/users-block.controller.ts | 10 +++++----- BE/src/users-block/users-block.service.ts | 20 ++++++++++++++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/BE/src/entities/blockUser.entity.ts b/BE/src/entities/blockUser.entity.ts index a6c258d..f3ecb3d 100644 --- a/BE/src/entities/blockUser.entity.ts +++ b/BE/src/entities/blockUser.entity.ts @@ -17,6 +17,6 @@ export class BlockUserEntity { blockerUser: UserEntity; @ManyToOne(() => UserEntity, (blocked) => blocked.user_hash) - @JoinColumn({ name: 'blocked_user' }) + @JoinColumn({ name: 'blocked_user', referencedColumnName: 'user_hash' }) blockedUser: UserEntity; } diff --git a/BE/src/users-block/users-block.controller.ts b/BE/src/users-block/users-block.controller.ts index 9192bf0..5a403a2 100644 --- a/BE/src/users-block/users-block.controller.ts +++ b/BE/src/users-block/users-block.controller.ts @@ -5,16 +5,16 @@ import { UsersBlockService } from './users-block.service'; export class UsersBlockController { constructor(private readonly usersBlockService: UsersBlockService) {} + @Get() + async blockUserList() { + return this.usersBlockService.getBlockUser(); + } + @Post('/:id') async blockUserAdd(@Param('id') id: string) { await this.usersBlockService.addBlockUser(id); } - @Get() - findAll() { - return this.usersBlockService.findAll(); - } - @Delete(':id') remove(@Param('id') id: string) { return this.usersBlockService.remove(+id); diff --git a/BE/src/users-block/users-block.service.ts b/BE/src/users-block/users-block.service.ts index 49cff71..0ab1d97 100644 --- a/BE/src/users-block/users-block.service.ts +++ b/BE/src/users-block/users-block.service.ts @@ -46,8 +46,24 @@ export class UsersBlockService { } } - findAll() { - return `This action returns all usersBlock`; + async getBlockUser() { + const res = await this.blockUserRepository.find({ + where: { blocker: 'qwe', status: true }, + relations: ['blockedUser'], + }); + + const blockedUsers = res.reduce((acc, cur) => { + const user = { + nickname: cur.blockedUser.nickname, + profile_img: cur.blockedUser.profile_img, + user_id: cur.blockedUser.user_hash, + }; + + acc.push(user); + return acc; + }, []); + + return blockedUsers; } remove(id: number) { From ad93b4b4abbbc1a66dffdeeb495246b5f41c8ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=AA=E1=86=BC=E1=84=92?= =?UTF-8?q?=E1=85=AE=E1=86=AB?= Date: Thu, 23 Nov 2023 23:51:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[BE]=20Fix=20:=20userID=20=EB=A5=BC=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=A1=9C=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/users-block/users-block.controller.ts | 3 ++- BE/src/users-block/users-block.service.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/BE/src/users-block/users-block.controller.ts b/BE/src/users-block/users-block.controller.ts index 5a403a2..c63e6db 100644 --- a/BE/src/users-block/users-block.controller.ts +++ b/BE/src/users-block/users-block.controller.ts @@ -7,7 +7,8 @@ export class UsersBlockController { @Get() async blockUserList() { - return this.usersBlockService.getBlockUser(); + const id = 'qwe'; + return this.usersBlockService.getBlockUser(id); } @Post('/:id') diff --git a/BE/src/users-block/users-block.service.ts b/BE/src/users-block/users-block.service.ts index 0ab1d97..ee314ce 100644 --- a/BE/src/users-block/users-block.service.ts +++ b/BE/src/users-block/users-block.service.ts @@ -46,9 +46,9 @@ export class UsersBlockService { } } - async getBlockUser() { + async getBlockUser(id: string) { const res = await this.blockUserRepository.find({ - where: { blocker: 'qwe', status: true }, + where: { blocker: id, status: true }, relations: ['blockedUser'], });