Skip to content

Commit

Permalink
Merge pull request #107 from DEPthes/develop
Browse files Browse the repository at this point in the history
V.4.1.1 Deploy
  • Loading branch information
phonil authored Aug 18, 2024
2 parents 8741991 + 3d2b7b1 commit 13bd349
Show file tree
Hide file tree
Showing 19 changed files with 270 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface AuthService {

SuccessResponse<Message> logout(UserDetailsImpl userDetails, LogoutReq logoutReq);

SuccessResponse<Message> exit(UserDetailsImpl userDetails);

SuccessResponse<ReissueRes> reissue(String refreshToken);

SuccessResponse<EmailDuplicateCheckRes> checkEmailDuplicate(String email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
import mvp.deplog.domain.auth.dto.response.LoginRes;
import mvp.deplog.domain.auth.dto.request.JoinReq;
import mvp.deplog.domain.auth.dto.response.ReissueRes;
import mvp.deplog.domain.comment.domain.Comment;
import mvp.deplog.domain.comment.domain.repository.CommentRepository;
import mvp.deplog.domain.likes.domain.Likes;
import mvp.deplog.domain.likes.domain.repository.LikesRepository;
import mvp.deplog.domain.post.domain.Post;
import mvp.deplog.domain.post.domain.repository.PostRepository;
import mvp.deplog.domain.scrap.domain.Scrap;
import mvp.deplog.domain.scrap.domain.repository.ScrapRepository;
import mvp.deplog.domain.tag.domain.Tag;
import mvp.deplog.domain.tag.domain.repository.TagRepository;
import mvp.deplog.domain.tagging.Tagging;
import mvp.deplog.domain.tagging.repository.TaggingRepository;
import mvp.deplog.global.common.Message;
import mvp.deplog.global.common.SuccessResponse;
import mvp.deplog.domain.member.domain.Member;
Expand All @@ -32,6 +44,7 @@
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RequiredArgsConstructor
Expand All @@ -50,6 +63,13 @@ public class AuthServiceImpl implements AuthService{
private final MemberAuthMapper memberAuthMapper;

private final MemberRepository memberRepository;
private final PostRepository postRepository;
private final CommentRepository commentRepository;
private final LikesRepository likesRepository;
private final ScrapRepository scrapRepository;
private final TaggingRepository taggingRepository;
private final TagRepository tagRepository;

private final PasswordEncoder passwordEncoder;
private final JwtTokenProvider jwtTokenProvider;

Expand Down Expand Up @@ -124,6 +144,76 @@ public SuccessResponse<Message> logout(UserDetailsImpl userDetails, LogoutReq lo
return SuccessResponse.of(message);
}

@Override
@Transactional
public SuccessResponse<Message> exit(UserDetailsImpl userDetails) {
Member member = memberRepository.findById(userDetails.getMember().getId())
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 회원입니다."));

// method : handle likes - delete likes
List<Likes> likesList = likesRepository.findAllByMember(member);
for (Likes likes : likesList) {
Post post = likes.getPost();
if(post.getMember().equals(member))
continue;
post.decrementLikesCount();
}
likesRepository.deleteAll(likesList);

// method : handle scrap - delete scrap
List<Scrap> scrapList = scrapRepository.findAllByMember(member);
for (Scrap scrap : scrapList) {
Post post = scrap.getPost();
if (post.getMember().equals(member))
continue;
post.decrementScrapCount();
}
scrapRepository.deleteAll(scrapList);

// method : handle comment - delete comment
List<Comment> commentList = commentRepository.findByMember(member);
for (Comment comment : commentList) {
if (comment.getParentComment() == null) {
List<Comment> childCommentList = commentRepository.findByParentComment(comment);
commentRepository.deleteAll(childCommentList);
}
}
commentRepository.deleteAll(commentList);

// method : handle tag - control tag && delete post
List<Post> postList = postRepository.findByMember(member);
for (Post post : postList) {
List<Tagging> taggingList = taggingRepository.findByPost(post);
for (Tagging tagging : taggingList) {
Tag tag = tagging.getTag();
Long taggingCount = taggingRepository.countByTag(tag);
taggingRepository.delete(tagging);
if(taggingCount == 1)
tagRepository.delete(tag);
}

List<Comment> postCommentList = commentRepository.findByPost(post);
for (Comment comment : postCommentList) {
if (comment.getParentComment() == null) {
List<Comment> childCommentList = commentRepository.findByParentComment(comment);
commentRepository.deleteAll(childCommentList);
}
}
commentRepository.deleteAll(postCommentList);
}

postRepository.deleteAll(postList);

// delete member
memberRepository.delete(member);

Message message = Message.builder()
.message("회원 탈퇴가 완료되었습니다.")
.build();

return SuccessResponse.of(message);
}

@Override
public SuccessResponse<ReissueRes> reissue(String refreshToken) {
if (!jwtTokenProvider.isTokenValid(refreshToken))
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/mvp/deplog/domain/auth/presentation/AuthApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ ResponseEntity<SuccessResponse<Message>> logout(
@Parameter(description = "Schemas의 LogoutReq를 참고해주세요.", required = true) @RequestBody LogoutReq logoutReq
);

@Operation(summary = "회원 탈퇴 API", description = "회원 탈퇴를 진행합니다.")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200", description = "회원 탈퇴 성공",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}
),
@ApiResponse(
responseCode = "400", description = "회원 탈퇴 실패",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}
)
})
@DeleteMapping(value = "/exit")
ResponseEntity<SuccessResponse<Message>> exit(
@Parameter(description = "Access Token을 입력해주세요.", required = true) @AuthenticationPrincipal UserDetailsImpl userDetails
);

@Operation(summary = "토큰 재발급 API", description = "리프레시 토큰으로 액세스 토큰 재발급을 진행합니다.")
@ApiResponses(value = {
@ApiResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public ResponseEntity<SuccessResponse<Message>> logout(
return ResponseEntity.ok(authService.logout(userDetails, logoutReq));
}

@Override
@DeleteMapping(value = "/exit")
public ResponseEntity<SuccessResponse<Message>> exit(@AuthenticationPrincipal UserDetailsImpl userDetails) {
return ResponseEntity.ok(authService.exit(userDetails));
}

@Override
@GetMapping(value = "/reissue")
public ResponseEntity<SuccessResponse<ReissueRes>> reissue(@RequestParam(value = "refreshToken") String refreshToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,65 @@ public class CommentService {
public SuccessResponse<List<CommentListRes>> getCommentList(Long postId){
Post post = postRepository.findById(postId)
.orElseThrow(() -> new IllegalArgumentException("해당하는 아이디의 게시글이 없습니다: " + postId));
List<Comment> commentList = commentRepository.findByPost(post);

List<Comment> commentList = commentRepository.findByPostAndParentCommentIsNull(post);
List<Comment> replyList = commentRepository.findByPostAndParentCommentIsNotNull(post);

List<CommentListRes> commentDetails = new ArrayList<>();

for(Comment comment : commentList) {
Avatar avatar;
if (comment.isUseNickname()) {
avatar = Avatar.builder()
.avatarFace(null)
.avatarBody(null)
.avatarEyes(null)
.avatarNose(null)
.avatarMouth(null)
.build();
} else {
Member member = comment.getMember();
avatar = Avatar.builder()
.avatarFace(member.getAvatarFace())
.avatarBody(member.getAvatarBody())
.avatarEyes(member.getAvatarEyes())
.avatarNose(member.getAvatarNose())
.avatarMouth(member.getAvatarMouth())
.build();
}
Avatar avatar = commentAvatar(comment);

CommentListRes commentListRes = CommentListRes.builder()
.commentId(comment.getId())
.avatar(avatar)
.nickname(comment.getNickname())
.createdDate(comment.getCreatedDate().toLocalDate())
.content(comment.getContent())
.replyList(new ArrayList<>()) // 대댓글 리스트 초기화
.build();

commentDetails.add(commentListRes);
}

if(comment.getParentComment() == null){
CommentListRes commentListRes = CommentListRes.builder()
.commentId(comment.getId())
.avatar(avatar)
.nickname(comment.getNickname())
.createdDate(comment.getCreatedDate().toLocalDate())
.content(comment.getContent())
.replyList(new ArrayList<>()) // 대댓글 리스트 초기화
.build();
for(Comment reply : replyList) {
Avatar avatar = commentAvatar(reply);

commentDetails.add(commentListRes);
} else {
ReplyListRes replyListRes = ReplyListRes.builder()
.commentId(comment.getId())
.parentCommentId(comment.getParentComment().getId())
.avatar(avatar)
.nickname(comment.getNickname())
.createdDate(comment.getCreatedDate().toLocalDate())
.content(comment.getContent())
.build();
ReplyListRes replyListRes = ReplyListRes.builder()
.commentId(reply.getId())
.parentCommentId(reply.getParentComment().getId())
.avatar(avatar)
.nickname(reply.getNickname())
.createdDate(reply.getCreatedDate().toLocalDate())
.content(reply.getContent())
.build();

commentDetails.stream()
.filter(parentComment -> parentComment.getCommentId().equals(comment.getParentComment().getId()))
.findFirst()
.ifPresent(parentComment -> parentComment.getReplyList().add(replyListRes));
}
commentDetails.stream()
.filter(parentComment -> parentComment.getCommentId().equals(reply.getParentComment().getId()))
.findFirst()
.ifPresent(parentComment -> parentComment.getReplyList().add(replyListRes));
}

return SuccessResponse.of(commentDetails);
}

private Avatar commentAvatar(Comment comment){
if(!comment.isUseNickname()) {
Member member = comment.getMember();
return Avatar.builder()
.avatarFace(member.getAvatarFace())
.avatarBody(member.getAvatarBody())
.avatarEyes(member.getAvatarEyes())
.avatarNose(member.getAvatarNose())
.avatarMouth(member.getAvatarMouth())
.build();
}
return Avatar.builder()
.avatarFace(null)
.avatarBody(null)
.avatarEyes(null)
.avatarNose(null)
.avatarMouth(null)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
package mvp.deplog.domain.comment.domain.repository;

import mvp.deplog.domain.comment.domain.Comment;
import mvp.deplog.domain.member.domain.Member;
import mvp.deplog.domain.post.domain.Post;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {

List<Comment> findByPost(Post post);
// 댓글 목록 조회
List<Comment> findByPostAndParentCommentIsNull(Post post);

List<Comment> findByMember(Member member);

List<Comment> findByParentComment(Comment parentComment);
// 대댓글 목록 조회
List<Comment> findByPostAndParentCommentIsNotNull(Post post);

void deleteByPost(Post post);
// 대댓글 삭제
void deleteByPostAndParentCommentIsNotNull(Post post);

// 댓글 삭제
void deleteByPostAndParentCommentIsNull(Post post);

List<Comment> findByPost(Post post);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mvp.deplog.domain.comment.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

@Data
Expand All @@ -13,11 +14,13 @@ public class CreateCommentReq {
private Long postId;

@Schema(type = "String", example = "**댓글 내용**", description = "댓글 내용입니다.")
@NotBlank
private String content;

@Schema(type = "String", example = "닉네임", description = "닉네임입니다.")
@NotBlank
private String nickname;

@Schema(type = "boolean", example = "true", description = "닉네임 사용 체크박스 체크 여부입니다. 회원이 체크 안한 경우, 비회원의 경우 모두 true입니다. 회원이 누른 경우만 falseh입니다.")
@Schema(type = "boolean", example = "true", description = "닉네임 사용 체크박스 체크 여부입니다. 회원이 체크 안한 경우, 비회원의 경우 모두 true입니다. 회원이 누른 경우만 false입니다.")
private boolean useNicknameChecked;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import mvp.deplog.domain.comment.dto.request.CreateCommentReq;
import mvp.deplog.domain.comment.dto.response.CommentListRes;
import mvp.deplog.global.common.Message;
Expand Down Expand Up @@ -40,7 +41,7 @@ public interface CommentApi {
@PostMapping
ResponseEntity<SuccessResponse<Message>> createComment(
@Parameter(description = "Access Token을 입력해주세요.", required = true) @AuthenticationPrincipal UserDetailsImpl userDetails,
@Parameter(description = "Schemas의 CommentReq를 참고해주세요.", required = true) @RequestBody CreateCommentReq createCommentReq
@Parameter(description = "Schemas의 CommentReq를 참고해주세요.", required = true) @Valid @RequestBody CreateCommentReq createCommentReq
);

@Operation(summary = "댓글 목록 조회 API", description = "해당 게시글을 댓글 목록을 조회합니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mvp.deplog.domain.comment.presentation;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import mvp.deplog.domain.comment.application.CommentService;
import mvp.deplog.domain.comment.application.CreateCommentService;
Expand All @@ -26,7 +27,8 @@ public class CommentController implements CommentApi {

@Override
@PostMapping
public ResponseEntity<SuccessResponse<Message>> createComment(@AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody CreateCommentReq createCommentReq) {
public ResponseEntity<SuccessResponse<Message>> createComment(@AuthenticationPrincipal UserDetailsImpl userDetails,
@Valid @RequestBody CreateCommentReq createCommentReq) {
CreateCommentService createCommentService = createCommentServiceFactory.find(userDetails, createCommentReq.getParentCommentId());
return ResponseEntity
.status(HttpStatus.CREATED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mvp.deplog.domain.post.domain.Post;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface LikesRepository extends JpaRepository<Likes, Long> {
Expand All @@ -13,5 +14,7 @@ public interface LikesRepository extends JpaRepository<Likes, Long> {

Optional<Likes> findByMemberAndPost(Member member, Post post);

List<Likes> findAllByMember(Member member);

void deleteByPost(Post post);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MemberPostDetailServiceImpl implements PostDetailService<MemberPost

@Override
public boolean supports(UserDetailsImpl userDetails) {
return userDetails.getMember().getRole().equals(Role.MEMBER) || userDetails.getMember().getRole().equals(Role.ADMIN);
return userDetails != null && (userDetails.getMember().getRole().equals(Role.MEMBER) || userDetails.getMember().getRole().equals(Role.ADMIN));
}

@Override
Expand Down
Loading

0 comments on commit 13bd349

Please sign in to comment.