Skip to content

Commit

Permalink
Merge pull request #27 from Modagbul/feat/게시글
Browse files Browse the repository at this point in the history
fix: 소모임 탈퇴 후 회원 닉네임 처리 및 test오류 해결
  • Loading branch information
minsu20 authored Oct 2, 2023
2 parents 3036011 + 3f1ba15 commit 33b3056
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public class BoardBlocks {

private Boolean isRead;

private Boolean writerIsDeleted;

@QueryProjection
public BoardBlocks(Long boardId, String writerNickName, Boolean writerIsLeader, String writerProfileImage, String title, String content, Integer commentNum) {
public BoardBlocks(Long boardId, String writerNickName, Boolean writerIsLeader, String writerProfileImage, String title, String content, Integer commentNum, Boolean writerIsDeleted) {
this.boardId = boardId;
this.writerNickName = writerNickName;
this.writerIsLeader = writerIsLeader;
Expand All @@ -36,9 +38,18 @@ public BoardBlocks(Long boardId, String writerNickName, Boolean writerIsLeader,
this.content = content;
this.commentNum = commentNum;
this.isRead = false;
this.writerIsDeleted=writerIsDeleted;
deleteMember();
}

public void readBoard() {
this.isRead = true;
}

public void deleteMember() {
if(Boolean.TRUE.equals(writerIsDeleted)) {
this.writerNickName = "(알 수 없음)";
this.writerProfileImage = "undef";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static com.moing.backend.domain.board.domain.entity.QBoard.board;
import static com.moing.backend.domain.boardRead.domain.entity.QBoardRead.boardRead;

public class BoardCustomRepositoryImpl implements BoardCustomRepository {
public class BoardCustomRepositoryImpl implements BoardCustomRepository {
private final JPAQueryFactory queryFactory;

public BoardCustomRepositoryImpl(EntityManager em) {
Expand Down Expand Up @@ -51,7 +51,8 @@ public GetAllBoardResponse findBoardAll(Long teamId, Long memberId) {
b.getWriterProfileImage(),
b.getTitle(),
b.getContent(),
b.getCommentNum()
b.getCommentNum(),
b.getTeamMember().isDeleted()
);
if (isRead) {
boardBlocks.readBoard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ public class CommentBlocks {
private String writerProfileImage;

private Boolean isWriter;

private Boolean writerIsDeleted;

public void deleteMember(){
this.writerNickName="(알 수 없음)";
this.writerProfileImage="undef";
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.moing.backend.domain.boardComment.domain.repository;

import com.moing.backend.domain.board.domain.entity.Board;
import com.moing.backend.domain.boardComment.application.dto.response.CommentBlocks;
import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse;
import com.moing.backend.domain.boardComment.application.service.GetBoardCommentUserCase;
import com.moing.backend.domain.boardComment.domain.entity.BoardComment;
import com.moing.backend.domain.boardComment.domain.entity.QBoardComment;
import com.moing.backend.domain.teamMember.domain.entity.QTeamMember;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;
import com.querydsl.core.types.ExpressionUtils;
Expand All @@ -17,7 +13,6 @@
import java.util.List;

import static com.moing.backend.domain.boardComment.domain.entity.QBoardComment.boardComment;
import static com.moing.backend.domain.teamMember.domain.entity.QTeamMember.teamMember;

public class BoardCommentCustomRepositoryImpl implements BoardCommentCustomRepository{

Expand All @@ -42,11 +37,15 @@ public GetBoardCommentResponse findBoardCommentAll(Long boardId, TeamMember team
.from(QTeamMember.teamMember)
.where(QTeamMember.teamMember.eq(teamMember)
.and(QTeamMember.teamMember.eq(boardComment.teamMember)))
.exists(), "isWriter")))
.exists(), "isWriter"),
boardComment.teamMember.isDeleted))
.from(boardComment)
.where(boardComment.board.boardId.eq(boardId))
.orderBy(boardComment.createdDate.asc())
.fetch();

commentBlocks.forEach(CommentBlocks::deleteMember);

return new GetBoardCommentResponse(commentBlocks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Member extends BaseTimeEntity {
@ColumnDefault("true")
private boolean isFirePush;

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "member")
private List<TeamMember> teamMembers = new ArrayList<>(); //최대 3개이므로 양방향

//==생성 메서드==//
Expand Down Expand Up @@ -168,4 +168,11 @@ public Member(String ageRange, String email, String fcmToken, String gender, Str
this.socialId = socialId;
}

public void deleteTeamMember(){
List<TeamMember> teamMemberList=this.getTeamMembers();
for(TeamMember teamMember:teamMemberList){
teamMember.deleteMember();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;
import com.moing.backend.global.config.security.jwt.TokenUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -11,8 +12,10 @@
public class SignOutUserCase {

private final TokenUtil tokenUtil;
private final MemberGetService memberGetService;

public void signOut(String socialId){
//TODO: teamMember가 isDeleted가 아닌게 한개라도 있으면 error 반환
tokenUtil.expireRefreshToken(socialId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.team.domain.service.TeamGetService;
import com.moing.backend.domain.team.exception.NotAuthByTeamException;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -19,11 +21,14 @@ public class DisbandTeamUserCase {
private final MemberGetService memberGetService;
private final TeamGetService teamGetService;
private final CheckLeaderUserCase checkLeaderUserCase;
private final TeamMemberGetService teamMemberGetService;

public DeleteTeamResponse disbandTeam(String socialId, Long teamId) {
Member member = memberGetService.getMemberBySocialId(socialId);
Team team = teamGetService.getTeamByTeamId(teamId);

if (checkLeaderUserCase.isTeamLeader(member, team)) {
//TODO: 팀의 모든 멤버 isDeleted true 해주환
team.deleteTeam();
} else {
throw new NotAuthByTeamException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DeleteTeamResponse withdrawTeam(String socialId, Long teamId) {
Member member = memberGetService.getMemberBySocialId(socialId);
Team team = teamGetService.getTeamByTeamId(teamId);
TeamMember teamMember = teamMemberGetService.getTeamMember(member, team);
teamMember.withdrawTeam();
teamMember.deleteMember();
return new DeleteTeamResponse(team.getTeamId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void updateMember(Member member) {
member.getTeamMembers().add(this);
}

public void withdrawTeam() {
public void deleteMember() {
this.isDeleted = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public void get_board_all() throws Exception {
.boardId(1L)
.writerIsLeader(true)
.writerNickName("작성자 닉네임")
.writerIsDeleted(false)
.writerProfileImage("작성자 프로필 이미지")
.title("공지 제목")
.content("공지 내용")
Expand All @@ -204,6 +205,7 @@ public void get_board_all() throws Exception {
.boardId(1L)
.writerIsLeader(true)
.writerNickName("작성자 닉네임")
.writerIsDeleted(false)
.writerProfileImage("작성자 프로필 이미지")
.title("게시글 제목")
.content("게시글 내용")
Expand Down Expand Up @@ -246,6 +248,7 @@ public void get_board_all() throws Exception {
fieldWithPath("data.noticeBlocks[0].writerNickName").description("작성자 닉네임"),
fieldWithPath("data.noticeBlocks[0].writerIsLeader").description("작성자 소모임장 여부"),
fieldWithPath("data.noticeBlocks[0].writerProfileImage").description("작성자 프로필 이미지"),
fieldWithPath("data.noticeBlocks[0].writerIsDeleted").description("작성자 삭제 여부"),
fieldWithPath("data.noticeBlocks[0].title").description("공지 제목"),
fieldWithPath("data.noticeBlocks[0].content").description("공지 내용"),
fieldWithPath("data.noticeBlocks[0].commentNum").description("공지 댓글 개수"),
Expand All @@ -255,6 +258,7 @@ public void get_board_all() throws Exception {
fieldWithPath("data.notNoticeBlocks[0].writerNickName").description("작성자 닉네임"),
fieldWithPath("data.notNoticeBlocks[0].writerIsLeader").description("작성자 소모임장 여부"),
fieldWithPath("data.notNoticeBlocks[0].writerProfileImage").description("작성자 프로필 이미지"),
fieldWithPath("data.notNoticeBlocks[0].writerIsDeleted").description("작성자 삭제 여부"),
fieldWithPath("data.notNoticeBlocks[0].title").description("일반 게시글 제목"),
fieldWithPath("data.notNoticeBlocks[0].content").description("일반 게시글 내용"),
fieldWithPath("data.notNoticeBlocks[0].commentNum").description("일반 게시글 댓글 개수"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

@WebMvcTest(BoardCommentController.class)
public class BoardCommentControllerTest extends CommonControllerTest {

@MockBean
private CreateBoardCommentUserCase createBoardCommentUserCase;
@MockBean
Expand Down Expand Up @@ -139,6 +140,7 @@ public void get_board_comment_all() throws Exception {
.writerIsLeader(true)
.writerNickName("작성자 닉네임")
.writerProfileImage("작성자 프로필 이미지")
.writerIsDeleted(false)
.isWriter(true)
.build();

Expand Down Expand Up @@ -177,6 +179,7 @@ public void get_board_comment_all() throws Exception {
fieldWithPath("data.commentBlocks[0].writerIsLeader").description("작성자 소모임장 여부"),
fieldWithPath("data.commentBlocks[0].writerNickName").description("작성자 닉네임"),
fieldWithPath("data.commentBlocks[0].writerProfileImage").description("작성자 프로필 이미지"),
fieldWithPath("data.commentBlocks[0].writerIsDeleted").description("작성자 삭제 여부"),
fieldWithPath("data.commentBlocks[0].isWriter").description("댓글 작성자 여부")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import com.moing.backend.domain.mission.application.service.MissionReadUseCase;
import com.moing.backend.domain.mission.application.service.MissionUpdateUseCase;
import com.moing.backend.domain.mission.domain.repository.MissionRepository;
import com.moing.backend.domain.mission.domain.service.MissionQueryService;
import com.moing.backend.domain.mission.presentation.MissionController;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
Expand Down Expand Up @@ -47,6 +49,9 @@ public class MissionControllerTest extends CommonControllerTest {
@MockBean
private MissionDeleteUseCase missionDeleteUseCase;

@MockBean
private MissionQueryService missionQueryService;



@Test
Expand Down

0 comments on commit 33b3056

Please sign in to comment.