Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] Main Merge #612

Merged
merged 97 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
c0c01c4
[BE] Feat : 엔티티 연관관계 수정
koomin1227 Dec 19, 2023
3b88fb6
[BE] Feat : post custom repository 생성
koomin1227 Dec 19, 2023
0fa4f34
[BE] Test : post.repository.ts 테스트 코드 작성
koomin1227 Dec 19, 2023
afaeaf7
[BE] Feat : 차단된 유저, 게시글 제외하고 게시글 조회하는 기능 수정
koomin1227 Dec 19, 2023
9b27805
[BE] Feat : 게시글 조회시 차단 목록을 같이 가져오도록 수정
koomin1227 Dec 19, 2023
aa297cc
[BE] Feat : 특정 사용자가 차단한 기록을 게시글 조회시 포함도록 수정
koomin1227 Dec 19, 2023
26c6ee4
[BE] Refactor : 사용하지 않는 코드 삭제
koomin1227 Dec 19, 2023
677b76d
[BE] Feat : cascade 옵션 적용
koomin1227 Dec 19, 2023
47c05c9
[BE] Feat : softDelete 시 cascade 하게 삭제되는 메서드 추가
koomin1227 Dec 19, 2023
b843df1
[BE] Refactor : cascade 삭제를 PostRepository 로 분리
koomin1227 Dec 19, 2023
d9c505a
[BE] Feat : 게시글 삭제시 cascade 옵션을 위해 트랜잭션 적용
koomin1227 Dec 21, 2023
8350631
Merge pull request #578 from boostcampwm2023/BE-ChangePost-#577
namewhat99 Dec 21, 2023
da3629a
[BE] Feat : transaction.interceptor.ts 생성
koomin1227 Dec 21, 2023
bc9c07a
[BE] Feat : BaseRepository 생성
koomin1227 Dec 21, 2023
b33ea97
[BE] Feat : custom PostRepository가 BaseRepository 를 상속 하도록 변경
koomin1227 Dec 21, 2023
ad602bb
[BE] Feat : transaction interceptor를 사용하는 방식으로 변경
koomin1227 Dec 21, 2023
d739265
[BE] Test : post repository 테스트 코드 수정
koomin1227 Dec 21, 2023
0cf4559
[BE] Refactor : 사용하지 않는 import 삭제
koomin1227 Dec 21, 2023
95c9915
[BE] Test : 사용하지 않는 import 삭제
koomin1227 Dec 21, 2023
d1fb69f
[BE] Feat : 쿼리 파람의 page를 cursorId로 변경
koomin1227 Dec 23, 2023
bc2ca81
[BE] Feat : 응답 데이터 변경
koomin1227 Dec 23, 2023
fabdeed
[BE] Test : page -> cursorId로 변경
koomin1227 Dec 23, 2023
77fb925
Merge pull request #586 from boostcampwm2023/BE-ChangePostList-#585
namewhat99 Dec 23, 2023
720cb23
[BE] Feat : s3 provider 생성
koomin1227 Dec 24, 2023
ab34122
[BE] Feat : image 모듈 분리
koomin1227 Dec 24, 2023
1a25184
[BE] Feat : postImage repository 생성
koomin1227 Dec 24, 2023
d31cfa2
[BE] Feat : image 모듈 app module에 등록
koomin1227 Dec 24, 2023
1d5fdab
[BE] Feat : post에서 image 모듈을 가져와 로직 분리
koomin1227 Dec 24, 2023
639a006
[BE] Feat : 게시글 등록에 트랜잭션 적용
koomin1227 Dec 24, 2023
4499e9b
[BE] Feat : 이미지 수정 기능 추가
koomin1227 Dec 24, 2023
bec7a5d
[BE] Feat : 이미지 수정 로직 분리
koomin1227 Dec 24, 2023
70a4bc9
Merge pull request #581 from boostcampwm2023/BE-ChangeTransaction-#580
namewhat99 Dec 26, 2023
292cda2
[BE] Feat : uuid 모듈 변경
koomin1227 Dec 29, 2023
db80e02
[BE] Test : image service 테스트 코드 작성
koomin1227 Dec 29, 2023
240debe
[BE] Refactor : uuid 모듈 변경
koomin1227 Dec 29, 2023
6bbe708
Merge pull request #589 from boostcampwm2023/BE-SeparateImageService-…
namewhat99 Dec 30, 2023
9eb5f6e
[BE] test : findPosts, findPostById 테스트 코드 작성
koomin1227 Jan 6, 2024
0b62fb0
[BE] Feat : 게시글 조회시 user 테이블을 참조하지 않도록 수정
koomin1227 Jan 6, 2024
71e87c4
[BE] Test : checkAuth 테스트 코드 작성
koomin1227 Jan 6, 2024
4a4494c
[BE] Test : findPostsTitles 테스트 코드 작성
koomin1227 Jan 6, 2024
5251751
[BE] Test : updatePostById,createPost, updatePostThumbnail, removePos…
koomin1227 Jan 6, 2024
b9720f4
Merge pull request #595 from boostcampwm2023/BE-TestPostService-#593
namewhat99 Jan 7, 2024
275ec3d
[BE] Feat : user repository 생성
koomin1227 Jan 7, 2024
3abcf54
[BE] Refactor : 유저 삭제시 차단 목록 삭제코드 변경
koomin1227 Jan 7, 2024
664e6d1
[BE] Refactor : user service의 이미지 처리 분리
koomin1227 Jan 7, 2024
0c55e64
[BE] Refactor : checkAuth의 사용하지 않는 반환값 제거
koomin1227 Jan 7, 2024
9a3fd52
[BE] Refactor : 사용하지 않는 의존성 제거
koomin1227 Jan 7, 2024
0853fae
[BE] Feat : notification module 생성
koomin1227 Jan 7, 2024
b4039aa
[BE] Feat : NotificationService 생성자 구현
koomin1227 Jan 7, 2024
456c2d1
[BE] Feat : registerToken 구현
koomin1227 Jan 7, 2024
6257538
[BE] Feat : 토큰 삭제 기능 구현
koomin1227 Jan 7, 2024
fd593d0
[BE] Feat : 토큰을 가져오는 메서드 구현
koomin1227 Jan 7, 2024
5fcfbad
[BE] Feat : 채팅 알림을 보내는 메서드 구현
koomin1227 Jan 7, 2024
23b1e5c
[BE] Feat : registrationTokenRepository 로 분리
koomin1227 Jan 7, 2024
de7b250
[BE] Refactor : fcmHandler 의존성 제거
koomin1227 Jan 7, 2024
dd96197
[BE] Refactor : 사용하지 않는 유저 생성 컨트롤러 제거
koomin1227 Jan 7, 2024
8026a6c
Feat : chatRoom Entity 수정
namewhat99 Jan 8, 2024
444e74f
Feat : 채팅 보낼때 상대방의 나가기 여부 확인
namewhat99 Jan 8, 2024
5741b63
Fix : chatroom 의 user,writer left 를 boolean 으로 변경
namewhat99 Jan 8, 2024
0016f86
Fix: unreadChat , chatRoomList boolean 으로 수정
namewhat99 Jan 8, 2024
590e35c
Fix: gitIgnore 파일 삭제
namewhat99 Jan 8, 2024
5dca4a8
[BE] Refactor : user module의 사용하지 않는 provider 제거
koomin1227 Jan 8, 2024
a8b7c9e
Fix : .gitignore 파일₩
namewhat99 Jan 9, 2024
a5f214a
Feat : 채팅방 나가기 기능 추가
namewhat99 Jan 9, 2024
7c040f8
Fix : 메서드 get 에서 patch 로 변경
namewhat99 Jan 9, 2024
300dff7
Merge pull request #601 from boostcampwm2023/BE-checkLeft-#000
koomin1227 Jan 9, 2024
e9b228c
Feat : 마지막 채팅 chatRoom 에 같이 저장
namewhat99 Jan 9, 2024
cbdf454
Feat : 마지막 채팅 join 으로 채팅방목록 api 개선
namewhat99 Jan 9, 2024
3dbb785
Merge pull request #602 from boostcampwm2023/BE-saveLastChat-#001
koomin1227 Jan 10, 2024
ca8b194
Feat : 채팅방 entity 수정
namewhat99 Jan 11, 2024
ddd94c0
Feat : 채팅방 나가면 나간 시간 기록
namewhat99 Jan 11, 2024
474e43f
Feat : 채팅방 나간 후 돌아오면 이전 채팅 안 뜨게 설정
namewhat99 Jan 11, 2024
9e3755a
Fix : 주석 제거
namewhat99 Jan 11, 2024
2ca1a1e
[BE] Refactor : S3Handler.ts 삭제
koomin1227 Jan 11, 2024
29c3519
[BE] Refactor : 기본 이미지 처리를 널 병합 연산자로 변경
koomin1227 Jan 11, 2024
8937e8a
[BE] Refactor : 사용하지 않는 return 문 제거
koomin1227 Jan 11, 2024
a20e44b
[BE] fix : 토큰이 없는 경우 Null 반환하도록 수정
koomin1227 Jan 11, 2024
094ab83
[BE] test : notification.service 테스트 코드 작성
koomin1227 Jan 11, 2024
b15592f
Merge pull request #605 from boostcampwm2023/BE-SeparateUserService-#599
namewhat99 Jan 12, 2024
bff8a19
[BE] Refactor : 파일 경로 수정
koomin1227 Jan 12, 2024
b6a410d
[BE] Test : userService test 세팅
koomin1227 Jan 12, 2024
3c85fdb
[BE] Test : checkAuth 테스트
koomin1227 Jan 12, 2024
b025a99
[BE] Test : findUserById 테스트
koomin1227 Jan 12, 2024
4488d80
[BE] Refactor : 불필요한 인자 삭제
koomin1227 Jan 12, 2024
f093c7f
[BE] Test : updateUserById 테스트
koomin1227 Jan 12, 2024
106ba72
[BE] Refactor : 사용하지 않는 인자 제거
koomin1227 Jan 12, 2024
7482eff
[BE] Test : removeUser 테스트
koomin1227 Jan 12, 2024
a57e2b6
Fix : PR 수정 사항 반영
namewhat99 Jan 13, 2024
fafefd4
Fix : 오류 코드 수정
namewhat99 Jan 13, 2024
05e5514
Merge pull request #607 from boostcampwm2023/BE-TestUserService-#606
namewhat99 Jan 14, 2024
de92ad7
Feat : chat 가져올때 pagination 코드 미리 작성
namewhat99 Jan 14, 2024
c10de5a
Feat : 채팅 페이지네이션 분리 및 주석처리
namewhat99 Jan 14, 2024
00adc4e
Merge pull request #604 from boostcampwm2023/BE-fixChat-#603
namewhat99 Jan 14, 2024
27d9f32
Feat : 채팅에서 차단 여부 체크
namewhat99 Jan 21, 2024
56804b3
Merge pull request #610 from boostcampwm2023/BE-checkChatBlock-#004
koomin1227 Jan 21, 2024
fd96917
Fix : unread 수정
namewhat99 Jan 22, 2024
db56a6d
Merge pull request #611 from boostcampwm2023/BE-hotfix
namewhat99 Jan 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions BE/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,4 @@ lerna-debug.log*

/envs
/logs
firebase.json

village-2ed97-firebase-adminsdk-1axqh-408a2ee88b.json
54 changes: 16 additions & 38 deletions BE/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion BE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"typeorm": "^0.3.17",
"uuidv4": "^6.2.13",
"uuid": "^9.0.1",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1",
"ws": "^8.14.2"
Expand Down
4 changes: 4 additions & 0 deletions BE/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { ChatModule } from './chat/chat.module';
import { CacheModule } from '@nestjs/cache-manager';
import { RedisConfigProvider } from './config/redis.config';
import { ReportModule } from './report/report.module';
import { ImageModule } from './image/image.module';
import { NotificationModule } from './notification/notification.module';

@Module({
imports: [
Expand All @@ -40,6 +42,8 @@ import { ReportModule } from './report/report.module';
LoginModule,
ChatModule,
ReportModule,
ImageModule,
NotificationModule,
],
controllers: [AppController],
providers: [
Expand Down
8 changes: 8 additions & 0 deletions BE/src/chat/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
Get,
HttpException,
Param,
Patch,
Post,
Put,
UseGuards,
} from '@nestjs/common';
import { ChatService } from './chat.service';
Expand Down Expand Up @@ -52,6 +54,12 @@ export class ChatController {
return await this.chatService.unreadChat(userId);
}

@Patch('leave/:id')
@UseGuards(AuthGuard)
async leaveChatRoom(@Param('id') id: number, @UserHash() userId: string) {
return await this.chatService.leaveChatRoom(id, userId);
}

@Get()
async testPush(@Body() body) {
await this.fcmHandler.sendPush(body.user, {
Expand Down
129 changes: 97 additions & 32 deletions BE/src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ export class ChatService {
chat.chat_room = message.room_id;
chat.is_read = is_read;
chat.count = message.count;
await this.chatRepository.save(chat);
const lastChat = await this.chatRepository.save(chat);

await this.chatRoomRepository.update(
{
id: message.room_id,
},
{
last_chat_id: lastChat.id,
},
);
}

async createRoom(
Expand Down Expand Up @@ -79,24 +88,12 @@ export class ChatService {
async findRoomList(userId: string) {
const chatListInfo = { all_read: true, chat_list: [] };

const subquery = this.chatRepository
.createQueryBuilder('chat')
.select('chat.id', 'id')
.addSelect('chat.chat_room', 'chat_room')
.addSelect('chat.message', 'message')
.addSelect('chat.create_date', 'create_date')
.addSelect('chat.is_read', 'is_read')
.addSelect('chat.sender', 'sender')
.where(
'chat.id IN (SELECT MAX(chat.id) FROM chat GROUP BY chat.chat_room)',
);

const rooms = await this.chatRoomRepository
.createQueryBuilder('chat_room')
.innerJoin(
'(' + subquery.getQuery() + ')',
'chat_room.lastChat',
'chat_info',
'chat_room.id = chat_info.chat_room',
'chat_room.lastChat = chat_info.id',
)
.innerJoin(
'chat_room.writerUser',
Expand Down Expand Up @@ -126,7 +123,9 @@ export class ChatService {
'chat_info.sender as sender',
])
.where('chat_room.writer = :userId', { userId: userId })
.andWhere('chat_room.writer_hide IS false')
.orWhere('chat_room.user = :userId', { userId: userId })
.andWhere('chat_room.user_hide IS false')
.orderBy('chat_info.create_date', 'DESC')
.getRawMany();

Expand Down Expand Up @@ -160,24 +159,12 @@ export class ChatService {
}

async unreadChat(userId: string) {
const subquery = this.chatRepository
.createQueryBuilder('chat')
.select('chat.id', 'id')
.addSelect('chat.chat_room', 'chat_room')
.addSelect('chat.message', 'message')
.addSelect('chat.create_date', 'create_date')
.addSelect('chat.is_read', 'is_read')
.addSelect('chat.sender', 'sender')
.where(
'chat.id IN (SELECT MAX(chat.id) FROM chat GROUP BY chat.chat_room)',
);

const rooms = await this.chatRoomRepository
.createQueryBuilder('chat_room')
.innerJoin(
'(' + subquery.getQuery() + ')',
'chat_room.lastChat',
'chat_info',
'chat_room.id = chat_info.chat_room',
'chat_room.lastChat = chat_info.id',
)
.innerJoin(
'chat_room.writerUser',
Expand All @@ -204,7 +191,9 @@ export class ChatService {
'chat_info.sender as sender',
])
.where('chat_room.writer = :userId', { userId: userId })
.andWhere('chat_room.writer_hide IS false')
.orWhere('chat_room.user = :userId', { userId: userId })
.andWhere('chat_room.user_hide IS false')
.orderBy('chat_info.create_date', 'DESC')
.getRawMany();

Expand All @@ -217,7 +206,7 @@ export class ChatService {
return { all_read: true };
}

async findRoomById(roomId: number, userId: string) {
async makeAllRead(roomId: number, userId: string) {
await this.chatRepository
.createQueryBuilder('chat')
.update()
Expand All @@ -226,15 +215,57 @@ export class ChatService {
.andWhere('chat.is_read = :isRead', { isRead: false })
.andWhere('chat.sender != :userId', { userId: userId })
.execute();
}

const room = await this.chatRoomRepository.findOne({
/*async getRoomAndChatInfoPagination(roomId: number, chatId: number) {
return await this.chatRoomRepository
.createQueryBuilder('chat_room')
.innerJoinAndSelect('chat_room.chats', 'chat_info')
.innerJoinAndSelect('chat_room.writerUser', 'writer')
.innerJoinAndSelect('chat_room.userUser', 'user')
.where('chat_room.id = :roomId', { roomId: roomId })
.andWhere('chat_info.id < :chatId', { chatId: chatId })
.orderBy('chat_info.id', 'DESC')
.limit(30)
.getOne();
}*/

async getRoomAndChatInfo(roomId: number, userId: string) {
return await this.chatRoomRepository.findOne({
where: {
id: roomId,
},
relations: ['chats', 'userUser', 'writerUser'],
});
}

async findRoomById(roomId: number, userId: string) {
await this.makeAllRead(roomId, userId);

const room = await this.getRoomAndChatInfo(roomId, userId);

this.checkAuth(room, userId);

let chats = room.chats;

if (
room.writer === userId &&
room.writer_hide === false &&
room.writer_left_time !== null
) {
chats = chats.filter((chat) => {
return chat.create_date > room.writer_left_time;
});
} else if (
room.user === userId &&
room.user_hide === false &&
room.user_left_time !== null
) {
chats = chats.filter((chat) => {
return chat.create_date > room.user_left_time;
});
}

return {
writer: room.writer,
writer_profile_img:
Expand All @@ -247,7 +278,7 @@ export class ChatService {
? this.configService.get('DEFAULT_PROFILE_IMAGE')
: room.userUser.profile_img,
post_id: room.post_id,
chat_log: room.chats,
chat_log: chats,
};
}

Expand All @@ -256,6 +287,10 @@ export class ChatService {
throw new HttpException('존재하지 않는 채팅방입니다.', 404);
} else if (room.writer !== userId && room.user !== userId) {
throw new HttpException('권한이 없습니다.', 403);
} else if (room.writer === userId && room.writer_hide === true) {
throw new HttpException('숨긴 채팅방입니다.', 403);
} else if (room.user === userId && room.user_hide === true) {
throw new HttpException('숨긴 채팅방입니다.', 403);
}
}

Expand All @@ -264,6 +299,7 @@ export class ChatService {
where: { id: message.room_id },
relations: ['writerUser', 'userUser'],
});

const receiver: UserEntity =
chatRoom.writerUser.user_hash === message.sender
? chatRoom.userUser
Expand All @@ -280,6 +316,19 @@ export class ChatService {
await this.fcmHandler.sendPush(receiver.user_hash, pushMessage);
}

async checkOpponentLeft(roomId: number, userId: string) {
const room = await this.chatRoomRepository.findOne({
where: { id: roomId },
});

if (room.writer === userId && room.user_hide !== false) {
room.user_hide = false;
} else if (room.user === userId && room.writer_hide !== false) {
room.writer_hide = false;
}
await this.chatRoomRepository.save(room);
}

validateUser(authorization) {
try {
const payload: Payload = jwt.verify(
Expand All @@ -292,4 +341,20 @@ export class ChatService {
return null;
}
}

async leaveChatRoom(roomId: number, userId: string) {
const room = await this.chatRoomRepository.findOne({
where: { id: roomId },
});

if (room.writer === userId) {
room.writer_hide = true;
room.writer_left_time = new Date();
} else if (room.user === userId) {
room.user_hide = true;
room.user_left_time = new Date();
}

await this.chatRoomRepository.save(room);
}
}
3 changes: 3 additions & 0 deletions BE/src/chat/chats.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export class ChatsGateway implements OnGatewayConnection, OnGatewayDisconnect {
);
});
}

await this.chatService.checkOpponentLeft(message['room_id'], sender);

client.send(
JSON.stringify({ event: 'send-message', data: { sent: true } }),
);
Expand Down
Loading
Loading