Skip to content

Commit

Permalink
Merge pull request #559 from woowacourse-teams/fix/tag_update
Browse files Browse the repository at this point in the history
tag 수정시 존재하는 태그가 사라지는 오류 수정
  • Loading branch information
kyum-q authored Aug 22, 2024
2 parents 827807a + 39063b3 commit 2dafb0e
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ public class TemplateTagService {
@Transactional
public void createTags(Template template, List<String> tagNames) {
List<String> existingTags = tagRepository.findNameByNamesIn(tagNames);
templateTagRepository.saveAll(
existingTags.stream()
.map(tagRepository::fetchByName)
.map(tag -> new TemplateTag(template, tag))
.toList()
);

List<Tag> newTags = tagRepository.saveAll(
tagNames.stream()
.filter(tagName -> !existingTags.contains(tagName))
.map(Tag::new)
.toList()
);

templateTagRepository.saveAll(
newTags.stream()
.map(tag -> new TemplateTag(template, tag))
Expand Down

0 comments on commit 2dafb0e

Please sign in to comment.