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/#116 최근 조회한 뉴스 관련 기능 구현 #133

Merged
merged 40 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2a18520
chore: 도메인명 수정
realhsb May 14, 2024
e733fbe
feat: Moya networking extension 설정
realhsb May 14, 2024
1cc31d6
fix: info.plist 내용 추가 및 폴더 수정 후 경로 설정
realhsb May 14, 2024
3d280a8
chore: News 전체 조회시 사용되는 쿼리(sort) 추가
realhsb May 14, 2024
3f619a9
chore: NewsListViewModel Macro 설정
realhsb May 14, 2024
64f937d
chore: 미사용 VM 주석처리
realhsb May 14, 2024
f13bf9b
chore: API base url 설정
realhsb May 15, 2024
44be161
chore: 요약 뉴스 전체 조회 헤더 설정
realhsb May 15, 2024
cc54731
chore: News 모델 및 뷰모델 수정
realhsb May 15, 2024
7354343
chore: 카드 뉴스 및 뉴스 목록 UI 수정
realhsb May 15, 2024
95f065a
chore: NewsListViewModel 프로퍼티 래퍼 제거
realhsb May 15, 2024
f90c3a1
Merge pull request #120 from tukcomCD2024/feat/#117-ios-전체-뉴스-조회-api-연결
realhsb May 15, 2024
131319e
Merge pull request #123 from tukcomCD2024/Dev-backend
yeonjy May 15, 2024
d820da8
feat: 전체 뉴스 조회 모델과 상세 뉴스 조회 모델 분리
realhsb May 16, 2024
6ef84ac
feat: 상세 뉴스 조회 service
realhsb May 16, 2024
19d73f2
feat: 상세 뉴스 조회 ViewModel 및 View
realhsb May 16, 2024
a5a3e05
chore: DetailCardNews 디자인 수정
realhsb May 16, 2024
b5feb4b
feat: 상세 뉴스 조회 내비게이션 연결
realhsb May 16, 2024
c36ef89
chore: Pretendard Regular 16 추가
realhsb May 16, 2024
5c7ada0
Merge pull request #124 from tukcomCD2024/feat/#121-ios-kakao-social-…
realhsb May 16, 2024
50af019
Merge pull request #125 from tukcomCD2024/DeviOS
realhsb May 16, 2024
446a778
chore: 상세 뉴스 모델 및 뷰모델 이름 수정
realhsb May 16, 2024
515aacf
chore: 뉴스 목록 UI 수정
realhsb May 16, 2024
46549d3
feat: ui 수정
realhsb May 16, 2024
d3abc72
Merge pull request #127 from tukcomCD2024/Dev-backend
yeonjy May 16, 2024
3736e98
Merge pull request #128 from tukcomCD2024/feat/#126-ios-ui-수정
realhsb May 16, 2024
4f05f76
Merge pull request #129 from tukcomCD2024/DeviOS
realhsb May 16, 2024
472b41d
feat: WebView 연결
realhsb May 16, 2024
4c46e28
chore: UI 수정
realhsb May 16, 2024
738993f
Merge pull request #131 from tukcomCD2024/feat/#130-ios-상세-뉴스-url-연결을…
realhsb May 16, 2024
93688fa
Merge pull request #132 from tukcomCD2024/DeviOS
realhsb May 16, 2024
68a2bb8
Merge remote-tracking branch 'origin/Dev' into feat/#116-backend-rece…
yeonjy May 29, 2024
993c8d5
feat: 최근 읽은 뉴스 조회 api
yeonjy May 29, 2024
ec0c5bf
refactor: DebateMessageRepository directory news -> debate
yeonjy May 29, 2024
e3454a4
feat: readNews 조회 & 저장
yeonjy May 29, 2024
7e14537
feat: ReadNewsRepository
yeonjy May 29, 2024
2f600eb
style: 줄바꿈 제거
yeonjy May 29, 2024
f6c2507
feat: ReadNews Builder 구현
yeonjy May 29, 2024
6429b08
feat: ReadNewsResponse DTO 구현
yeonjy May 29, 2024
cee502b
style: summarizeNewsContent 주석 해제
yeonjy May 29, 2024
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
@@ -1,4 +1,4 @@
package com.rollthedice.backend.domain.news.repository;
package com.rollthedice.backend.domain.debate.repository;

import com.rollthedice.backend.domain.debate.entity.DebateMessage;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest;
import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse;
import com.rollthedice.backend.domain.debate.entity.DebateRoom;
import com.rollthedice.backend.domain.debate.exception.DebateRoomNotFoundException;
import com.rollthedice.backend.domain.debate.mapper.DebateMessageMapper;
import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository;
import com.rollthedice.backend.domain.news.repository.DebateMessageRepository;
import com.rollthedice.backend.domain.debate.repository.DebateMessageRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse;
import com.rollthedice.backend.domain.news.dto.response.NewsResponse;
import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
Expand Down Expand Up @@ -46,4 +47,17 @@ NewsDetailResponse getDetailNews(
Long newsId
);

@Operation(
summary = "최근 읽은 뉴스 조회",
description = "가장 최근에 읽은 3개의 뉴스를 조회합니다.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"news"}
)
@ApiResponse(
responseCode = "200",
description = "요청에 성공하였습니다."
)
List<ReadNewsResponse> getReadNews();


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.rollthedice.backend.domain.news.api;

import com.rollthedice.backend.domain.crawling.NewsCrawlingService;
import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse;
import com.rollthedice.backend.domain.news.dto.response.NewsResponse;
import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse;
import com.rollthedice.backend.domain.news.service.NewsService;
import com.rollthedice.backend.domain.news.service.ReadNewsService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
Expand All @@ -15,6 +18,8 @@
@RequestMapping("news")
public class NewsController implements NewsApi {
private final NewsService newsService;
private final ReadNewsService readNewsService;
private final NewsCrawlingService crawlingService;

@ResponseStatus(HttpStatus.OK)
@GetMapping("")
Expand All @@ -28,4 +33,10 @@ public List<NewsResponse> getNews(final Pageable pageable) {
public NewsDetailResponse getDetailNews(final @PathVariable Long newsId) {
return newsService.getDetailNews(newsId);
}

@ResponseStatus(HttpStatus.OK)
@GetMapping("/viewed-history")
public List<ReadNewsResponse> getReadNews() {
return readNewsService.getReadNews();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 ReadNewsResponse {
private Long id;
private String title;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.rollthedice.backend.global.config.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -23,4 +24,10 @@ public class ReadNews extends BaseTimeEntity {
@JoinColumn(name = "news_id")
private News news;

@Builder
public ReadNews(Member member, News news) {
this.member = member;
this.news = news;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse;
import com.rollthedice.backend.domain.news.dto.response.NewsResponse;
import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse;
import com.rollthedice.backend.domain.news.entity.News;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants.ComponentModel;
Expand All @@ -11,5 +12,7 @@ public interface NewsMapper {

NewsResponse toResponse(final News news, boolean isBookmarked);

ReadNewsResponse toReadNewsResponse(final News news);

NewsDetailResponse toDetailResponse(final News news);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
@Repository
public interface NewsRepository extends JpaRepository<News, Long> {
List<News> findAllByContentIsNull();
List<News> findAllByOrderByViewsDescCreatedAtDesc(
final Pageable pageable);
List<News> findAllByOrderByViewsDescCreatedAtDesc(final Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.rollthedice.backend.domain.news.repository;

import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.news.entity.ReadNews;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ReadNewsRepository extends JpaRepository<ReadNews, Long> {
List<ReadNews> getTop3ByMemberOrderByCreatedAtDesc(Member member);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
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.dto.response.ReadNewsResponse;
import com.rollthedice.backend.domain.news.entity.ReadNews;
import com.rollthedice.backend.domain.news.exception.NewsNotFoundException;
import com.rollthedice.backend.domain.news.repository.ReadNewsRepository;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import com.rollthedice.backend.domain.news.contentqueue.ContentProducer;
import com.rollthedice.backend.domain.news.dto.ContentMessageDto;
Expand All @@ -29,6 +32,7 @@ public class NewsService {
private final AuthService authService;
private final ContentProducer contentProducer;
private final NewsRepository newsRepository;
private final ReadNewsRepository readNewsRepository;
private final NewsMapper newsMapper;
private final BookmarkService bookmarkService;

Expand Down Expand Up @@ -69,6 +73,13 @@ public List<NewsResponse> getNews(final Pageable pageable) {

public NewsDetailResponse getDetailNews(Long newsId) {
final News news = newsRepository.findById(newsId).orElseThrow(NewsNotFoundException::new);
readNewsRepository.save(ReadNews.builder()
.member(authService.getMember()).news(news).build());
return newsMapper.toDetailResponse(news);
}

public List<ReadNewsResponse> getNewsByReadNews(final List<News> news) {
return news.stream().map(newsMapper::toReadNewsResponse).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.rollthedice.backend.domain.news.service;

import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse;
import com.rollthedice.backend.domain.news.entity.ReadNews;
import com.rollthedice.backend.domain.news.repository.ReadNewsRepository;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class ReadNewsService {
private final AuthService authService;
private final ReadNewsRepository readNewsReository;
private final NewsService newsService;

public List<ReadNewsResponse> getReadNews() {
Member member = authService.getMember();
List<ReadNews> readNews = readNewsReository.getTop3ByMemberOrderByCreatedAtDesc(member);
return newsService.getNewsByReadNews(readNews.stream().map(r -> r.getNews()).collect(Collectors.toList()));
}
}
Loading
Loading