Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public void delete(Comment comment) {
commentRepository.delete(comment);
}

@Override
public void deleteByParentId(Long parentId) {
commentRepository.deleteByParentId(parentId);
}

@Override
public Optional<CommentReadModel> findComment(Long id) {
return commentRepository.findReadModelById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface CommentQueryRepository {
List<CommentReadModel> findExcludeSubCommentByCursor(Long noticeId, String cursor, int size);

List<CommentReadModel> findSubCommentByIds(Long noticeId, Set<Long> parentCommentIds);

void deleteByParentId(Long parentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -86,6 +87,14 @@ public List<CommentReadModel> findSubCommentByIds(Long noticeId, Set<Long> paren
).fetch();
}

@Override
public void deleteByParentId(Long parentId) {
queryFactory.update(comment)
.set(comment.destroyedAt, LocalDateTime.now())
.where(comment.parentId.eq(parentId))
.execute();
}

private static BooleanExpression cursorId(String cursorId) {
return cursorId == null ? null : comment.id.goe(Long.parseLong(cursorId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface CommentCommandPort {
void createReply(Long userId, Long noticeId, Long parentId, String content);

void delete(Comment comment);

void deleteByParentId(Long parentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public void process(DeleteCommentCommand command) {
commentCommandPort.delete(findComment);

log.info("delete notice-comment, user{}, notice{}, comment{}", rootUser.getId(), findNotice.getId(), findComment.getId());

commentCommandPort.deleteByParentId(findComment.getId());
}

private static boolean isNotCommentOwner(Comment findComment, RootUser findUser, NoticeDto findNotice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public enum DepartmentName {
ADV_INDUSTRIAL("advanced_industrial", "aif", "신산업융합학과"),
BIOLOGICAL("biological", "microbio", "생물공학과"),
KBEAUTY("kbeauty_industry_fusion", "kbeauty", "K뷰티산업융합학과"),
MECHA_ROBOT_AUTO("mechanical_robot_automotive", "me", "기계로봇자동차공학부"),
MATERIAL("materials_science", "mse", "재료공학과"),
AERO_MOBILITY("aerospace_mobility", "aeroeng", "항공우주모빌리티공학과"),

POLITICS("political_science", "kupol", "정치외교학과"),
ECONOMICS("economics", "econ", "경제학과"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.kustacks.kuring.worker.scrap.deptinfo.engineering;

import com.kustacks.kuring.worker.parser.notice.LatestPageNoticeHtmlParser;
import com.kustacks.kuring.worker.scrap.client.notice.LatestPageGraduateNoticeApiClient;
import com.kustacks.kuring.worker.scrap.client.notice.LatestPageNoticeApiClient;
import com.kustacks.kuring.worker.scrap.client.notice.property.LatestPageNoticeProperties;
import com.kustacks.kuring.worker.scrap.deptinfo.NoticeScrapInfo;
import com.kustacks.kuring.worker.scrap.deptinfo.RegisterDepartmentMap;
import com.kustacks.kuring.worker.scrap.deptinfo.StaffScrapInfo;

import java.util.List;

import static com.kustacks.kuring.notice.domain.DepartmentName.AERO_MOBILITY;

@RegisterDepartmentMap(key = AERO_MOBILITY)
public class AeroMobilityDept extends EngineeringCollege {

public AeroMobilityDept(
LatestPageNoticeApiClient latestPageNoticeApiClient,
LatestPageNoticeHtmlParser latestPageNoticeHtmlParser,
LatestPageNoticeProperties latestPageNoticeProperties,
LatestPageGraduateNoticeApiClient latestPageGraduateNoticeApiClient
) {
super();
this.noticeApiClient = latestPageNoticeApiClient;
this.htmlParser = latestPageNoticeHtmlParser;
this.latestPageNoticeProperties = latestPageNoticeProperties;

List<Integer> siteIds = List.of(11837);
this.staffScrapInfo = new StaffScrapInfo(AERO_MOBILITY.getHostPrefix(), siteIds);
this.noticeScrapInfo = new NoticeScrapInfo(AERO_MOBILITY.getHostPrefix(), 284);
this.departmentName = AERO_MOBILITY;
this.noticeGraduationInfo = new NoticeScrapInfo(AERO_MOBILITY.getHostPrefix(), 761);
this.latestPageGraduateNoticeApiClient = latestPageGraduateNoticeApiClient;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.kustacks.kuring.worker.scrap.deptinfo.engineering;

import com.kustacks.kuring.worker.parser.notice.LatestPageNoticeHtmlParser;
import com.kustacks.kuring.worker.scrap.client.notice.LatestPageGraduateNoticeApiClient;
import com.kustacks.kuring.worker.scrap.client.notice.LatestPageNoticeApiClient;
import com.kustacks.kuring.worker.scrap.client.notice.property.LatestPageNoticeProperties;
import com.kustacks.kuring.worker.scrap.deptinfo.NoticeScrapInfo;
import com.kustacks.kuring.worker.scrap.deptinfo.RegisterDepartmentMap;
import com.kustacks.kuring.worker.scrap.deptinfo.StaffScrapInfo;

import java.util.List;

import static com.kustacks.kuring.notice.domain.DepartmentName.MATERIAL;

@RegisterDepartmentMap(key = MATERIAL)
public class MaterialDept extends EngineeringCollege {

public MaterialDept(
LatestPageNoticeApiClient latestPageNoticeApiClient,
LatestPageNoticeHtmlParser latestPageNoticeHtmlParser,
LatestPageNoticeProperties latestPageNoticeProperties,
LatestPageGraduateNoticeApiClient latestPageGraduateNoticeApiClient
) {
super();
this.noticeApiClient = latestPageNoticeApiClient;
this.htmlParser = latestPageNoticeHtmlParser;
this.latestPageNoticeProperties = latestPageNoticeProperties;

List<Integer> siteIds = List.of(11785);
this.staffScrapInfo = new StaffScrapInfo(MATERIAL.getHostPrefix(), siteIds);
this.noticeScrapInfo = new NoticeScrapInfo(MATERIAL.getHostPrefix(), 5897);
this.departmentName = MATERIAL;
this.noticeGraduationInfo = new NoticeScrapInfo(MATERIAL.getHostPrefix(), 5899);
this.latestPageGraduateNoticeApiClient = latestPageGraduateNoticeApiClient;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.kustacks.kuring.worker.scrap.deptinfo.engineering;

import com.kustacks.kuring.worker.parser.notice.LatestPageNoticeHtmlParser;
import com.kustacks.kuring.worker.scrap.client.notice.LatestPageGraduateNoticeApiClient;
import com.kustacks.kuring.worker.scrap.client.notice.LatestPageNoticeApiClient;
import com.kustacks.kuring.worker.scrap.client.notice.property.LatestPageNoticeProperties;
import com.kustacks.kuring.worker.scrap.deptinfo.NoticeScrapInfo;
import com.kustacks.kuring.worker.scrap.deptinfo.RegisterDepartmentMap;
import com.kustacks.kuring.worker.scrap.deptinfo.StaffScrapInfo;

import java.util.List;

import static com.kustacks.kuring.notice.domain.DepartmentName.MECHA_ROBOT_AUTO;

@RegisterDepartmentMap(key = MECHA_ROBOT_AUTO)
public class MechaRobotAutoDept extends EngineeringCollege {

public MechaRobotAutoDept(
LatestPageNoticeApiClient latestPageNoticeApiClient,
LatestPageNoticeHtmlParser latestPageNoticeHtmlParser,
LatestPageNoticeProperties latestPageNoticeProperties,
LatestPageGraduateNoticeApiClient latestPageGraduateNoticeApiClient
) {
super();
this.noticeApiClient = latestPageNoticeApiClient;
this.htmlParser = latestPageNoticeHtmlParser;
this.latestPageNoticeProperties = latestPageNoticeProperties;

List<Integer> siteIds = List.of(10048);
this.staffScrapInfo = new StaffScrapInfo(MECHA_ROBOT_AUTO.getHostPrefix(), siteIds);
this.noticeScrapInfo = new NoticeScrapInfo(MECHA_ROBOT_AUTO.getHostPrefix(), 403);
this.departmentName = MECHA_ROBOT_AUTO;
this.noticeGraduationInfo = new NoticeScrapInfo(MECHA_ROBOT_AUTO.getHostPrefix(), 763);
this.latestPageGraduateNoticeApiClient = latestPageGraduateNoticeApiClient;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- 부모 댓글이 삭제되었으나(destroyed_at IS NOT NULL), 아직 Soft Delete 처리되지 않은 답글들을 업데이트합니다.

UPDATE comment AS child
INNER JOIN comment AS parent
ON child.parent_id = parent.id
SET child.destroyed_at = parent.destroyed_at -- 답글의 Soft Delete 시간을 부모의 삭제 시간과 동일하게 설정

WHERE
child.parent_id IS NOT NULL -- 1. 이 답글이 루트 댓글이 아님 (parent_id가 NULL이 아님)
AND child.destroyed_at IS NULL -- 2. 답글이 아직 삭제되지 않았고 (destroyed_at IS NULL)
AND parent.destroyed_at IS NOT NULL -- 3. 부모 댓글은 이미 삭제된 상태인 경우 (destroyed_at IS NOT NULL)
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void look_up_department_list() {
var 학과_조회_요청_응답 = 학과_조회_요청();

// then
학과_조회_응답_확인(학과_조회_요청_응답, 63);
학과_조회_응답_확인(학과_조회_요청_응답, 66);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import com.kustacks.kuring.notice.domain.DepartmentName;
import com.kustacks.kuring.support.IntegrationTestSupport;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.springframework.http.HttpStatus;

import java.util.List;
Expand Down Expand Up @@ -455,4 +454,51 @@ void comment_multiple_whitelist_words_test() {
() -> assertThat(response2.statusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY.value())
);
}

/**
* Given : 사전에 저장된 공지와 원댓글 3개, 답글 3개가 있다
* When : 댓글을 삭제하면
* Then : 댓글의 답글들도 같이 삭제된다.
*/
@DisplayName("[v2] 댓글 삭제 시 답글들도 함께 삭제된다.")
@Test
void delete_parent_comment_with_sub_comments() {
//given - 사용자 로그인
String accessToken = 사용자_로그인_되어_있음(USER_FCM_TOKEN, USER_EMAIL, USER_PASSWORD);

var 공지_조회_응답 = 공지사항_조회_요청("stu");
var noticeId = 공지_조회_응답.jsonPath().getLong("data[0].id");

//댓글 추가
공지에_댓글_추가(noticeId, accessToken, "삭제될 원댓글");

//원댓글 ID 조회
var 댓글_목록_응답 = 공지의_댓글_조회(noticeId, null, 10);
long parentCommentId = 댓글_목록_응답.jsonPath().getLong("data.comments[0].comment.id"); //3번째 추가.

//답글 3개 추가
공지에_댓글_추가(noticeId, parentCommentId, accessToken, "답글 1");
공지에_댓글_추가(noticeId, parentCommentId, accessToken, "답글 2");
공지에_댓글_추가(noticeId, parentCommentId, accessToken, "답글 3");

var 삭제_전_응답 = 공지사항_조회_요청("stu");
long 삭제_전_댓글_수 = 삭제_전_응답.jsonPath().getLong("data[0].commentCount");

//when - 댓글 삭제(댓글 1건 + 답글 3건 총 4건 삭제)
댓글_삭제(accessToken, noticeId, parentCommentId);

//then - 삭제 후 공지 목록 조회
var 삭제_후_응답 = 공지사항_조회_요청("stu");
long 삭제_후_댓글_수 = 삭제_후_응답.jsonPath().getLong("data[0].commentCount");

// 공지의 댓글 목록 조회 시에도 두건만 나와야 함(기존 6건 - 4건 = 2건)
var 삭제_후_댓글_목록 = 공지의_댓글_조회(noticeId, null, 10);
int 실제_조회된_댓글_수 = 삭제_후_댓글_목록.jsonPath().getList("data.comments").size();

assertAll(
() -> assertThat(삭제_전_댓글_수).isEqualTo(4),
() -> assertThat(삭제_후_댓글_수).isZero(),
() -> assertThat(실제_조회된_댓글_수).isZero()
);
}
}
Loading