Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#106 Exception Handling #107

Merged
merged 11 commits into from
May 4, 2024
Prev Previous commit
Next Next commit
refactor: NewsDetailResponse κ΅¬ν˜„
  • Loading branch information
yeonjy committed May 3, 2024
commit 818579672fa31d7f922190fd1ba0a6ad14b4f4dc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.rollthedice.backend.domain.news.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class NewsDetailResponse {
private Long id;
private String url;
private String title;
private String content;
private String thumbnailUrl;
private String postDate;
private Boolean isBookmarked;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rollthedice.backend.domain.news.mapper;

import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse;
import com.rollthedice.backend.domain.news.dto.response.NewsResponse;
import com.rollthedice.backend.domain.news.entity.News;
import org.mapstruct.Mapper;
Expand All @@ -9,4 +10,6 @@
public interface NewsMapper {

NewsResponse toResponse(final News news, boolean isBookmarked);

NewsDetailResponse toDetailResponse(final News news, boolean isBookmarked);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rollthedice.backend.domain.bookmark.service.BookmarkService;
import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse;
import com.rollthedice.backend.domain.news.exception.NewsNotFoundException;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import com.rollthedice.backend.domain.news.contentqueue.ContentProducer;
Expand Down Expand Up @@ -66,7 +67,9 @@ public List<NewsResponse> getNews(final Pageable pageable) {
.collect(Collectors.toList());
}

public News getOneNews(Long newsId) {
return newsRepository.findById(newsId).orElseThrow(NewsNotFoundException::new);
public NewsDetailResponse getDetailNews(Long newsId) {
Member member = authService.getMember();
final News news = newsRepository.findById(newsId).orElseThrow(NewsNotFoundException::new);
return newsMapper.toDetailResponse(news, bookmarkService.isBookmarked(member, news));
}
}