From f550f7ce625a2756e69110601b7e6b42bc1b894f Mon Sep 17 00:00:00 2001 From: Eun-chan Cho Date: Mon, 18 Sep 2023 21:44:47 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20feat:=20=EB=B0=9C=ED=96=89=20=ED=9B=84?= =?UTF-8?q?=20=EB=B0=9C=ED=96=89=20url=20=EA=B8=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EC=9D=91=EB=8B=B5=EC=97=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#410)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: 발행 후 글 조회시 글 정보에 발행 글 url 필드 추가 --- .../backend/application/service/blog/PublishService.java | 2 +- .../application/service/writing/WritingService.java | 7 +++---- .../java/org/donggle/backend/domain/blog/BlogWriting.java | 4 +++- .../client/medium/dto/response/MediumPublishResponse.java | 1 + .../dto/response/TistoryGetWritingResponseWrapper.java | 3 ++- .../org/donggle/backend/ui/response/PublishResponse.java | 3 ++- .../backend/ui/response/PublishedDetailResponse.java | 5 +++-- .../backend/application/service/PublishServiceTest.java | 2 +- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/org/donggle/backend/application/service/blog/PublishService.java b/backend/src/main/java/org/donggle/backend/application/service/blog/PublishService.java index ef13999c1..010245140 100644 --- a/backend/src/main/java/org/donggle/backend/application/service/blog/PublishService.java +++ b/backend/src/main/java/org/donggle/backend/application/service/blog/PublishService.java @@ -52,7 +52,7 @@ public PublishWritingRequest findPublishWriting(final Long memberId, final Long } public void saveProperties(final Blog blog, final Writing writing, final PublishResponse response) { - blogWritingRepository.save(new BlogWriting(blog, writing, response.dateTime(), response.tags())); + blogWritingRepository.save(new BlogWriting(blog, writing, response.dateTime(), response.tags(), response.url())); } diff --git a/backend/src/main/java/org/donggle/backend/application/service/writing/WritingService.java b/backend/src/main/java/org/donggle/backend/application/service/writing/WritingService.java index 3b2ee2bdc..c878bdac6 100644 --- a/backend/src/main/java/org/donggle/backend/application/service/writing/WritingService.java +++ b/backend/src/main/java/org/donggle/backend/application/service/writing/WritingService.java @@ -18,6 +18,8 @@ import org.donggle.backend.exception.notfound.CategoryNotFoundException; import org.donggle.backend.exception.notfound.MemberNotFoundException; import org.donggle.backend.exception.notfound.WritingNotFoundException; +import org.donggle.backend.infrastructure.client.notion.NotionApiClient; +import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import org.donggle.backend.ui.response.PublishedDetailResponse; import org.donggle.backend.ui.response.WritingDetailResponse; import org.donggle.backend.ui.response.WritingListWithCategoryResponse; @@ -197,10 +199,7 @@ private void changeCategory(final Long memberId, final Long categoryId, final Wr private List convertToPublishedDetailResponses(final Long findWriting) { final List blogWritings = blogWritingRepository.findByWritingId(findWriting); return blogWritings.stream() - .map(blogWriting -> new PublishedDetailResponse( - blogWriting.getBlogTypeValue(), - blogWriting.getPublishedAt(), - blogWriting.getTags())) + .map(PublishedDetailResponse::of) .toList(); } diff --git a/backend/src/main/java/org/donggle/backend/domain/blog/BlogWriting.java b/backend/src/main/java/org/donggle/backend/domain/blog/BlogWriting.java index 9607c90b2..86391dace 100644 --- a/backend/src/main/java/org/donggle/backend/domain/blog/BlogWriting.java +++ b/backend/src/main/java/org/donggle/backend/domain/blog/BlogWriting.java @@ -34,12 +34,14 @@ public class BlogWriting extends BaseEntity { private LocalDateTime publishedAt; @ElementCollection private List tags; + private String url; - public BlogWriting(final Blog blog, final Writing writing, final LocalDateTime publishedAt, final List tags) { + public BlogWriting(final Blog blog, final Writing writing, final LocalDateTime publishedAt, final List tags, final String url) { this.blog = blog; this.writing = writing; this.publishedAt = publishedAt; this.tags = tags; + this.url = url; } public String getBlogTypeValue() { diff --git a/backend/src/main/java/org/donggle/backend/infrastructure/client/medium/dto/response/MediumPublishResponse.java b/backend/src/main/java/org/donggle/backend/infrastructure/client/medium/dto/response/MediumPublishResponse.java index 860d78d28..d4ede4047 100644 --- a/backend/src/main/java/org/donggle/backend/infrastructure/client/medium/dto/response/MediumPublishResponse.java +++ b/backend/src/main/java/org/donggle/backend/infrastructure/client/medium/dto/response/MediumPublishResponse.java @@ -26,6 +26,7 @@ public PublishResponse toPublishResponse() { return PublishResponse.builder() .dateTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(publishedAt), ZoneId.systemDefault())) .tags(tags) + .url(url) .build(); } } diff --git a/backend/src/main/java/org/donggle/backend/infrastructure/client/tistory/dto/response/TistoryGetWritingResponseWrapper.java b/backend/src/main/java/org/donggle/backend/infrastructure/client/tistory/dto/response/TistoryGetWritingResponseWrapper.java index 48e1b1b90..582b93127 100644 --- a/backend/src/main/java/org/donggle/backend/infrastructure/client/tistory/dto/response/TistoryGetWritingResponseWrapper.java +++ b/backend/src/main/java/org/donggle/backend/infrastructure/client/tistory/dto/response/TistoryGetWritingResponseWrapper.java @@ -1,8 +1,8 @@ package org.donggle.backend.infrastructure.client.tistory.dto.response; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.donggle.backend.ui.response.PublishResponse; import org.donggle.backend.infrastructure.client.tistory.util.TistoryTagsDeserializer; +import org.donggle.backend.ui.response.PublishResponse; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -36,6 +36,7 @@ public PublishResponse toPublishResponse() { return PublishResponse.builder() .dateTime(LocalDateTime.parse(tistory.item().date, formatter)) .tags(tistory.item().tags.tags()) + .url(tistory.item().postUrl) .build(); } } diff --git a/backend/src/main/java/org/donggle/backend/ui/response/PublishResponse.java b/backend/src/main/java/org/donggle/backend/ui/response/PublishResponse.java index 44a8af9ab..b7bbc62d7 100644 --- a/backend/src/main/java/org/donggle/backend/ui/response/PublishResponse.java +++ b/backend/src/main/java/org/donggle/backend/ui/response/PublishResponse.java @@ -8,6 +8,7 @@ @Builder public record PublishResponse( LocalDateTime dateTime, - List tags + List tags, + String url ) { } diff --git a/backend/src/main/java/org/donggle/backend/ui/response/PublishedDetailResponse.java b/backend/src/main/java/org/donggle/backend/ui/response/PublishedDetailResponse.java index d16cd412f..5afaecadb 100644 --- a/backend/src/main/java/org/donggle/backend/ui/response/PublishedDetailResponse.java +++ b/backend/src/main/java/org/donggle/backend/ui/response/PublishedDetailResponse.java @@ -8,9 +8,10 @@ public record PublishedDetailResponse( String blogName, LocalDateTime publishedAt, - List tags + List tags, + String url ) { public static PublishedDetailResponse of(final BlogWriting blogWriting) { - return new PublishedDetailResponse(blogWriting.getBlogTypeValue(), blogWriting.getPublishedAt(), blogWriting.getTags()); + return new PublishedDetailResponse(blogWriting.getBlogTypeValue(), blogWriting.getPublishedAt(), blogWriting.getTags(), blogWriting.getUrl()); } } diff --git a/backend/src/test/java/org/donggle/backend/application/service/PublishServiceTest.java b/backend/src/test/java/org/donggle/backend/application/service/PublishServiceTest.java index c15e0c0d8..d672c4dac 100644 --- a/backend/src/test/java/org/donggle/backend/application/service/PublishServiceTest.java +++ b/backend/src/test/java/org/donggle/backend/application/service/PublishServiceTest.java @@ -39,7 +39,7 @@ void alreadyPublishedException() { final PublishRequest medium = new PublishRequest("MEDIUM", null); final Blog blog = blogRepository.findByBlogType(BlogType.MEDIUM).orElseThrow(); final Writing writing = writingRepository.findById(1L).orElseThrow(); - blogWritingRepository.save(new BlogWriting(blog, writing, LocalDateTime.now(), null)); + blogWritingRepository.save(new BlogWriting(blog, writing, LocalDateTime.now(), null, null)); //when