Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
L-U-Ready committed Nov 28, 2024
2 parents 7dabd23 + 64f2967 commit 69df8b6
Showing 8 changed files with 56 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package the_monitor.application.dto;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -11,6 +10,7 @@
public class ScrapArticleDto {

private Long articleId;
private String keyword;
private String title;
private String body;
private String url;
@@ -22,6 +22,7 @@ public class ScrapArticleDto {

@Builder
public ScrapArticleDto(Long articleId,
String keyword,
String title,
String body,
String url,
@@ -32,6 +33,7 @@ public ScrapArticleDto(Long articleId,
CategoryType categoryType) {

this.articleId = articleId;
this.keyword = keyword;
this.title = title;
this.body = body;
this.url = url;
10 changes: 2 additions & 8 deletions src/main/java/the_monitor/application/service/ScrapService.java
Original file line number Diff line number Diff line change
@@ -2,18 +2,12 @@

import the_monitor.application.dto.ScrapArticleDto;
import the_monitor.application.dto.response.ScrapCategoryTypeResponse;
import the_monitor.domain.model.Scrap;

import java.util.List;

public interface ScrapService {

Scrap findById(Long scrapId);

String scrapArticle(Long articleId);

// ScrapArticleListResponse getScrapArticleList(Long clientId, ScrapIdsRequest request);

ScrapCategoryTypeResponse getScrappedArticlesByClientId();

ScrapArticleDto getScrapArticleInfo(Long scrapId);

}
Original file line number Diff line number Diff line change
@@ -12,16 +12,12 @@
import the_monitor.application.dto.ArticleGoogleDto;
import the_monitor.application.dto.response.ArticleResponse;
import the_monitor.application.service.GoogleSearchService;
import the_monitor.domain.model.Keyword;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

@Slf4j
@Service
@@ -141,12 +137,14 @@ private ArticleResponse parseResponse(String jsonResponse) {
JsonNode metatagsNode = item.path("pagemap").path("metatags");
if (metatagsNode.isArray() && metatagsNode.has(0)) {
publisher = metatagsNode.get(0).path("og:site_name").asText("");
publishDate = metatagsNode.get(0).path("article:published_time").asText("");
publishDate = OffsetDateTime.parse(
metatagsNode.get(0).path("article:published_time").asText("")
).format(DateTimeFormatter.ofPattern("yyyy.MM.dd"));
reporter = metatagsNode.get(0).path("dable:author").asText("");
}

// publisher와 publishDate가 null이면 추가하지 않음.
if ((publisher == null || publisher.isEmpty()) && (publishDate == null || publishDate.isEmpty())) {
if ((publisher == null || publisher.isEmpty()) && publishDate.isEmpty()) {
continue;
}

Original file line number Diff line number Diff line change
@@ -70,16 +70,14 @@ public ReportCreateResponse createReports(ReportCreateRequest request, Multipart

String logoUrl = getLogoUrl(logo, client.getLogo());

System.out.println("Media: " + request.isMedia());
System.out.println("Reporter: " + request.isReporter());

Report report = reportRepository.save(request.toEntity(client, logoUrl));
// 각 카테고리별로 ReportArticle 생성 및 저장
createAndSaveReportArticlesByCategories(report, request);

return ReportCreateResponse.builder()
.reportId(report.getId())
.build();

}

@Override
@@ -387,10 +385,6 @@ private ReportArticle findReportArticleById(Long reportArticleId) {
.orElseThrow(() -> new ApiException(ErrorStatus._REPORT_ARTICLE_NOT_FOUND));
}

private List<ReportArticle> findReportArticleByReportId(Long reportId) {
return reportArticleRepository.findByReportId(reportId);
}

// Client ID와 Report ID로 Report 조회
private Report findByClientIdAndReportId(Long clientId, Long reportId) {
return reportRepository.findReportByClientIdAndReportId(clientId, reportId);
@@ -490,7 +484,7 @@ private ReportArticle copyReportArticleFromArticle(Long articleId, ReportCategor
.publishDate(article.getPublishDate())
.categoryType(reportCategory.getCategoryType())
.reportCategory(reportCategory)
.keyword(article.getKeyword().toString())
.keyword(article.getKeyword().getKeyword())
.build();

}
@@ -533,7 +527,7 @@ private ReportArticlesResponse buildArticlesResponse(ReportArticle article) {
return ReportArticlesResponse.builder()
.ReportArticleId(article.getId())
.keyword(article.getKeyword())
.publishedDate(article.getPublishDate() != null ? article.getPublishDate().toString() : null)
.publishedDate(article.getPublishDate() != null ? article.getPublishDate() : null)
.headLine(article.getTitle())
.url(article.getUrl())
.media(article.getPublisherName())
Original file line number Diff line number Diff line change
@@ -7,9 +7,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import the_monitor.application.dto.ScrapArticleDto;
import the_monitor.application.dto.response.ReportArticlesResponse;
import the_monitor.application.dto.response.ReportCategoryResponse;
import the_monitor.application.dto.response.ReportCategoryTypeResponse;
import the_monitor.application.dto.response.ScrapCategoryTypeResponse;
import the_monitor.application.service.ClientService;
import the_monitor.application.service.ScrapService;
@@ -41,12 +38,6 @@ public class ScrapServiceImpl implements ScrapService {
private final ClientRepository clientRepository;
private final AccountRepository accountRepository;

@Override
public Scrap findById(Long scrapId) {
return scrapRepository.findById(scrapId)
.orElseThrow(() -> new ApiException(ErrorStatus._SCRAP_NOT_FOUND));
}

@Override
@Transactional
public String scrapArticle(Long articleId) {
@@ -59,7 +50,7 @@ public String scrapArticle(Long articleId) {
// 3. Article 조회
Article article = findArticleById(articleId);

String responseMsg = "";
String responseMsg;

if (article.isScrapped()) {
findAndDeleteByClientAndTitleAndUrl(client, article);
@@ -92,6 +83,15 @@ public ScrapCategoryTypeResponse getScrappedArticlesByClientId() {

}

@Override
public ScrapArticleDto getScrapArticleInfo(Long scrapId) {

Scrap scrap = findScrapById(scrapId);

return buildScrapArticleDto(scrap);

}

private Long getAccountId() {

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
@@ -118,6 +118,11 @@ private Article findArticleById(Long articleId) {
.orElseThrow(() -> new ApiException(ErrorStatus._ARTICLE_NOT_FOUND));
}

private Scrap findScrapById(Long scrapId) {
return scrapRepository.findById(scrapId)
.orElseThrow(() -> new ApiException(ErrorStatus._SCRAP_NOT_FOUND));
}

private void findAndDeleteByClientAndTitleAndUrl(Client client, Article article) {

Scrap scrap = scrapRepository.findByClientAndTitleAndUrl(client, article.getTitle(), article.getUrl())
@@ -129,6 +134,8 @@ private void findAndDeleteByClientAndTitleAndUrl(Client client, Article article)

private void buildAndSaveScrap(Article article, Client client) {

System.out.println("스크랩 키워드" + article.getKeyword().getKeyword());

Scrap scrap = Scrap.builder()
.client(client)
.title(article.getTitle())
@@ -149,6 +156,7 @@ private Map<CategoryType, List<ScrapArticleDto>> groupedByCategory(List<Article>
return scrappedArticles.stream()
.map(article -> ScrapArticleDto.builder()
.articleId(article.getId())
.keyword(article.getKeyword().getKeyword())
.title(article.getTitle())
.body(article.getBody())
.url(article.getUrl())
@@ -177,6 +185,19 @@ private ScrapCategoryTypeResponse buildScrapCategoryTypeResponse(Map<CategoryTyp

}

private ScrapArticleDto buildScrapArticleDto(Scrap scrap) {
return ScrapArticleDto.builder()
.articleId(scrap.getId())
.keyword(scrap.getKeyword())
.title(scrap.getTitle())
.url(scrap.getUrl())
.publisherName(scrap.getPublisherName())
.publishDate(scrap.getPublishDate())
.reporterName(scrap.getReporterName())
.categoryType(scrap.getCategoryType())
.build();
}

}


4 changes: 3 additions & 1 deletion src/main/java/the_monitor/common/BaseTimeEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package the_monitor.common;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
@@ -17,10 +18,11 @@ public class BaseTimeEntity {

@CreatedDate
@Column(name = "created_at", nullable = false)
@JsonFormat(pattern = "yyyy.MM.dd")
private LocalDateTime createdAt;

@LastModifiedDate
@Column(name = "updated_at", nullable = false)
@JsonFormat(pattern = "yyyy.MM.dd")
private LocalDateTime updatedAt;

}
2 changes: 0 additions & 2 deletions src/main/java/the_monitor/presentation/ArticleController.java
Original file line number Diff line number Diff line change
@@ -3,9 +3,7 @@
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import the_monitor.application.dto.request.ScrapReportArticleRequest;
import the_monitor.application.dto.response.ArticleResponse;
import the_monitor.application.dto.response.ScrapReportArticeResponse;
import the_monitor.application.service.ArticleService;
import the_monitor.common.ApiResponse;
import the_monitor.common.PageResponse;
11 changes: 8 additions & 3 deletions src/main/java/the_monitor/presentation/ScrapController.java
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
import the_monitor.application.service.ScrapService;
import the_monitor.common.ApiResponse;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/scrap")
@@ -21,7 +19,7 @@ public class ScrapController {
@PostMapping()
public ApiResponse<String> scrapArticle(@RequestParam("articleId") Long articleId) {

return ApiResponse.onSuccessData("기사 스크랩 변경 => ", scrapService.scrapArticle(articleId));
return ApiResponse.onSuccessData("기사 스크랩 변경", scrapService.scrapArticle(articleId));

}

@@ -31,4 +29,11 @@ public ApiResponse<ScrapCategoryTypeResponse> getScrappedArticlesByClientId() {
return ApiResponse.onSuccessData("스크랩 기사 조회 성공", scrapService.getScrappedArticlesByClientId());
}

@GetMapping("info")
public ApiResponse<ScrapArticleDto> getScrapArticleInfo(@RequestParam("scrapId") Long scrapId) {

return ApiResponse.onSuccessData("스크랩 기사 상세 조회 성공", scrapService.getScrapArticleInfo(scrapId));

}

}

0 comments on commit 69df8b6

Please sign in to comment.