Skip to content

Commit

Permalink
feat : 3차 세미나 실습 과제_blogService에 요청으로 들어온 memberId가 블로그의 소유주인지 확인하는 메…
Browse files Browse the repository at this point in the history
…소드 추가 #7
  • Loading branch information
PicturePark1101 committed May 1, 2024
1 parent 3577cc3 commit 1446d46
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@Service
@RequiredArgsConstructor
public class BlogService {

private final BlogRepository blogRepository;
private final MemberService memberService;

Expand All @@ -24,7 +25,7 @@ public String create(Long memberId, BlogCreateRequest blogCreateRequest) {
return blog.getId().toString();
}

private Blog findById(Long blogId) {
public Blog findById(Long blogId) {
return blogRepository.findById(blogId).orElseThrow(
() -> new NotFoundException(ErrorMessage.BLOG_NOT_FOUND)
);
Expand All @@ -36,4 +37,10 @@ public void updateTitle(Long blogId, BlogTitleUpdateRequest blogTitleUpdateReque
blog.updateTitle(blogTitleUpdateRequest);
// blogRepository.save(blog); 이렇게 해도 됨.
}

public void validateOwner(Long requestMemberId, Long findMemberId) {
if (!requestMemberId.equals(findMemberId)) {
throw new NotFoundException(ErrorMessage.BLOG_UNAUTHORIZED);
}
}
}

0 comments on commit 1446d46

Please sign in to comment.