Skip to content

Commit

Permalink
feat: saveBookmark & deleteBookmark 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjy committed Apr 20, 2024
1 parent a18ca80 commit 8c5f3d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,6 +20,7 @@
@Service
public class BookmarkService {
private final AuthService authService;
private final NewsService newsService;
private final BookmarkRepository bookmarkRepository;
private final NewsMapper newsMapper;

Expand All @@ -35,5 +37,19 @@ public List<NewsResponse> 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);
}
}

Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -66,4 +65,8 @@ public List<NewsResponse> getNews(final Pageable pageable) {
news, bookmarkService.isBookmarked(member, news)))
.collect(Collectors.toList());
}

public News getOneNews(Long newsId) {
return newsRepository.findById(newsId).orElseThrow(EntityNotFoundException::new);
}
}

0 comments on commit 8c5f3d8

Please sign in to comment.