From 284cee2ff4155819cc0b1460fc658b98d3ed73d3 Mon Sep 17 00:00:00 2001 From: echo724 Date: Sat, 16 Sep 2023 00:41:55 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20Parser=20->=20Block=20?= =?UTF-8?q?=ED=91=9C=ED=98=84=20=EB=B3=80=EB=B0=8F=20NotionDivider=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ookmarkParser.java => NotionBookmark.java} | 8 ++-- ...{CalloutParser.java => NotionCallout.java} | 8 ++-- ...eBlockParser.java => NotionCodeBlock.java} | 6 +-- ...ockParser.java => NotionDefaultBlock.java} | 8 ++-- .../domain/parser/notion/NotionDivider.java | 13 ++++++ ...{HeadingParser.java => NotionHeading.java} | 8 ++-- .../{ImageParser.java => NotionImage.java} | 8 ++-- ...lockParser.java => NotionNormalBlock.java} | 2 +- .../domain/parser/notion/NotionParser.java | 42 +++++++++---------- .../{TodoParser.java => NotionTodo.java} | 8 ++-- ...est.java => NotionBookmarkParserTest.java} | 8 ++-- ...Test.java => NotionCalloutParserTest.java} | 12 +++--- ...rserTest.java => NotionCodeBlockTest.java} | 8 ++-- ...java => NotionDefaultBlockParserTest.java} | 14 +++---- ...Test.java => NotionHeadingParserTest.java} | 4 +- ...geParserTest.java => NotionImageTest.java} | 8 ++-- .../parser/notion/NotionParserTest.java | 18 ++++---- 17 files changed, 98 insertions(+), 85 deletions(-) rename backend/src/main/java/org/donggle/backend/domain/parser/notion/{BookmarkParser.java => NotionBookmark.java} (89%) rename backend/src/main/java/org/donggle/backend/domain/parser/notion/{CalloutParser.java => NotionCallout.java} (77%) rename backend/src/main/java/org/donggle/backend/domain/parser/notion/{CodeBlockParser.java => NotionCodeBlock.java} (76%) rename backend/src/main/java/org/donggle/backend/domain/parser/notion/{DefaultBlockParser.java => NotionDefaultBlock.java} (73%) create mode 100644 backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionDivider.java rename backend/src/main/java/org/donggle/backend/domain/parser/notion/{HeadingParser.java => NotionHeading.java} (74%) rename backend/src/main/java/org/donggle/backend/domain/parser/notion/{ImageParser.java => NotionImage.java} (77%) rename backend/src/main/java/org/donggle/backend/domain/parser/notion/{NotionNormalBlockParser.java => NotionNormalBlock.java} (81%) rename backend/src/main/java/org/donggle/backend/domain/parser/notion/{TodoParser.java => NotionTodo.java} (77%) rename backend/src/test/java/org/donggle/backend/domain/parser/notion/{BookmarkParserTest.java => NotionBookmarkParserTest.java} (83%) rename backend/src/test/java/org/donggle/backend/domain/parser/notion/{CalloutParserTest.java => NotionCalloutParserTest.java} (77%) rename backend/src/test/java/org/donggle/backend/domain/parser/notion/{CodeBlockParserTest.java => NotionCodeBlockTest.java} (76%) rename backend/src/test/java/org/donggle/backend/domain/parser/notion/{DefaultBlockParserTest.java => NotionDefaultBlockParserTest.java} (84%) rename backend/src/test/java/org/donggle/backend/domain/parser/notion/{HeadingParserTest.java => NotionHeadingParserTest.java} (83%) rename backend/src/test/java/org/donggle/backend/domain/parser/notion/{ImageParserTest.java => NotionImageTest.java} (75%) diff --git a/backend/src/main/java/org/donggle/backend/domain/parser/notion/BookmarkParser.java b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionBookmark.java similarity index 89% rename from backend/src/main/java/org/donggle/backend/domain/parser/notion/BookmarkParser.java rename to backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionBookmark.java index 73674983d..c418bd322 100644 --- a/backend/src/main/java/org/donggle/backend/domain/parser/notion/BookmarkParser.java +++ b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionBookmark.java @@ -1,19 +1,19 @@ package org.donggle.backend.domain.parser.notion; import com.fasterxml.jackson.databind.JsonNode; -import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import org.donggle.backend.domain.writing.Style; import org.donggle.backend.domain.writing.StyleRange; import org.donggle.backend.domain.writing.StyleType; +import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import java.util.List; -public record BookmarkParser(List caption, String url) implements NotionNormalBlockParser { - public static BookmarkParser from(final NotionBlockNodeResponse blockNode) { +public record NotionBookmark(List caption, String url) implements NotionNormalBlock { + public static NotionBookmark from(final NotionBlockNodeResponse blockNode) { final JsonNode blockProperties = blockNode.getBlockProperties(); final List caption = RichText.parseRichTexts(blockProperties, "caption"); final String url = blockProperties.get("url").asText(); - return new BookmarkParser(caption, url); + return new NotionBookmark(caption, url); } @Override diff --git a/backend/src/main/java/org/donggle/backend/domain/parser/notion/CalloutParser.java b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionCallout.java similarity index 77% rename from backend/src/main/java/org/donggle/backend/domain/parser/notion/CalloutParser.java rename to backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionCallout.java index d0c2e6c05..514814755 100644 --- a/backend/src/main/java/org/donggle/backend/domain/parser/notion/CalloutParser.java +++ b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionCallout.java @@ -1,13 +1,13 @@ package org.donggle.backend.domain.parser.notion; import com.fasterxml.jackson.databind.JsonNode; -import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import org.donggle.backend.domain.writing.Style; +import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import java.util.List; -public record CalloutParser(List richTexts, String icon) implements NotionNormalBlockParser { - public static NotionNormalBlockParser from(final NotionBlockNodeResponse blockNode) { +public record NotionCallout(List richTexts, String icon) implements NotionNormalBlock { + public static NotionNormalBlock from(final NotionBlockNodeResponse blockNode) { final JsonNode blockProperties = blockNode.getBlockProperties(); final List richTexts = RichText.parseRichTexts(blockProperties, "rich_text"); String icon = ""; @@ -15,7 +15,7 @@ public static NotionNormalBlockParser from(final NotionBlockNodeResponse blockNo icon = blockProperties.get("icon").get("emoji").asText(); } - return new CalloutParser(richTexts, icon); + return new NotionCallout(richTexts, icon); } @Override diff --git a/backend/src/main/java/org/donggle/backend/domain/parser/notion/CodeBlockParser.java b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionCodeBlock.java similarity index 76% rename from backend/src/main/java/org/donggle/backend/domain/parser/notion/CodeBlockParser.java rename to backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionCodeBlock.java index d463100f0..09bba68ef 100644 --- a/backend/src/main/java/org/donggle/backend/domain/parser/notion/CodeBlockParser.java +++ b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionCodeBlock.java @@ -5,12 +5,12 @@ import java.util.List; -public record CodeBlockParser(List richTexts, String language) { - public static CodeBlockParser from(final NotionBlockNodeResponse blockNode) { +public record NotionCodeBlock(List richTexts, String language) { + public static NotionCodeBlock from(final NotionBlockNodeResponse blockNode) { final JsonNode blockProperties = blockNode.getBlockProperties(); final List richTexts = RichText.parseRichTexts(blockProperties, "rich_text"); final String language = blockProperties.get("language").asText(); - return new CodeBlockParser(richTexts, language); + return new NotionCodeBlock(richTexts, language); } public String parseRawText() { diff --git a/backend/src/main/java/org/donggle/backend/domain/parser/notion/DefaultBlockParser.java b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionDefaultBlock.java similarity index 73% rename from backend/src/main/java/org/donggle/backend/domain/parser/notion/DefaultBlockParser.java rename to backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionDefaultBlock.java index bd26371e1..055b4baae 100644 --- a/backend/src/main/java/org/donggle/backend/domain/parser/notion/DefaultBlockParser.java +++ b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionDefaultBlock.java @@ -1,16 +1,16 @@ package org.donggle.backend.domain.parser.notion; import com.fasterxml.jackson.databind.JsonNode; -import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import org.donggle.backend.domain.writing.Style; +import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import java.util.List; -public record DefaultBlockParser(List richTexts) implements NotionNormalBlockParser { - public static NotionNormalBlockParser from(final NotionBlockNodeResponse blockNode) { +public record NotionDefaultBlock(List richTexts) implements NotionNormalBlock { + public static NotionNormalBlock from(final NotionBlockNodeResponse blockNode) { final JsonNode blockProperties = blockNode.getBlockProperties(); final List richTexts = RichText.parseRichTexts(blockProperties, "rich_text"); - return new DefaultBlockParser(richTexts); + return new NotionDefaultBlock(richTexts); } @Override diff --git a/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionDivider.java b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionDivider.java new file mode 100644 index 000000000..c5287f610 --- /dev/null +++ b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionDivider.java @@ -0,0 +1,13 @@ +package org.donggle.backend.domain.parser.notion; + +import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; + +public record NotionDivider() { + public static NotionDivider from(final NotionBlockNodeResponse blockNode) { + return new NotionDivider(); + } + + public String parseRawText() { + return "---"; + } +} diff --git a/backend/src/main/java/org/donggle/backend/domain/parser/notion/HeadingParser.java b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionHeading.java similarity index 74% rename from backend/src/main/java/org/donggle/backend/domain/parser/notion/HeadingParser.java rename to backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionHeading.java index ca7c4a6fe..0e57b69ce 100644 --- a/backend/src/main/java/org/donggle/backend/domain/parser/notion/HeadingParser.java +++ b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionHeading.java @@ -1,17 +1,17 @@ package org.donggle.backend.domain.parser.notion; import com.fasterxml.jackson.databind.JsonNode; -import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import org.donggle.backend.domain.writing.Style; +import org.donggle.backend.infrastructure.client.notion.dto.response.NotionBlockNodeResponse; import java.util.List; -public record HeadingParser(List richTexts, boolean isToggleable) implements NotionNormalBlockParser { - public static NotionNormalBlockParser from(final NotionBlockNodeResponse blockNode) { +public record NotionHeading(List richTexts, boolean isToggleable) implements NotionNormalBlock { + public static NotionNormalBlock from(final NotionBlockNodeResponse blockNode) { final JsonNode blockProperties = blockNode.getBlockProperties(); final List richTexts = RichText.parseRichTexts(blockProperties, "rich_text"); final boolean isToggleable = blockProperties.get("is_toggleable").asBoolean(); - return new HeadingParser(richTexts, isToggleable); + return new NotionHeading(richTexts, isToggleable); } @Override diff --git a/backend/src/main/java/org/donggle/backend/domain/parser/notion/ImageParser.java b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionImage.java similarity index 77% rename from backend/src/main/java/org/donggle/backend/domain/parser/notion/ImageParser.java rename to backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionImage.java index e07b222dc..d7cc5e5c5 100644 --- a/backend/src/main/java/org/donggle/backend/domain/parser/notion/ImageParser.java +++ b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionImage.java @@ -6,18 +6,18 @@ import java.util.List; import java.util.Objects; -public record ImageParser(List caption, String url) { +public record NotionImage(List caption, String url) { - public static ImageParser from(final NotionBlockNodeResponse blockNode) { + public static NotionImage from(final NotionBlockNodeResponse blockNode) { final JsonNode blockProperties = blockNode.getBlockProperties(); final List caption = RichText.parseRichTexts(blockProperties, "caption"); final String type = blockProperties.get("type").asText(); if (Objects.equals(type, "file")) { final String url = ""; - return new ImageParser(caption, url); + return new NotionImage(caption, url); } final String url = blockProperties.get("external").get("url").asText(); - return new ImageParser(caption, url); + return new NotionImage(caption, url); } public String parseCaption() { diff --git a/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionNormalBlockParser.java b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionNormalBlock.java similarity index 81% rename from backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionNormalBlockParser.java rename to backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionNormalBlock.java index 49d85e3f4..db500efb9 100644 --- a/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionNormalBlockParser.java +++ b/backend/src/main/java/org/donggle/backend/domain/parser/notion/NotionNormalBlock.java @@ -4,7 +4,7 @@ import java.util.List; -public interface NotionNormalBlockParser { +public interface NotionNormalBlock { String parseRawText(); List