Skip to content

Commit

Permalink
[HotFix] Disable frameOptions (#259)
Browse files Browse the repository at this point in the history
* [Refactor/#254] add query of delete board with relations

* [Refactor/#254] complete remove question with relations

* [Refactor/#254] unify delete board query

* [Refactor/#254] apply unified deleting board query at each controller method

* [Refactor/#254] apply unified deleting board query at schedule controller method

* [HotFix] Disable frameOptions

---------

Co-authored-by: hann <wjdgks1233@gmail.com>
  • Loading branch information
ahnsugyeong and Han-Jeong authored May 14, 2024
1 parent 2fa7c08 commit fd7cb38
Show file tree
Hide file tree
Showing 27 changed files with 166 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ Long updateQuestion(Long boardId,

void deleteQuestion(Long boardId, Member member);

void deleteQuestionWithRelations(Long boardId, Member member);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.waggle.domain.board.application.question;

import com.example.waggle.domain.board.application.board.BoardService;
import com.example.waggle.domain.board.persistence.dao.board.jpa.BoardRepository;
import com.example.waggle.domain.board.persistence.dao.question.jpa.QuestionRepository;
import com.example.waggle.domain.board.persistence.entity.Question;
import com.example.waggle.domain.board.persistence.entity.ResolutionStatus;
import com.example.waggle.domain.board.presentation.dto.question.QuestionRequest;
import com.example.waggle.domain.conversation.persistence.dao.comment.jpa.CommentRepository;
import com.example.waggle.domain.media.application.MediaCommandService;
import com.example.waggle.domain.member.persistence.entity.Member;
import com.example.waggle.domain.recommend.persistence.dao.RecommendRepository;
Expand All @@ -25,6 +27,8 @@ public class QuestionCommandServiceImpl implements QuestionCommandService {

private final QuestionRepository questionRepository;
private final RecommendRepository recommendRepository;
private final CommentRepository commentRepository;
private final BoardRepository boardRepository;
private final BoardService boardService;
private final MediaCommandService mediaCommandService;

Expand Down Expand Up @@ -88,6 +92,15 @@ public void deleteQuestion(Long boardId, Member member) {
questionRepository.delete(question);
}

@Override
public void deleteQuestionWithRelations(Long boardId, Member member) {
if (!boardService.validateMemberUseBoard(boardId, QUESTION, member)) {
throw new QuestionHandler(ErrorStatus.BOARD_CANNOT_EDIT_OTHERS);
}
commentRepository.deleteCommentsWithRelationsByBoard(boardId);
boardRepository.deleteBoardsWithRelations(QUESTION, boardId);
}

private Question buildQuestion(QuestionRequest createQuestionRequest, Member member) {
return Question.builder()
.title(createQuestionRequest.getTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ Long updateSiren(Long boardId,

void deleteSiren(Long boardId, Member member);

void deleteSirenWithRelations(Long boardId, Member member);

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.example.waggle.domain.board.application.siren;

import com.example.waggle.domain.board.application.board.BoardService;
import com.example.waggle.domain.board.persistence.dao.board.jpa.BoardRepository;
import com.example.waggle.domain.board.persistence.dao.siren.jpa.SirenRepository;
import com.example.waggle.domain.board.persistence.entity.ResolutionStatus;
import com.example.waggle.domain.board.persistence.entity.Siren;
import com.example.waggle.domain.board.persistence.entity.SirenCategory;
import com.example.waggle.domain.board.presentation.dto.siren.SirenRequest;
import com.example.waggle.domain.conversation.application.comment.CommentCommandService;
import com.example.waggle.domain.conversation.persistence.dao.comment.jpa.CommentRepository;
import com.example.waggle.domain.media.application.MediaCommandService;
import com.example.waggle.domain.member.persistence.entity.Gender;
import com.example.waggle.domain.member.persistence.entity.Member;
import com.example.waggle.domain.recommend.persistence.dao.RecommendRepository;
import com.example.waggle.exception.object.handler.QuestionHandler;
import com.example.waggle.exception.object.handler.SirenHandler;
import com.example.waggle.exception.payload.code.ErrorStatus;
import com.example.waggle.global.service.redis.RedisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -30,10 +31,11 @@ public class SirenCommandServiceImpl implements SirenCommandService {

private final SirenRepository sirenRepository;
private final RecommendRepository recommendRepository;
private final CommentRepository commentRepository;
private final BoardRepository boardRepository;
private final BoardService boardService;
private final CommentCommandService commentCommandService;
private final MediaCommandService mediaCommandService;
private final RedisService redisService;

@Override
public Long createSiren(SirenRequest createSirenRequest, Member member) {
Expand Down Expand Up @@ -88,6 +90,15 @@ public void deleteSiren(Long boardId, Member member) {
sirenRepository.delete(siren);
}

@Override
public void deleteSirenWithRelations(Long boardId, Member member) {
if (!boardService.validateMemberUseBoard(boardId, SIREN, member)) {
throw new SirenHandler(ErrorStatus.BOARD_CANNOT_EDIT_OTHERS);
}
commentRepository.deleteCommentsWithRelationsByBoard(boardId);
boardRepository.deleteBoardsWithRelations(SIREN, boardId);
}

private Siren buildSiren(SirenRequest createSirenRequest, Member member) {
return Siren.builder()
.title(createSirenRequest.getTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Long updateStory(Long boardId,

void deleteStory(Long boardId, Member member);

void deleteStoryWithRelations(Long boardId, Member member);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.waggle.domain.board.application.story;

import com.example.waggle.domain.board.application.board.BoardService;
import com.example.waggle.domain.board.persistence.dao.board.jpa.BoardRepository;
import com.example.waggle.domain.board.persistence.dao.story.jpa.StoryRepository;
import com.example.waggle.domain.board.persistence.entity.Story;
import com.example.waggle.domain.board.presentation.dto.story.StoryRequest;
import com.example.waggle.domain.conversation.application.comment.CommentCommandService;
import com.example.waggle.domain.conversation.persistence.dao.comment.jpa.CommentRepository;
import com.example.waggle.domain.media.application.MediaCommandService;
import com.example.waggle.domain.member.persistence.entity.Member;
import com.example.waggle.domain.recommend.persistence.dao.RecommendRepository;
Expand All @@ -24,6 +26,8 @@
public class StoryCommandServiceImpl implements StoryCommandService {

private final StoryRepository storyRepository;
private final BoardRepository boardRepository;
private final CommentRepository commentRepository;
private final RecommendRepository recommendRepository;
private final BoardService boardService;
private final MediaCommandService mediaCommandService;
Expand Down Expand Up @@ -77,6 +81,15 @@ public void deleteStory(Long boardId, Member member) {
storyRepository.delete(story);
}

@Override
public void deleteStoryWithRelations(Long boardId, Member member) {
if (!boardService.validateMemberUseBoard(boardId, STORY, member)) {
throw new StoryHandler(ErrorStatus.BOARD_CANNOT_EDIT_OTHERS);
}
commentRepository.deleteCommentsWithRelationsByBoard(boardId);
boardRepository.deleteBoardsWithRelations(STORY, boardId);
}

private Story buildStory(StoryRequest createStoryRequest, Member member) {
return Story.builder()
.member(member)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.example.waggle.domain.board.persistence.dao.board;
package com.example.waggle.domain.board.persistence.dao.board.jpa;

import com.example.waggle.domain.board.persistence.dao.board.querydsl.BoardQueryRepository;
import com.example.waggle.domain.board.persistence.entity.Board;
import com.example.waggle.domain.member.persistence.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

public interface BoardRepository extends JpaRepository<Board, Long> {
public interface BoardRepository extends JpaRepository<Board, Long>, BoardQueryRepository {

List<Board> findAllByMember(Member member);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.waggle.domain.board.persistence.dao.board.querydsl;

import com.example.waggle.domain.board.persistence.entity.BoardType;

public interface BoardQueryRepository {
void deleteBoardsWithRelations(BoardType boardType, Long boardId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.waggle.domain.board.persistence.dao.board.querydsl;

import com.example.waggle.domain.board.persistence.entity.BoardType;
import com.example.waggle.exception.object.general.GeneralException;
import com.example.waggle.exception.payload.code.ErrorStatus;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import static com.example.waggle.domain.board.persistence.entity.QQuestion.question;
import static com.example.waggle.domain.board.persistence.entity.QSiren.siren;
import static com.example.waggle.domain.board.persistence.entity.QStory.story;
import static com.example.waggle.domain.hashtag.persistence.entity.QBoardHashtag.boardHashtag;
import static com.example.waggle.domain.media.persistence.entity.QMedia.media;
import static com.example.waggle.domain.recommend.persistence.entity.QRecommend.recommend;
import static com.example.waggle.domain.schedule.persistence.entity.QMemberSchedule.memberSchedule;
import static com.example.waggle.domain.schedule.persistence.entity.QSchedule.schedule;

@RequiredArgsConstructor
@Repository
public class BoardQueryRepositoryImpl implements BoardQueryRepository {
private final JPAQueryFactory queryFactory;


@Override
public void deleteBoardsWithRelations(BoardType boardType, Long boardId) {
queryFactory.delete(media).where(media.board.id.eq(boardId)).execute();
queryFactory.delete(boardHashtag).where(boardHashtag.board.id.eq(boardId)).execute();
queryFactory.delete(recommend).where(recommend.board.id.eq(boardId)).execute();
deleteByBoardType(boardType, boardId);
}

private void deleteByBoardType(BoardType boardType, Long boardId) {
switch (boardType) {
case STORY -> {
queryFactory.delete(story).where(story.id.eq(boardId)).execute();
}
case QUESTION -> {
queryFactory.delete(question).where(question.id.eq(boardId)).execute();
}
case SIREN -> {
queryFactory.delete(siren).where(siren.id.eq(boardId)).execute();
}
case SCHEDULE -> {
queryFactory.delete(memberSchedule).where(memberSchedule.schedule.id.eq(boardId)).execute();
queryFactory.delete(schedule).where(schedule.id.eq(boardId)).execute();
}
default -> {
throw new GeneralException(ErrorStatus.BOARD_INVALID_TYPE);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public ApiResponseDto<QuestionDetailDto> getQuestionByBoardId(
@DeleteMapping("/{questionId}")
public ApiResponseDto<Boolean> deleteQuestion(@PathVariable("questionId") Long questionId,
@AuthUser Member member) {
questionCommandService.deleteQuestion(questionId, member);
questionCommandService.deleteQuestionWithRelations(questionId, member);
return ApiResponseDto.onSuccess(Boolean.TRUE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ApiResponseDto<Long> convertStatus(@PathVariable("sirenId") Long sirenId,
@DeleteMapping("/{sirenId}")
public ApiResponseDto<Boolean> deleteSiren(@PathVariable("sirenId") Long sirenId,
@AuthUser Member member) {
sirenCommandService.deleteSiren(sirenId, member);
sirenCommandService.deleteSirenWithRelations(sirenId, member);
return ApiResponseDto.onSuccess(Boolean.TRUE);
}

Expand All @@ -111,7 +111,7 @@ public ApiResponseDto<Boolean> deleteSiren(@PathVariable("sirenId") Long sirenId
@GetMapping
public ApiResponseDto<SirenPagedSummaryListDto> getAllSiren(
@RequestParam(name = "currentPage", defaultValue = "0") int currentPage) {
Pageable pageable = PageRequest.of(currentPage, 8, latestSorting);
Pageable pageable = PageRequest.of(currentPage, SIREN_SIZE, latestSorting);
Page<Siren> pagedSirenList = sirenQueryService.getPagedSirenList(pageable);
SirenPagedSummaryListDto listDto = SirenConverter.toSirenPageDto(pagedSirenList);
setRecommendCntInList(listDto.getSirenList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public ApiResponseDto<StoryDetailDto> getStoryByBoardId(@PathVariable("storyId")
@DeleteMapping("/{storyId}")
public ApiResponseDto<Boolean> deleteStory(@PathVariable("storyId") Long storyId,
@AuthUser Member member) {
storyCommandService.deleteStory(storyId, member);
storyCommandService.deleteStoryWithRelations(storyId, member);
return ApiResponseDto.onSuccess(Boolean.TRUE);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.example.waggle.domain.chat.persistence.entity;

public enum ChatMessageType {
JOIN, LEAVE, TALK
JOIN, LEAVE, TALK, ENTER
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.waggle.domain.conversation.application.comment;

import com.example.waggle.domain.board.persistence.dao.board.BoardRepository;
import com.example.waggle.domain.board.persistence.dao.board.jpa.BoardRepository;
import com.example.waggle.domain.board.persistence.entity.Board;
import com.example.waggle.domain.conversation.persistence.dao.comment.jpa.CommentRepository;
import com.example.waggle.domain.conversation.persistence.dao.reply.ReplyRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
package com.example.waggle.domain.conversation.application.comment;

import com.example.waggle.domain.conversation.persistence.entity.Comment;
import com.example.waggle.domain.conversation.persistence.dao.comment.querydsl.CommentQueryRepository;
import com.example.waggle.domain.conversation.persistence.dao.comment.jpa.CommentRepository;
import com.example.waggle.domain.conversation.persistence.entity.Comment;
import com.example.waggle.domain.conversation.presentation.dto.comment.CommentResponse.QuestionCommentViewDto;
import com.example.waggle.domain.conversation.presentation.dto.comment.CommentResponse.SirenCommentViewDto;

import java.util.List;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class CommentQueryServiceImpl implements CommentQueryService {
private final CommentRepository commentRepository;
private final CommentQueryRepository commentQueryRepository;

@Override
public List<Comment> getComments(Long boardId) {
Expand All @@ -35,12 +32,12 @@ public Page<Comment> getPagedComments(Long boardId, Pageable pageable) {

@Override
public Page<SirenCommentViewDto> getPagedSirenCommentsByUserUrl(String userUrl, Pageable pageable) {
return commentQueryRepository.findPagedSirenCommentsByUserUrl(userUrl, pageable);
return commentRepository.findPagedSirenCommentsByUserUrl(userUrl, pageable);
}

@Override
public Page<QuestionCommentViewDto> getPagedQuestionCommentsByUserUrl(String userUrl, Pageable pageable) {
return commentQueryRepository.findPagedQuestionCommentsByUserUrl(userUrl, pageable);
return commentRepository.findPagedQuestionCommentsByUserUrl(userUrl, pageable);
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.example.waggle.domain.conversation.persistence.dao.comment.jpa;

import com.example.waggle.domain.board.persistence.entity.Board;
import com.example.waggle.domain.conversation.persistence.dao.comment.querydsl.CommentQueryRepository;
import com.example.waggle.domain.conversation.persistence.entity.Comment;
import com.example.waggle.domain.member.persistence.entity.Member;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface CommentRepository extends JpaRepository<Comment, Long> {
import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long>, CommentQueryRepository {
List<Comment> findByBoardId(Long boardId);

Page<Comment> findPagedCommentsByBoardId(Long boardId, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface CommentQueryRepository {

Page<QuestionCommentViewDto> findPagedQuestionCommentsByUserUrl(String userUrl, Pageable pageable);

void deleteCommentsWithRelationsByBoard(Long boardId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.example.waggle.domain.member.presentation.dto.MemberResponse.MemberSummaryDto;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
Expand All @@ -17,12 +17,13 @@
import static com.example.waggle.domain.board.persistence.entity.QQuestion.question;
import static com.example.waggle.domain.board.persistence.entity.QSiren.siren;
import static com.example.waggle.domain.conversation.persistence.entity.QComment.comment;
import static com.example.waggle.domain.conversation.persistence.entity.QReply.reply;

@Repository
@RequiredArgsConstructor
public class CommentQueryRepositoryImpl implements CommentQueryRepository {

@Autowired
private JPAQueryFactory queryFactory;
private final JPAQueryFactory queryFactory;

@Override
public Page<SirenCommentViewDto> findPagedSirenCommentsByUserUrl(String userUrl, Pageable pageable) {
Expand Down Expand Up @@ -86,4 +87,11 @@ public Page<QuestionCommentViewDto> findPagedQuestionCommentsByUserUrl(String us

return new PageImpl<>(content, pageable, total);
}

@Override
public void deleteCommentsWithRelationsByBoard(Long boardId) {
queryFactory.delete(reply).where(reply.comment.board.id.eq(boardId)).execute();
queryFactory.delete(comment).where(comment.board.id.eq(boardId)).execute();
}

}
Loading

0 comments on commit fd7cb38

Please sign in to comment.