Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
[BE] feat: 발행 후 발행 url 글 정보 조회 API 응답에 추가 (#410)
Browse files Browse the repository at this point in the history
feat: 발행 후 글 조회시 글 정보에 발행 글 url 필드 추가
  • Loading branch information
Eun-chan Cho committed Oct 6, 2023
1 parent b0893e4 commit f550f7c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -197,10 +199,7 @@ private void changeCategory(final Long memberId, final Long categoryId, final Wr
private List<PublishedDetailResponse> convertToPublishedDetailResponses(final Long findWriting) {
final List<BlogWriting> blogWritings = blogWritingRepository.findByWritingId(findWriting);
return blogWritings.stream()
.map(blogWriting -> new PublishedDetailResponse(
blogWriting.getBlogTypeValue(),
blogWriting.getPublishedAt(),
blogWriting.getTags()))
.map(PublishedDetailResponse::of)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public class BlogWriting extends BaseEntity {
private LocalDateTime publishedAt;
@ElementCollection
private List<String> tags;
private String url;

public BlogWriting(final Blog blog, final Writing writing, final LocalDateTime publishedAt, final List<String> tags) {
public BlogWriting(final Blog blog, final Writing writing, final LocalDateTime publishedAt, final List<String> tags, final String url) {
this.blog = blog;
this.writing = writing;
this.publishedAt = publishedAt;
this.tags = tags;
this.url = url;
}

public String getBlogTypeValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public PublishResponse toPublishResponse() {
return PublishResponse.builder()
.dateTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(publishedAt), ZoneId.systemDefault()))
.tags(tags)
.url(url)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Builder
public record PublishResponse(
LocalDateTime dateTime,
List<String> tags
List<String> tags,
String url
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
public record PublishedDetailResponse(
String blogName,
LocalDateTime publishedAt,
List<String> tags
List<String> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f550f7c

Please sign in to comment.