Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ public String addMeme(@RequestParam String title,
if (categoryIds != null && !categoryIds.isEmpty()) {
categoryRepository.findAllById(categoryIds)
.forEach(category -> {
MemeCategory memeCategory = MemeCategory.builder()
.meme(savedMeme)
.category(category)
.build();
MemeCategory memeCategory = MemeCategory.create(savedMeme, category);
memeCategoryRepository.save(memeCategory);
});
}
Expand Down Expand Up @@ -416,10 +413,7 @@ public String updateMeme(@PathVariable Long id,
if (categoryIds != null && !categoryIds.isEmpty()) {
categoryRepository.findAllById(categoryIds)
.forEach(category -> {
MemeCategory memeCategory = MemeCategory.builder()
.meme(meme)
.category(category)
.build();
MemeCategory memeCategory = MemeCategory.create(meme, category);
memeCategoryRepository.save(memeCategory);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public long createMeme(MemeCreateRequest request, MultipartFile imageFile) {
.filter(ids -> !ids.isEmpty())
.map(categoryRepository::findAllById)
.map(categories -> categories.stream()
.map(category -> MemeCategory.builder()
.meme(savedMeme)
.category(category)
.build())
.map(category -> MemeCategory.create(savedMeme, category))
.toList())
.ifPresent(memeCategoryRepository::saveAll);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/spring/memewikibe/domain/meme/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ private Category(String name, String imgUrl) {
this.name = name;
this.imgUrl = imgUrl;
}

/**
* Category 생성을 위한 정적 팩토리 메서드
*/
public static Category create(String name, String imgUrl) {
return Category.builder()
.name(name)
.imgUrl(imgUrl)
.build();
}
}