diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/service/BookmarkService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/service/BookmarkService.java index 2a938a13..667bcf1e 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/service/BookmarkService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/service/BookmarkService.java @@ -1,5 +1,6 @@ package com.rollthedice.backend.domain.bookmark.service; +import com.rollthedice.backend.domain.bookmark.entity.Bookmark; import com.rollthedice.backend.domain.bookmark.repository.BookmarkRepository; import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.member.query.AuthService; @@ -19,6 +20,7 @@ @Service public class BookmarkService { private final AuthService authService; + private final NewsService newsService; private final BookmarkRepository bookmarkRepository; private final NewsMapper newsMapper; @@ -35,5 +37,19 @@ public List getBookmarkedNews(Pageable pageable) { .collect(Collectors.toList()); } + + @Transactional + public void saveBookmark(Long newsId) { + Member member = authService.getMember(); + bookmarkRepository.save(Bookmark.builder() + .member(member) + .news(newsService.getOneNews(newsId)) + .build()); + } + + @Transactional + public void deleteBookmark(Long newsId) { + bookmarkRepository.deleteByNewsId(newsId); + } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java index 29099278..cb59ca9a 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java @@ -1,6 +1,5 @@ package com.rollthedice.backend.domain.news.service; -import com.rollthedice.backend.domain.bookmark.entity.Bookmark; import com.rollthedice.backend.domain.bookmark.service.BookmarkService; import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.member.query.AuthService; @@ -66,4 +65,8 @@ public List getNews(final Pageable pageable) { news, bookmarkService.isBookmarked(member, news))) .collect(Collectors.toList()); } + + public News getOneNews(Long newsId) { + return newsRepository.findById(newsId).orElseThrow(EntityNotFoundException::new); + } }