-
Notifications
You must be signed in to change notification settings - Fork 2
대댓글
jaeyoungjang2 edited this page May 18, 2022
·
1 revision
같은 comment entity를 양방향 연관관계로 설정함.
![image](https://user-images.githubusercontent.com/47101085/169031137-8b9afe8c-c9c2-494b-b42f-7853329a896f.png)
대댓글이 저장되는 시점에서 (연관관계 주인)
현재 대댓글의 parent 정보를 저장하는 동시에, 현재 대댓글의 parent인 댓글에서도 child의 정보를 저장함.
대댓글이 아닌 최상위 댓글에서는 parent 정보가 존재하지 않기 때문에 parent != null 을 이용하여 현재 댓글이 대댓글인지, 최상위 댓글인지 확인하는 작업을 거친다.
![image](https://user-images.githubusercontent.com/47101085/169035168-16ada6ee-b45a-4a66-b901-9d969f16f811.png)
프론트에서 대댓글을 조회하는 api를 요청하는 경우 데이터 처리가 편하도록 오름차순 정렬을 진행합니다.
parent id를 기준으로 오름차순 정렬을 하고 (오래된 댓글을 우선으로 확인),
생성시간을 기준으로 오름차순 정렬을 진행 (같은 댓글에 달린 대댓글은 생성시간을 기준으로 오름차순 정렬을 한다. - 오래된 댓글 우선 확인)
![image](https://user-images.githubusercontent.com/47101085/169031745-8f2e41cf-9e78-418a-a47a-049a782c44a0.png)
자식 댓글이 존재하지 않는 경우 바로 삭제 자식 댓글이 존재하는 경우 delete type 변경
![image](https://user-images.githubusercontent.com/47101085/169034751-208bd23d-a1e6-413b-87d3-ffedcd416fce.png)
![image](https://user-images.githubusercontent.com/47101085/169037960-6511b13d-25b9-4d88-868f-2eabaca249a8.png)