Skip to content

Commit

Permalink
Merge pull request #31 from 9oormthon-univ/dev
Browse files Browse the repository at this point in the history
♻️Refactor: 사용자가 작성한 PT 영상 게시글 조회 기능 수정
  • Loading branch information
eunxeum authored Nov 22, 2024
2 parents 287c41f + fa916e3 commit 56126f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public ResponseEntity<BoardInfoResDto> boardInfo(@PathVariable(name = "boardId")
@ApiResponse(responseCode = "404", description = "게시글 없음", content = @Content(schema = @Schema(example = "게시글이 존재하지 않습니다."))),
})
@GetMapping("/my")
public ResponseEntity<BoardInfoResDto> myBoardInfo(@User LoginUser loginUser, @PathVariable(name = "boardId") Long boardId) {
BoardInfoResDto myBoardInfo = boardService.myBoardInfo(loginUser.getMemberId(), boardId);
public ResponseEntity<BoardInfoResDto> myBoardInfo(@User LoginUser loginUser) {
BoardInfoResDto myBoardInfo = boardService.myBoardInfo(loginUser.getMemberId());
return new ResponseEntity<>(myBoardInfo, HttpStatus.OK);
}

Expand Down Expand Up @@ -107,4 +107,5 @@ public ResponseEntity<Void> boardDelete(@User LoginUser loginUser,
boardService.boardDelete(loginUser.getMemberId(), boardId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,14 @@ public BoardInfoResDto boardInfo(Long boardId) {

// (내가 작성한) 게시글 한개 조회
@Transactional
public BoardInfoResDto myBoardInfo(Long memberId, Long boardId) {
public BoardInfoResDto myBoardInfo(Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다."));

Board board = boardRepository.findById(boardId)
Board board = boardRepository.findFirstByWriter(member)
.orElseThrow(() -> new IllegalArgumentException("게시글이 존재하지 않습니다."));

checkBoardOwnership(member, board);

boolean isLike = boardLikeRepository.existsByBoardAndMember(board, member);

return BoardInfoResDto.of(member, board, isLike);
}

Expand Down Expand Up @@ -148,4 +145,4 @@ public Board findById(Long boardId) {
return boardRepository.findById(boardId)
.orElseThrow(() -> new IllegalArgumentException("게시글이 존재하지 않습니다."));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.springframework.data.jpa.repository.JpaRepository;
import univ.yesummit.domain.board.domain.Board;
import univ.yesummit.domain.member.entity.Member;

import java.util.List;

import java.util.Optional;

public interface BoardRepository extends JpaRepository<Board, Long> {
Optional<Board> findFirstByWriter(Member member);
List<Board> findBySummitId(Long summitId);
}

0 comments on commit 56126f4

Please sign in to comment.