Skip to content

Commit

Permalink
Merge pull request #141 from boostcampwm2023/BE-getUserBlockList-#137
Browse files Browse the repository at this point in the history
[BE/#137] GET users/block API 구현
  • Loading branch information
koomin1227 authored Nov 23, 2023
2 parents beb592a + ad93b4b commit bcc2ed8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BE/src/entities/blockUser.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 6 additions & 5 deletions BE/src/users-block/users-block.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import { UsersBlockService } from './users-block.service';
export class UsersBlockController {
constructor(private readonly usersBlockService: UsersBlockService) {}

@Get()
async blockUserList() {
const id = 'qwe';
return this.usersBlockService.getBlockUser(id);
}

@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);
Expand Down
20 changes: 18 additions & 2 deletions BE/src/users-block/users-block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,24 @@ export class UsersBlockService {
}
}

findAll() {
return `This action returns all usersBlock`;
async getBlockUser(id: string) {
const res = await this.blockUserRepository.find({
where: { blocker: id, 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) {
Expand Down

0 comments on commit bcc2ed8

Please sign in to comment.