Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 567a9b8

Browse files
change: Update Post REST API to Use Category
1 parent f7a40f6 commit 567a9b8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

‎src/main/java/com/springboot/blog/service/impl/PostServiceImpl.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,13 @@ public PostDto updatePost(PostDto postDto, long id) {
9494
// get post by id from the database
9595
Post post = postRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Post", "id", id));
9696

97+
Category category = categoryRepository.findById(postDto.getCategoryId()).orElseThrow(() ->
98+
new ResourceNotFoundException("Category", "id", postDto.getCategoryId()));
99+
97100
post.setTitle(postDto.getTitle());
98101
post.setDescription(postDto.getDescription());
99102
post.setContent(postDto.getContent());
103+
post.setCategory(category);
100104

101105
Post updatedPost = postRepository.save(post);
102106
return mapToDTO(updatedPost);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /