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
@@ -1,7 +1,6 @@
package clap.server.adapter.inbound.web.comment;

import clap.server.adapter.inbound.security.SecurityUserDetails;
import clap.server.adapter.inbound.web.dto.task.DeleteCommentRequest;
import clap.server.adapter.inbound.web.dto.task.PostAndEditCommentRequest;
import clap.server.application.port.inbound.comment.CommandCommentUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
Expand Down Expand Up @@ -40,9 +39,8 @@ public void editComment(
@Secured({"ROLE_MANAGER", "ROLE_USER"})
public void deleteComment(
@AuthenticationPrincipal SecurityUserDetails userInfo,
@PathVariable Long commentId,
@RequestBody DeleteCommentRequest request) {
commandCommentUsecase.deleteComment(userInfo.getUserId(), commentId, request);
@PathVariable Long commentId) {
commandCommentUsecase.deleteComment(userInfo.getUserId(), commentId);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package clap.server.adapter.inbound.web.notification;

import clap.server.adapter.inbound.security.SecurityUserDetails;
import clap.server.application.port.inbound.notification.EnableAgitUsecase;
import clap.server.application.port.inbound.notification.EnableEmailUsecase;
import clap.server.application.port.inbound.notification.EnableKakaoUsecase;
import clap.server.application.port.inbound.notification.UpdateNotificationUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -22,17 +25,39 @@
public class ManagementNotificationController {

private final UpdateNotificationUsecase updateNotificationUsecase;
private final EnableKakaoUsecase enableKakaoUsecase;
private final EnableAgitUsecase enableAgitUsecase;
private final EnableEmailUsecase enableEmailUsecase;

@Operation(summary = "알림 목록에서 한 개 눌렀을 때 읽음 처리")
@Parameter(name = "notificationId", description = "알림 고유 ID", required = true, in = ParameterIn.PATH)
@PatchMapping("/{notificationId}")
public void updateNotificationIsRead(@PathVariable Long notificationId) {
updateNotificationUsecase.updateNotification(notificationId);
public void updateNotificationIsRead(@AuthenticationPrincipal SecurityUserDetails userInfo,
@PathVariable Long notificationId) {
updateNotificationUsecase.updateNotification(userInfo.getUserId(), notificationId);
}

@Operation(summary = "알림 목록에서 전체 읽음 버튼을 눌렀을 때 전체 읽음 처리")
@PatchMapping
public void updateAllNotificationIsRead(@AuthenticationPrincipal SecurityUserDetails userInfo) {
updateNotificationUsecase.updateAllNotification(userInfo.getUserId());
}

@Operation(summary = "카카오 푸시 알림 활성화/비활성화 API", description = "알림 거부였을 시 -> 승인으로 변경, 알림 승인이였을 시 -> 거부로 변경")
@PatchMapping("/kakao")
public void enableKaKaoWork(@AuthenticationPrincipal SecurityUserDetails userInfo) {
enableKakaoUsecase.enableKakao(userInfo.getUserId());
}

@Operation(summary = "아지트 푸시 알림 활성화/비활성화 API", description = "알림 거부였을 시 -> 승인으로 변경, 알림 승인이였을 시 -> 거부로 변경")
@PatchMapping("/agit")
public void enableAgit(@AuthenticationPrincipal SecurityUserDetails userInfo) {
enableAgitUsecase.enableAgit(userInfo.getUserId());
}

@Operation(summary = "이메일 푸시 알림 활성화/비활성화 API", description = "알림 거부였을 시 -> 승인으로 변경, 알림 승인이였을 시 -> 거부로 변경")
@PatchMapping("/email")
public void enableEmail(@AuthenticationPrincipal SecurityUserDetails userInfo) {
enableEmailUsecase.enableEmail(userInfo.getUserId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ public List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(final Lon
}

@Override
public List<Attachment> findAllyByTaskIdAndCommentIdAndAttachmentId(Long taskId, Long commentId, List<Long> attachmentIds) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findActiveAttachmentsByTask_TaskIdAndComment_CommentIdAndAttachmentIdIn(taskId, commentId, attachmentIds);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
public Optional<Attachment> findByCommentId(Long commentId) {
Optional<AttachmentEntity> attachmentEntity = attachmentRepository.findByComment_CommentIdAndIsDeletedFalse(commentId);
return attachmentEntity.map(attachmentPersistenceMapper::toDomain);
}

@Override
Expand All @@ -68,4 +66,9 @@ public List<Attachment> findAllByTaskIdAndCommentIsNotNull(final Long taskId) {
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}

@Override
public boolean exitsByCommentId(Long commentId) {
return attachmentRepository.existsByComment_CommentId(commentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public Comment saveComment(Comment comment) {
}

@Override
public Comment saveComment(Comment comment) {
CommentEntity commentEntity = commentRepository.save(commentPersistenceMapper.toEntity(comment));
return commentPersistenceMapper.toDomain(commentEntity);
public void deleteComment(Comment comment) {
commentRepository.delete(commentPersistenceMapper.toEntity(comment));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ public class MemberEntity extends BaseTimeEntity {
@Column
private String imageUrl;

@Column
private Boolean notificationEnabled;
@Column(name = "kakaowork_notification_enabled")
private Boolean kakaoworkNotificationEnabled = Boolean.TRUE;;

@Column(name = "agit_notification_enabled")
private Boolean agitNotificationEnabled = Boolean.TRUE;;

@Column(name = "email_notification_enabled")
private Boolean emailNotificationEnabled = Boolean.TRUE;;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "admin_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;

@Entity
@Table(name = "comment")
@Getter
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLDelete(sql = "UPDATE Comment SET is_Deleted = true WHERE comment_id = ?")
public class CommentEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -34,5 +36,5 @@ public class CommentEntity extends BaseTimeEntity {
private boolean isModified;

@Column(name="is_deleted", nullable = false)
private boolean isDeleted;
private boolean isDeleted = Boolean.FALSE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface AttachmentRepository extends JpaRepository<AttachmentEntity, Long> {
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndIsDeletedIsFalse(Long taskId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndIsDeletedIsFalseAndAttachmentIdIn(Long task_taskId, List<Long> attachmentId);
List<AttachmentEntity> findActiveAttachmentsByTask_TaskIdAndComment_CommentIdAndAttachmentIdIn(Long task_taskId, Long comment_commentId, List<Long> attachmentIds);
Optional<AttachmentEntity> findByComment_CommentIdAndIsDeletedFalse(Long commentId);
boolean existsByComment_CommentId(Long commentId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNotNullAndIsDeletedIsFalse(Long taskId);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package clap.server.application.port.inbound.comment;

import clap.server.adapter.inbound.web.dto.task.DeleteCommentRequest;
import clap.server.adapter.inbound.web.dto.task.PostAndEditCommentRequest;

import java.util.List;

public interface CommandCommentUsecase {

void updateComment(Long userId, Long commentId, PostAndEditCommentRequest request);

void deleteComment(Long userId, Long commentId, DeleteCommentRequest request);
void deleteComment(Long userId, Long commentId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package clap.server.application.port.inbound.notification;

public interface EnableAgitUsecase {

void enableAgit(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package clap.server.application.port.inbound.notification;

public interface EnableEmailUsecase {

void enableEmail(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package clap.server.application.port.inbound.notification;

public interface EnableKakaoUsecase {

void enableKakao(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package clap.server.application.port.inbound.notification;

public interface UpdateNotificationUsecase {
void updateNotification(Long notificationId);
void updateNotification(Long userId, Long notificationId);

void updateAllNotification(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface CommandCommentPort {

Comment saveComment(Comment comment);

void deleteComment(Comment comment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import clap.server.domain.model.task.Attachment;

import java.util.List;
import java.util.Optional;


public interface LoadAttachmentPort {
List<Attachment> findAllByTaskIdAndCommentIsNull(Long taskId);
List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(Long taskId, List<Long> attachmentIds);
List<Attachment> findAllyByTaskIdAndCommentIdAndAttachmentId(Long taskId, Long commentId, List<Long> attachmentIds);
Optional<Attachment> findByCommentId(Long commentId);
List<Attachment> findAllByTaskIdAndCommentIsNotNull(Long taskId);
boolean exitsByCommentId(Long commentId);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package clap.server.application.service.comment;

import clap.server.adapter.inbound.web.dto.task.DeleteCommentRequest;
import clap.server.adapter.inbound.web.dto.task.PostAndEditCommentRequest;
import clap.server.adapter.outbound.persistense.entity.member.constant.MemberRole;
import clap.server.application.port.inbound.comment.CommandCommentUsecase;
import clap.server.application.port.inbound.domain.MemberService;
import clap.server.application.port.outbound.task.CommandAttachmentPort;
Expand All @@ -13,16 +11,11 @@
import clap.server.domain.model.member.Member;
import clap.server.domain.model.task.Attachment;
import clap.server.domain.model.task.Comment;
import clap.server.domain.model.task.Task;
import clap.server.exception.ApplicationException;
import clap.server.exception.code.CommentErrorCode;
import clap.server.exception.code.MemberErrorCode;
import clap.server.exception.code.TaskErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@ApplicationService
@RequiredArgsConstructor
public class CommandCommentService implements CommandCommentUsecase {
Expand All @@ -42,7 +35,7 @@ public void updateComment(Long userId, Long commentId, PostAndEditCommentRequest
Comment comment = loadCommentPort.findById(commentId)
.orElseThrow(() -> new ApplicationException(CommentErrorCode.COMMENT_NOT_FOUND));

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

comment.updateComment(request.content());
commandCommentPort.saveComment(comment);
Expand All @@ -51,53 +44,25 @@ public void updateComment(Long userId, Long commentId, PostAndEditCommentRequest

@Transactional
@Override
public void deleteComment(Long userId, Long commentId, DeleteCommentRequest request) {
public void deleteComment(Long userId, Long commentId) {
Member member = memberService.findActiveMember(userId);


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

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

// 삭제할 댓글이 첨부파일일 경우
if (!request.attachmentsToDelete().isEmpty()) {
deleteAttachments(request.attachmentsToDelete(), comment.getTask(), comment.getCommentId());
if (Member.checkCommenter(comment.getTask(), member)) {
if (loadAttachmentPort.exitsByCommentId(commentId)) {
deleteAttachments(commentId);
}

comment.softDelete();
commandCommentPort.saveComment(comment);
commandCommentPort.deleteComment(comment);
};
}

private void deleteAttachments(List<Long> attachmentIdsToDelete, Task task, Long commentId) {
List<Attachment> attachmentsToDelete = validateAndGetAttachments(attachmentIdsToDelete, task, commentId);
attachmentsToDelete.forEach(Attachment::softDelete);
commandAttachmentPort.saveAll(attachmentsToDelete);
}

private List<Attachment> validateAndGetAttachments(List<Long> attachmentIdsToDelete, Task task, Long commentId) {
List<Attachment> attachmentsOfTask = loadAttachmentPort.findAllyByTaskIdAndCommentIdAndAttachmentId(task.getTaskId(), commentId, attachmentIdsToDelete);
if (attachmentsOfTask.size() != attachmentIdsToDelete.size()) {
throw new ApplicationException(TaskErrorCode.TASK_ATTACHMENT_NOT_FOUND);
}
return attachmentsOfTask;
}

public Boolean checkCommenter(Task task, Member member) {
// 일반 회원일 경우 => 요청자인지 확인
// 담당자일 경우 => 처리자인지 확인
if ((member.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER)
&& !(member.getMemberId() == task.getProcessor().getMemberId())) {
throw new ApplicationException(MemberErrorCode.NOT_A_COMMENTER);
}

else if ((member.getMemberInfo().getRole() == MemberRole.ROLE_USER)
&& !(member.getMemberId() == task.getRequester().getMemberId())) {
throw new ApplicationException(MemberErrorCode.NOT_A_COMMENTER);
}
else {
return true;
}
private void deleteAttachments(Long commentId) {
Attachment attachment = loadAttachmentPort.findByCommentId(commentId)
.orElseThrow(() -> new ApplicationException(CommentErrorCode.COMMENT_ATTACHMENT_NOT_FOUND));
attachment.softDelete();
commandAttachmentPort.save(attachment);
}
}
Loading