@@ -26,25 +26,29 @@ public class BoardService {
2626 private final PostJpaRepo postJpaRepo ;
2727 private final UserJpaRepo userJpaRepo ;
2828
29+ // 게시판 이름으로 게시판을 조회. 없을경우 CResourceNotExistException 처리
2930 public Board findBoard (String boardName ) {
3031 return Optional .ofNullable (boardJpaRepo .findByName (boardName )).orElseThrow (CResourceNotExistException ::new );
3132 }
3233
34+ // 게시판 이름으로 게시물 리스트 조회.
3335 public List <Post > findPosts (String boardName ) {
34- Board board = findBoard (boardName );
35- return postJpaRepo .findByBoardId (board .getId ());
36+ return postJpaRepo .findByBoard (findBoard (boardName ));
3637 }
3738
39+ // 게시물ID로 게시물 단건 조회. 없을경우 CResourceNotExistException 처리
3840 public Post getPost (long postId ) {
3941 return postJpaRepo .findById (postId ).orElseThrow (CResourceNotExistException ::new );
4042 }
4143
44+ // 게시물을 등록합니다. 게시물의 회원UID가 조회되지 않으면 CUserNotFoundException 처리합니다.
4245 public Post writePost (String uid , String boardName , ParamsPost paramsPost ) {
4346 Board board = findBoard (boardName );
44- Post post = new Post (userJpaRepo .findByUid (uid ).orElseThrow (CUserNotFoundException ::new ), board . getId () , paramsPost .getAuthor (), paramsPost .getTitle (), paramsPost .getContent ());
47+ Post post = new Post (userJpaRepo .findByUid (uid ).orElseThrow (CUserNotFoundException ::new ), board , paramsPost .getAuthor (), paramsPost .getTitle (), paramsPost .getContent ());
4548 return postJpaRepo .save (post );
4649 }
4750
51+ // 게시물을 수정합니다. 게시물 등록자와 로그인 회원정보가 틀리면 CNotOwnerException 처리합니다.
4852 public Post updatePost (long postId , String uid , ParamsPost paramsPost ) {
4953 Post post = getPost (postId );
5054 User user = post .getUser ();
@@ -55,6 +59,7 @@ public Post updatePost(long postId, String uid, ParamsPost paramsPost) {
5559 return postJpaRepo .save (post );
5660 }
5761
62+ // 게시물을 삭제합니다. 게시물 등록자와 로그인 회원정보가 틀리면 CNotOwnerException 처리합니다.
5863 public boolean deletePost (long postId , String uid ) {
5964 Post post = getPost (postId );
6065 User user = post .getUser ();
0 commit comments