Skip to content

Commit

Permalink
[Refactor/#112] Add&Refactor entity related comment,reply,member_sche…
Browse files Browse the repository at this point in the history
…dule (#115)

* [Refactor/#112] conversation entity add and extends comment&reply

* [Refactor/#112] add entity, repository, service, controller of member_schedule

* [Refactor/#112] refactor web related schedule

* [Refactor/#112] add schedule status in only dto field

* [Refactor/#112] add schedule api for search

* [Refactor/#112] add teamcolor enum and validTeamColor annotation

* [Refactor/#112] validate startTime is before endTime

* [Refactor/#112]refactroing all about this branch v1

* [Refactor/#112] test and add limit logic realtion of schedule

* [Refactor/#112] divide delete teamMember api & add auth check when comment in schedule

* [Refactor/#112]add teamSize field in teamResponse dto

* [Refactor/#112] refactor based on feedback

* [Refactor/#112] convert follow request (username->nickname)
  • Loading branch information
Han-Jeong committed Feb 11, 2024
1 parent f7523ba commit 32255e5
Show file tree
Hide file tree
Showing 86 changed files with 916 additions and 406 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/example/waggle/domain/board/Board.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.waggle.domain.board;

import com.example.waggle.domain.comment.entity.Comment;
import com.example.waggle.domain.conversation.entity.Comment;
import com.example.waggle.domain.hashtag.entity.BoardHashtag;
import com.example.waggle.domain.media.entity.Media;
import com.example.waggle.domain.member.entity.Member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.example.waggle.domain.board.question.entity.Question;
import com.example.waggle.domain.board.question.repository.QuestionRepository;
import com.example.waggle.domain.board.service.BoardService;
import com.example.waggle.domain.comment.service.comment.CommentCommandService;
import com.example.waggle.domain.conversation.service.comment.CommentCommandService;
import com.example.waggle.domain.media.service.MediaCommandService;
import com.example.waggle.domain.member.entity.Member;
import com.example.waggle.domain.member.service.MemberQueryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.example.waggle.domain.hashtag.repository.HashtagRepository;
import com.example.waggle.domain.member.entity.Member;
import com.example.waggle.domain.member.service.MemberQueryService;
import com.example.waggle.domain.schedule.repository.MemberScheduleRepository;
import com.example.waggle.domain.schedule.repository.ScheduleRepository;
import com.example.waggle.global.exception.GeneralException;
import com.example.waggle.global.exception.handler.*;
Expand All @@ -31,6 +32,7 @@ public class BoardServiceImpl implements BoardService {
private final SirenRepository sirenRepository;
private final ScheduleRepository scheduleRepository;
private final HashtagRepository hashtagRepository;
private final MemberScheduleRepository memberScheduleRepository;
private final MemberQueryService memberQueryService;


Expand Down Expand Up @@ -90,6 +92,10 @@ public Board getBoard(Long boardId, BoardType boardType) {
case SCHEDULE:
board = scheduleRepository.findById(boardId)
.orElseThrow(() -> new ScheduleHandler(ErrorStatus.BOARD_NOT_FOUND));
Member signInMember = memberQueryService.getSignInMember();
if (!memberScheduleRepository.existsByMemberIdAndScheduleId(signInMember.getId(), boardId)) {
throw new ScheduleHandler(ErrorStatus.SCHEDULE_CANNOT_COMMENTED_BECAUSE_OF_ACCESS);
}
break;
default:
throw new GeneralException(ErrorStatus.BOARD_INVALID_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.example.waggle.domain.board.service.BoardService;
import com.example.waggle.domain.board.siren.entity.Siren;
import com.example.waggle.domain.board.siren.repository.SirenRepository;
import com.example.waggle.domain.comment.service.comment.CommentCommandService;
import com.example.waggle.domain.conversation.service.comment.CommentCommandService;
import com.example.waggle.domain.media.service.MediaCommandService;
import com.example.waggle.domain.member.entity.Member;
import com.example.waggle.domain.member.service.MemberQueryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.example.waggle.domain.board.service.BoardService;
import com.example.waggle.domain.board.story.entity.Story;
import com.example.waggle.domain.board.story.repository.StoryRepository;
import com.example.waggle.domain.comment.service.comment.CommentCommandService;
import com.example.waggle.domain.conversation.service.comment.CommentCommandService;
import com.example.waggle.domain.media.service.MediaCommandService;
import com.example.waggle.domain.member.entity.Member;
import com.example.waggle.domain.member.service.MemberQueryService;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.waggle.domain.comment.entity;
package com.example.waggle.domain.conversation;

import com.example.waggle.domain.member.entity.Member;
import com.example.waggle.domain.mention.entity.Mention;
Expand All @@ -17,37 +17,29 @@
@Entity
@Getter
@SuperBuilder
@DiscriminatorColumn(name = "DTYPE")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Reply extends BaseEntity {
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Conversation extends BaseEntity {
@Id
@GeneratedValue
@Column(name = "reply_id")
@Column(name = "conversation_id")
private Long id;

@ManyToOne
@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

protected Member member;
@Lob
@Column(nullable = false)
private String content;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id")
private Comment comment;


@Builder.Default
@OneToMany(mappedBy = "reply", orphanRemoval = true)
@OneToMany(mappedBy = "conversation", orphanRemoval = true)
private List<Mention> mentions = new ArrayList<>();

public void changeContent(String content) {
this.content = content;
}

public void addMention(Mention mention) {
this.getMentions().add(mention);
mention.changeReply(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.waggle.domain.conversation.entity;

import com.example.waggle.domain.board.Board;
import com.example.waggle.domain.conversation.Conversation;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Entity
@Getter
@SuperBuilder
@DiscriminatorValue("type_comment")
@Table(name = "comment")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Comment extends Conversation {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "board_id")
private Board board;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.waggle.domain.conversation.entity;

import com.example.waggle.domain.conversation.Conversation;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Entity
@Getter
@SuperBuilder
@DiscriminatorValue("type_reply")
@Table(name = "reply")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Reply extends Conversation {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id")
private Comment comment;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.waggle.domain.comment.repository;
package com.example.waggle.domain.conversation.repository;

import com.example.waggle.domain.comment.entity.Comment;
import com.example.waggle.domain.conversation.entity.Comment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -13,4 +13,6 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
Page<Comment> findPagedCommentsByBoardId(Long boardId, Pageable pageable);

void deleteAllByMemberUsername(String username);

boolean existsByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.waggle.domain.comment.repository;
package com.example.waggle.domain.conversation.repository;

import com.example.waggle.domain.comment.entity.Reply;
import com.example.waggle.domain.conversation.entity.Reply;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.waggle.domain.comment.service.comment;
package com.example.waggle.domain.conversation.service.comment;

import com.example.waggle.domain.board.service.BoardType;
import com.example.waggle.web.dto.comment.CommentRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.example.waggle.domain.comment.service.comment;
package com.example.waggle.domain.conversation.service.comment;

import com.example.waggle.domain.board.Board;
import com.example.waggle.domain.board.service.BoardService;
import com.example.waggle.domain.board.service.BoardType;
import com.example.waggle.domain.comment.entity.Comment;
import com.example.waggle.domain.comment.repository.CommentRepository;
import com.example.waggle.domain.comment.repository.ReplyRepository;
import com.example.waggle.domain.conversation.entity.Comment;
import com.example.waggle.domain.conversation.repository.CommentRepository;
import com.example.waggle.domain.conversation.repository.ReplyRepository;
import com.example.waggle.domain.member.entity.Member;
import com.example.waggle.domain.member.service.MemberQueryService;
import com.example.waggle.domain.mention.service.MentionCommandService;
import com.example.waggle.global.exception.handler.CommentHandler;
import com.example.waggle.global.payload.code.ErrorStatus;
import com.example.waggle.web.dto.comment.CommentRequest;
Expand All @@ -26,6 +27,7 @@ public class CommentCommandServiceImpl implements CommentCommandService {
private final CommentRepository commentRepository;
private final ReplyRepository replyRepository;
private final MemberQueryService memberQueryService;
private final MentionCommandService mentionCommandService;
private final BoardService boardService;

@Override
Expand All @@ -38,6 +40,7 @@ public Long createComment(Long boardId, CommentRequest.Post commentWriteDto, Boa
.member(signInMember)
.build();
commentRepository.save(build);
mentionCommandService.createMentions(build, commentWriteDto.getMentionedNickname());
return build.getId();
}

Expand All @@ -51,27 +54,28 @@ public Long createCommentByUsername(Long boardId, CommentRequest.Post commentWri
.member(memberByUsername)
.build();
commentRepository.save(build);
mentionCommandService.createMentions(build, commentWriteDto.getMentionedNickname());
return build.getId();
}

@Override
public Long updateComment(Long commentId, CommentRequest.Post commentWriteDto) {
if (!validateMember(commentId)) {
throw new CommentHandler(ErrorStatus.COMMENT_CANNOT_EDIT_OTHERS);
}
Member signInMember = memberQueryService.getSignInMember();
Comment comment = commentRepository.findById(commentId)
.orElseThrow(() -> new CommentHandler(ErrorStatus.COMMENT_NOT_FOUND));
validateMember(comment, signInMember);

comment.changeContent(commentWriteDto.getContent());
mentionCommandService.updateMentions(comment, commentWriteDto.getMentionedNickname());
return comment.getId();
}

@Override
public void deleteComment(Long commentId) {
if (!validateMember(commentId)) {
throw new CommentHandler(ErrorStatus.COMMENT_CANNOT_EDIT_OTHERS);
}
Member signInMember = memberQueryService.getSignInMember();
Comment comment = commentRepository.findById(commentId)
.orElseThrow(() -> new CommentHandler(ErrorStatus.COMMENT_NOT_FOUND));
validateMember(comment, signInMember);

replyRepository.deleteAllByCommentId(commentId);
commentRepository.delete(comment);
Expand All @@ -87,10 +91,9 @@ public void deleteCommentForHardReset(Long commentId) {
);
}

public boolean validateMember(Long commentId) {
Member signInMember = memberQueryService.getSignInMember();
Comment comment = commentRepository.findById(commentId)
.orElseThrow(() -> new CommentHandler(ErrorStatus.COMMENT_NOT_FOUND));
return comment.getMember().equals(signInMember);
public void validateMember(Comment comment, Member member) {
if (!comment.getMember().equals(member)) {
throw new CommentHandler(ErrorStatus.COMMENT_CANNOT_EDIT_OTHERS);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.waggle.domain.comment.service.comment;
package com.example.waggle.domain.conversation.service.comment;

import com.example.waggle.domain.comment.entity.Comment;
import com.example.waggle.domain.conversation.entity.Comment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

Expand All @@ -9,7 +9,5 @@
public interface CommentQueryService {
List<Comment> getComments(Long boardId);

boolean validateMember(Long commentId);

Page<Comment> getPagedComments(Long boardId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.example.waggle.domain.comment.service.comment;
package com.example.waggle.domain.conversation.service.comment;

import com.example.waggle.domain.comment.entity.Comment;
import com.example.waggle.domain.comment.repository.CommentRepository;
import com.example.waggle.global.exception.handler.CommentHandler;
import com.example.waggle.global.payload.code.ErrorStatus;
import com.example.waggle.global.util.SecurityUtil;
import com.example.waggle.domain.conversation.entity.Comment;
import com.example.waggle.domain.conversation.repository.CommentRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand All @@ -31,13 +28,4 @@ public Page<Comment> getPagedComments(Long boardId, Pageable pageable) {
return commentRepository.findPagedCommentsByBoardId(boardId, pageable);
}

@Override
public boolean validateMember(Long commentId) {
Comment comment = commentRepository.findById(commentId)
.orElseThrow(() -> new CommentHandler(ErrorStatus.COMMENT_NOT_FOUND));
return comment.getMember().getUsername()
.equals(SecurityUtil.getCurrentUsername());
}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.waggle.domain.comment.service.reply;
package com.example.waggle.domain.conversation.service.reply;

import com.example.waggle.web.dto.reply.ReplyRequest;

Expand Down
Loading

0 comments on commit 32255e5

Please sign in to comment.