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 @@ -28,13 +28,15 @@ public static record TaskDetails(
) {}

public static record CommentDetails(
Long commentId,
String nickName,
String profileImageUrl,
boolean isModified,
String comment
) {}

public static record CommentFileDetails(
Long commentId,
String nickName,
String profileImageUrl,
boolean isModified,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ public void saveAll(List<Attachment> attachments) {

@Override
public List<Attachment> findAllByTaskIdAndCommentIsNull(final Long taskId) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNullAndIsDeletedIsFalse(taskId);
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNull(taskId);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}

@Override
public List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(final Long taskId, final List<Long> attachmentIds) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNullAndIsDeletedIsFalseAndAttachmentIdIn(taskId, attachmentIds);
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNullAndAttachmentIdIn(taskId, attachmentIds);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}

@Override
public Optional<Attachment> findByCommentId(Long commentId) {
Optional<AttachmentEntity> attachmentEntity = attachmentRepository.findByComment_CommentIdAndIsDeletedFalse(commentId);
Optional<AttachmentEntity> attachmentEntity = attachmentRepository.findByComment_CommentId(commentId);
return attachmentEntity.map(attachmentPersistenceMapper::toDomain);
}

@Override
public List<Attachment> findAllByTaskIdAndCommentIsNotNull(final Long taskId) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNotNullAndIsDeletedIsFalse(taskId);
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNotNull(taskId);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import clap.server.adapter.outbound.persistense.entity.task.CommentEntity;
import clap.server.adapter.outbound.persistense.mapper.CommentPersistenceMapper;
import clap.server.adapter.outbound.persistense.repository.task.CommentRepository;
import clap.server.adapter.outbound.persistense.repository.history.CommentRepository;
import clap.server.application.port.outbound.task.CommandCommentPort;
import clap.server.application.port.outbound.task.LoadCommentPort;
import clap.server.common.annotation.architecture.PersistenceAdapter;
Expand Down Expand Up @@ -31,7 +31,7 @@ public Comment saveComment(Comment comment) {
}

@Override
public void deleteComment(Comment comment) {
commentRepository.delete(commentPersistenceMapper.toEntity(comment));
public void deleteCommentWithTaskHistory(Long commentId) {
commentRepository.deleteCommentWithTaskHistory(commentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

import clap.server.adapter.outbound.persistense.entity.task.TaskHistoryEntity;
import clap.server.adapter.outbound.persistense.mapper.TaskHistoryPersistenceMapper;
import clap.server.adapter.outbound.persistense.repository.task.TaskHistoryRepository;
import clap.server.adapter.outbound.persistense.repository.history.TaskHistoryRepository;
import clap.server.application.port.outbound.taskhistory.CommandTaskHistoryPort;
import clap.server.application.port.outbound.taskhistory.LoadTaskHistoryPort;
import clap.server.common.annotation.architecture.PersistenceAdapter;


import clap.server.domain.model.task.TaskHistory;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import clap.server.adapter.outbound.persistense.entity.common.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

@Entity
@Table(name = "attachment")
@Getter
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLRestriction("is_deleted = false")
public class AttachmentEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -35,6 +39,7 @@ public class AttachmentEntity extends BaseTimeEntity {
@JoinColumn(name = "comment_id")
private CommentEntity comment;

@Column(nullable = false)
private boolean isDeleted;
@Column(name= "is_deleted", nullable = false)
@Builder.Default
private boolean isDeleted = Boolean.FALSE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.Where;

@Entity
@Table(name = "comment")
@Getter
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLDelete(sql = "UPDATE Comment SET is_Deleted = true WHERE comment_id = ?")
@SQLDelete(sql = "UPDATE comment SET is_deleted = true WHERE comment_id = ?")
@SQLRestriction("is_deleted = false")
public class CommentEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskHistoryType;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

@Entity
@Table(name = "task_history")
@Getter
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLRestriction("is_deleted = false")
public class TaskHistoryEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -29,4 +33,8 @@ public class TaskHistoryEntity extends BaseTimeEntity {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id")
private CommentEntity comment;

@Column(name="is_deleted", nullable = false)
@Builder.Default
private boolean isDeleted = Boolean.FALSE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package clap.server.adapter.outbound.persistense.repository.history;


public interface CommentCustomRepository {
void deleteCommentWithTaskHistory(Long commentId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package clap.server.adapter.outbound.persistense.repository.history;

import clap.server.adapter.outbound.persistense.entity.task.QCommentEntity;
import clap.server.adapter.outbound.persistense.entity.task.QTaskHistoryEntity;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class CommentCustomRepositoryImpl implements CommentCustomRepository{
private final JPAQueryFactory queryFactory;
public void deleteCommentWithTaskHistory(Long commentId) {
QTaskHistoryEntity taskHistory = QTaskHistoryEntity.taskHistoryEntity;
QCommentEntity comment = QCommentEntity.commentEntity;

queryFactory
.update(comment)
.set(comment.isDeleted, true)
.where(comment.commentId.eq(commentId))
.execute();
queryFactory
.update(taskHistory)
.set(taskHistory.isDeleted, true)
.where(taskHistory.comment.commentId.eq(commentId))
.execute();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package clap.server.adapter.outbound.persistense.repository.task;
package clap.server.adapter.outbound.persistense.repository.history;

import clap.server.adapter.outbound.persistense.entity.task.CommentEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CommentRepository extends JpaRepository<CommentEntity, Long> {
public interface CommentRepository extends JpaRepository<CommentEntity, Long>, CommentCustomRepository {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clap.server.adapter.outbound.persistense.repository.task;
package clap.server.adapter.outbound.persistense.repository.history;

import clap.server.adapter.outbound.persistense.entity.task.TaskHistoryEntity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clap.server.adapter.outbound.persistense.repository.task;
package clap.server.adapter.outbound.persistense.repository.history;

import clap.server.adapter.outbound.persistense.entity.task.QCommentEntity;
import clap.server.adapter.outbound.persistense.entity.task.QTaskHistoryEntity;
Expand All @@ -7,7 +7,6 @@
import lombok.RequiredArgsConstructor;



import java.util.List;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package clap.server.adapter.outbound.persistense.repository.task;
package clap.server.adapter.outbound.persistense.repository.history;

import clap.server.adapter.outbound.persistense.entity.task.TaskHistoryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TaskHistoryRepository extends JpaRepository<TaskHistoryEntity, Long> , TaskHistoryCustomRepository{
List<TaskHistoryEntity> findAllByTaskModificationInfo_Task_TaskId(Long taskId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

@Repository
public interface AttachmentRepository extends JpaRepository<AttachmentEntity, Long> {
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndIsDeletedIsFalse(Long taskId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndIsDeletedIsFalseAndAttachmentIdIn(Long task_taskId, List<Long> attachmentId);
Optional<AttachmentEntity> findByComment_CommentIdAndIsDeletedFalse(Long commentId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNull(Long taskId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndAttachmentIdIn(Long task_taskId, List<Long> attachmentId);
Optional<AttachmentEntity> findByComment_CommentId(Long commentId);
boolean existsByComment_CommentId(Long commentId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNotNullAndIsDeletedIsFalse(Long taskId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNotNull(Long taskId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory
case COMMENT -> new FindTaskHistoryResponse.Details(
null,
new FindTaskHistoryResponse.CommentDetails(
taskHistory.getComment().getCommentId(),
taskHistory.getComment().getMember().getNickname(),
taskHistory.getComment().getMember().getImageUrl(),
taskHistory.getComment().isModified(),
Expand All @@ -50,6 +51,7 @@ public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory
.filter(attachment -> attachment.getComment().getCommentId().equals(taskHistory.getComment().getCommentId()))
.findFirst()
.map(attachment -> new FindTaskHistoryResponse.CommentFileDetails(
taskHistory.getComment().getCommentId(),
taskHistory.getComment().getMember().getNickname(),
taskHistory.getComment().getMember().getImageUrl(),
taskHistory.getComment().isModified(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package clap.server.application.port.inbound.domain;

import clap.server.application.port.outbound.task.LoadCommentPort;
import clap.server.domain.model.task.Comment;
import clap.server.exception.ApplicationException;
import clap.server.exception.code.CommentErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class CommentService {
private final LoadCommentPort loadCommentPort;

public Comment findById(Long commentId) {
return loadCommentPort.findById(commentId)
.orElseThrow(() -> new ApplicationException(CommentErrorCode.COMMENT_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public interface CommandCommentPort {

Comment saveComment(Comment comment);

void deleteComment(Comment comment);
void deleteCommentWithTaskHistory(Long commentId);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package clap.server.application.port.outbound.taskhistory;

import clap.server.domain.model.task.Comment;
import clap.server.domain.model.task.TaskHistory;

public interface CommandTaskHistoryPort {
TaskHistory save(TaskHistory taskHistory);

}
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
package clap.server.application.service.history;

import clap.server.adapter.inbound.web.dto.history.request.EditCommentRequest;
import clap.server.application.port.inbound.domain.CommentService;
import clap.server.application.port.inbound.history.DeleteCommentUsecase;
import clap.server.application.port.inbound.history.EditCommentUsecase;
import clap.server.application.port.inbound.domain.MemberService;
import clap.server.application.port.outbound.task.CommandAttachmentPort;
import clap.server.application.port.outbound.task.CommandCommentPort;
import clap.server.application.port.outbound.task.LoadAttachmentPort;
import clap.server.application.port.outbound.task.LoadCommentPort;
import clap.server.application.port.outbound.taskhistory.CommandTaskHistoryPort;
import clap.server.common.annotation.architecture.ApplicationService;
import clap.server.domain.model.member.Member;
import clap.server.domain.model.task.Attachment;
import clap.server.domain.model.task.Comment;
import clap.server.exception.ApplicationException;
import clap.server.exception.DomainException;
import clap.server.exception.code.CommentErrorCode;
import clap.server.exception.code.MemberErrorCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

@ApplicationService
@RequiredArgsConstructor
@Slf4j
public class CommandCommentService implements EditCommentUsecase, DeleteCommentUsecase {

private final MemberService memberService;
private final LoadCommentPort loadCommentPort;
private final CommentService commentService;

private final CommandCommentPort commandCommentPort;
private final LoadAttachmentPort loadAttachmentPort;
private final CommandAttachmentPort commandAttachmentPort;
private final CommandTaskHistoryPort commandTaskHistoryPort;

@Transactional
@Override
public void editComment(Long userId, Long commentId, EditCommentRequest request) {

Member member = memberService.findActiveMember(userId);

Comment comment = loadCommentPort.findById(commentId)
.orElseThrow(() -> new ApplicationException(CommentErrorCode.COMMENT_NOT_FOUND));
Comment comment = commentService.findById(commentId);

if (Member.checkCommenter(comment.getTask(), member)) {

comment.updateComment(request.content());
commandCommentPort.saveComment(comment);
};
Expand All @@ -47,17 +53,16 @@ public void editComment(Long userId, Long commentId, EditCommentRequest request)
@Override
public void deleteComment(Long userId, Long commentId) {
Member member = memberService.findActiveMember(userId);
Comment comment = commentService.findById(commentId);


Comment comment = loadCommentPort.findById(commentId)
.orElseThrow(() -> new ApplicationException(CommentErrorCode.COMMENT_NOT_FOUND));

if (Member.checkCommenter(comment.getTask(), member)) {
if (Objects.equals(comment.getMember().getMemberId(), member.getMemberId())) {
if (loadAttachmentPort.exitsByCommentId(commentId)) {
deleteAttachments(commentId);
}
commandCommentPort.deleteComment(comment);
};
commandCommentPort.deleteCommentWithTaskHistory(commentId);
}else{
throw new DomainException(MemberErrorCode.NOT_A_COMMENTER);
}
}

private void deleteAttachments(Long commentId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE task_history
ADD COLUMN is_deleted BOOLEAN DEFAULT FALSE;