Skip to content

Commit

Permalink
Merge pull request #39 from DevKor-github/feature/friendNew
Browse files Browse the repository at this point in the history
Feature/friend new
  • Loading branch information
JeongYeonSeung authored Jul 13, 2024
2 parents aa6d1c0 + af4bdb5 commit 5056346
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 169 deletions.
8 changes: 4 additions & 4 deletions src/friendship/dto/get-friend-timetable.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
import { IsNotEmpty, IsString } from 'class-validator';

export class GetFriendTimetableRequestDto {
@IsNumber()
@IsString()
@IsNotEmpty()
@ApiProperty({ description: '친구 ID' })
friendId: number;
@ApiProperty({ description: '친구 추가용 ID' })
username: string;

@IsString()
@IsNotEmpty()
Expand Down
10 changes: 0 additions & 10 deletions src/friendship/dto/reject-friendship-response.dto.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/friendship/dto/search-user-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class SearchUserResponseDto {
@ApiProperty({
description:
'유저 상태 (본인 / 친구 / 상대방의 수락 대기 중 / 나의 수락 보류 중 / 그 외)',
enum: Status,
})
status: Status;
}
57 changes: 50 additions & 7 deletions src/friendship/friendship.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { GetFriendResponseDto } from './dto/get-friend-response.dto';
import { GetWaitingFriendResponseDto } from './dto/get-waiting-friend-response.dto';
import { UpdateFriendshipResponseDto } from './dto/update-friendship-response.dto';
import { DeleteFriendshipResponseDto } from './dto/delete-friendship-response.dto';
import { RejectFriendshipResponseDto } from './dto/reject-friendship-response.dto';
import { SearchUserResponseDto } from './dto/search-user-response.dto';
import {
ApiBearerAuth,
Expand Down Expand Up @@ -93,10 +92,10 @@ export class FriendshipController {
'친구 ID, 연도, 학기를 입력받아 해당 학기에 친구의 대표 시간표를 조회합니다.',
})
@ApiQuery({
name: 'friendId',
name: 'username',
type: 'string',
required: true,
description: '친구 ID',
description: '친구 추가용 ID (username)',
})
@ApiQuery({
name: 'year',
Expand Down Expand Up @@ -162,11 +161,29 @@ export class FriendshipController {
isArray: true,
type: GetWaitingFriendResponseDto,
})
async getWaitingFriendList(
async getReceivedWaitingFriendList(
@User() user: AuthorizedUserDto,
): Promise<GetWaitingFriendResponseDto[]> {
const userId = user.id;
return await this.friendshipService.getWaitingFriendList(userId);
return await this.friendshipService.getReceivedWaitingFriendList(userId);
}

@UseGuards(JwtAuthGuard)
@Get('sent')
@ApiOperation({
summary: '내가 친구 요청을 보낸 유저 목록 조회',
description: '내가 친구 요청을 보낸 유저 목록을 조회합니다.',
})
@ApiOkResponse({
description: '내가 친구 요청을 보낸 유저 목록',
isArray: true,
type: GetWaitingFriendResponseDto,
})
async getSentWaitingFriendList(
@User() user: AuthorizedUserDto,
): Promise<GetWaitingFriendResponseDto[]> {
const userId = user.id;
return await this.friendshipService.getSentWaitingFriendList(userId);
}

@UseGuards(JwtAuthGuard)
Expand Down Expand Up @@ -209,19 +226,45 @@ export class FriendshipController {
})
@ApiOkResponse({
description: '친구 요청 거절 성공 시',
type: RejectFriendshipResponseDto,
type: DeleteFriendshipResponseDto,
})
async rejectFriendshipRequest(
@User() user: AuthorizedUserDto,
@Param('friendshipId') friendshipId: number,
): Promise<RejectFriendshipResponseDto> {
): Promise<DeleteFriendshipResponseDto> {
const userId = user.id;
return await this.friendshipService.rejectFriendshipRequest(
userId,
friendshipId,
);
}

@UseGuards(JwtAuthGuard)
@Delete('sent/:friendshipId')
@ApiOperation({
summary: '보낸 친구 요청 취소하기',
description: 'friendshipId를 받아 해당 friendship 레코드를 삭제합니다.',
})
@ApiParam({
name: 'friendshipId',
description: '해당 친구 요청에 대한 friendship id',
type: Number,
})
@ApiOkResponse({
description: '친구 요청 취소 성공 시',
type: DeleteFriendshipResponseDto,
})
async cancelFriendshipRequest(
@User() user: AuthorizedUserDto,
@Param('friendshipId') friendshipId: number,
): Promise<DeleteFriendshipResponseDto> {
const userId = user.id;
return await this.friendshipService.cancelFriendshipRequest(
userId,
friendshipId,
);
}

@UseGuards(JwtAuthGuard)
@Delete('/:friendshipId')
@ApiOperation({
Expand Down
35 changes: 7 additions & 28 deletions src/friendship/friendship.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ export class FriendshipRepository extends Repository<FriendshipEntity> {
super(FriendshipEntity, dataSource.createEntityManager());
}

async createFriendship(
fromUserId: number,
toUserId: number,
): Promise<FriendshipEntity> {
const friendship = this.create({
fromUser: { id: fromUserId },
toUser: { id: toUserId },
areWeFriend: false,
});
return await this.save(friendship);
}

async findFriendshipByFriendshipId(
friendshipId: number,
): Promise<FriendshipEntity> {
Expand Down Expand Up @@ -100,21 +88,12 @@ export class FriendshipRepository extends Repository<FriendshipEntity> {
});
}

async updateFriendship(
friendshipId: number,
areWeFriend: boolean,
): Promise<boolean> {
const updateResult = await this.update(
{ id: friendshipId },
{ areWeFriend: areWeFriend },
);

return updateResult.affected ? true : false;
}

async deleteFriendship(friendshipId: number): Promise<boolean> {
const deleteResult = await this.softDelete(friendshipId);

return deleteResult.affected ? true : false;
async findSentFriendshipsByUserId(
userId: number,
): Promise<FriendshipEntity[]> {
return await this.find({
where: [{ fromUser: { id: userId }, areWeFriend: false }],
relations: ['fromUser', 'toUser'],
});
}
}
Loading

0 comments on commit 5056346

Please sign in to comment.