Skip to content

Commit

Permalink
concise code, consider leveraging streams directly
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 25, 2024
1 parent 67f8292 commit 5705ca8
Showing 1 changed file with 1 addition and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.demo.readreplica.domain;

import static com.example.demo.readreplica.domain.CommentDTO.convertToComment;

import com.example.demo.readreplica.entities.Article;
import com.example.demo.readreplica.entities.Comment;
import java.time.LocalDateTime;
import java.util.List;

Expand All @@ -16,11 +13,7 @@ public record ArticleDTO(
public Article convertToArticle() {
Article article =
new Article().setAuthored(authored).setTitle(title).setPublished(published);
commentDTOs.forEach(
commentDTO -> {
Comment comment = convertToComment(commentDTO);
article.addComment(comment);
});
commentDTOs.stream().map(CommentDTO::convertToComment).forEach(article::addComment);
return article;
}
}

0 comments on commit 5705ca8

Please sign in to comment.