diff --git a/client/src/main/java/com/ossez/discourse/client/service/PostsService.java b/client/src/main/java/com/ossez/discourse/client/service/PostsService.java index be01d15..8eb6044 100644 --- a/client/src/main/java/com/ossez/discourse/client/service/PostsService.java +++ b/client/src/main/java/com/ossez/discourse/client/service/PostsService.java @@ -1,11 +1,9 @@ package com.ossez.discourse.client.service; import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.ossez.discourse.client.DiscourseClient; import com.ossez.discourse.common.model.dto.Post; -import com.ossez.discourse.common.model.dto.Topics; import okhttp3.OkHttpClient; import okhttp3.Response; import org.apache.http.HttpStatus; diff --git a/client/src/main/java/com/ossez/discourse/client/service/TopicsService.java b/client/src/main/java/com/ossez/discourse/client/service/TopicsService.java index 99e955a..0425440 100644 --- a/client/src/main/java/com/ossez/discourse/client/service/TopicsService.java +++ b/client/src/main/java/com/ossez/discourse/client/service/TopicsService.java @@ -2,7 +2,7 @@ package com.ossez.discourse.client.service; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.ossez.discourse.common.model.dto.Topics; +import com.ossez.discourse.common.model.dto.Topic; import com.ossez.discourse.client.DiscourseClient; import okhttp3.*; import org.apache.http.HttpStatus; @@ -30,10 +30,10 @@ public class TopicsService extends DiscourseClient { DiscourseClient.api_key = apiKey; } - public Optional getTopic(Long topicId) { + public Optional getTopic(Long topicId) { String path = "t/" + String.valueOf(topicId) + ".json"; - Optional discourseTopic = Optional.ofNullable(new Topics()); + Optional discourseTopic = Optional.ofNullable(new Topic()); try { Response response = client.newCall(getRequest(path)).execute(); @@ -42,7 +42,7 @@ public class TopicsService extends DiscourseClient { if (response.code() == HttpStatus.SC_OK) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - discourseTopic = Optional.of(objectMapper.readValue(responseStr, Topics.class)); + discourseTopic = Optional.of(objectMapper.readValue(responseStr, Topic.class)); } diff --git a/client/src/test/java/com/ossez/discourse/client/test/TestBase.java b/client/src/test/java/com/ossez/discourse/client/test/TestBase.java index 63c0ec3..f4da9d3 100644 --- a/client/src/test/java/com/ossez/discourse/client/test/TestBase.java +++ b/client/src/test/java/com/ossez/discourse/client/test/TestBase.java @@ -23,6 +23,8 @@ import java.util.Properties; public class TestBase { private static final Logger log = LoggerFactory.getLogger(TestBase.class); private static final String TEST_CONFIG_PROPERTIES= "test-config.properties"; + public static final Long DISCOURSE_POST_ID = 594L; + public static final Long DISCOURSE_TOPIC_ID = 570L; @BeforeAll public void setup() { diff --git a/client/src/test/java/com/ossez/discourse/client/test/TopicsServiceTest.java b/client/src/test/java/com/ossez/discourse/client/test/TopicServiceTest.java similarity index 61% rename from client/src/test/java/com/ossez/discourse/client/test/TopicsServiceTest.java rename to client/src/test/java/com/ossez/discourse/client/test/TopicServiceTest.java index 82304cd..dc554c8 100644 --- a/client/src/test/java/com/ossez/discourse/client/test/TopicsServiceTest.java +++ b/client/src/test/java/com/ossez/discourse/client/test/TopicServiceTest.java @@ -3,20 +3,25 @@ package com.ossez.discourse.client.test; import com.google.inject.Inject; import com.ossez.discourse.client.service.TopicsService; import com.ossez.discourse.common.exception.WxErrorException; +import com.ossez.discourse.common.model.dto.Topic; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for datacube API * * @author YuCheng */ @TestInstance(Lifecycle.PER_CLASS) -public class TopicsServiceTest extends TestBase { - private static final Logger log = LoggerFactory.getLogger(TopicsServiceTest.class); +public class TopicServiceTest extends TestBase { + private static final Logger log = LoggerFactory.getLogger(TopicServiceTest.class); @Inject protected TopicsService topicsService; @@ -28,7 +33,12 @@ public class TopicsServiceTest extends TestBase { @Test public void testCreate() throws WxErrorException { log.debug("Create WeChat Offical Account Menun Test"); - log.debug("{}", topicsService.getTopic(Long.valueOf("1245")).get().getTitle()); + Optional topic = topicsService.getTopic(DISCOURSE_TOPIC_ID); + assertThat(topic).isNotEmpty(); + + assertThat(topic.get().getId()).isEqualTo(DISCOURSE_TOPIC_ID); + assertThat(topic.get().getTitle()).isNotEmpty(); + log.debug("{}", topic.get().getTitle()); } diff --git a/client/src/test/resources/test-config.properties b/client/src/test/resources/test-config.properties index b1d0fc6..bb2311b 100644 --- a/client/src/test/resources/test-config.properties +++ b/client/src/test/resources/test-config.properties @@ -1,4 +1,4 @@ # --- APP --- api.site.url=https://www.zchub.net/ -api.username=****** -api.key=****** \ No newline at end of file +api.username=zchub +api.key=a6e6882164f606343bb0a9cde05992f27e73db2cf76c9347b885323a98f8afd3 \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml index b52139a..ac7ceee 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -17,6 +17,27 @@ Discourse Java Common The module is common for all other package + + + The MIT license + https://opensource.org/licenses/mit-license.php + repo + + + + + + ossez-repo + https://repo.ossez.com/repository/maven-releases/ + + + + ossez-repo + https://repo.ossez.com/repository/maven-snapshots/ + + + + org.jodd @@ -125,9 +146,13 @@ org.redisson redisson + + - org.springframework.data - spring-data-redis + org.assertj + assertj-core + 3.24.2 + test org.jetbrains diff --git a/common/src/main/java/com/ossez/discourse/common/model/dto/Topic.java b/common/src/main/java/com/ossez/discourse/common/model/dto/Topic.java new file mode 100644 index 0000000..67db215 --- /dev/null +++ b/common/src/main/java/com/ossez/discourse/common/model/dto/Topic.java @@ -0,0 +1,317 @@ +package com.ossez.discourse.common.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Topic { + + @JsonProperty(value = "id", required = true) + private Long id; + @JsonProperty(required = true) + private String title; + private String fancyTitle; + private Integer postsCount; + private String createdAt; + private Integer views; + private Integer replyCount; + private Integer likeCount; + private String lastPostedAt; + private Boolean visible; + private Boolean closed; + private Boolean archived; + private Boolean hasSummary; + private String archetype; + private String slug; + private Integer categoryId; + private Integer wordCount; + private String deletedAt; + private Long userId; + private String featuredLink; + private Boolean pinnedGlobally; + private String pinnedAt; + private String pinnedUntil; + private String imageUrl; + private Integer slowModeSeconds; + private String draft; + private String draftKey; + private Integer draftSequence; + private String unpinned; + private Boolean pinned; + private Integer currentPostNumber; + private Integer highestPostNumber; + private String deletedBy; + private Boolean hasDeleted; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getFancyTitle() { + return fancyTitle; + } + + public void setFancyTitle(String fancyTitle) { + this.fancyTitle = fancyTitle; + } + + public Integer getPostsCount() { + return postsCount; + } + + public void setPostsCount(Integer postsCount) { + this.postsCount = postsCount; + } + + public String getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + public Integer getViews() { + return views; + } + + public void setViews(Integer views) { + this.views = views; + } + + public Integer getReplyCount() { + return replyCount; + } + + public void setReplyCount(Integer replyCount) { + this.replyCount = replyCount; + } + + public Integer getLikeCount() { + return likeCount; + } + + public void setLikeCount(Integer likeCount) { + this.likeCount = likeCount; + } + + public String getLastPostedAt() { + return lastPostedAt; + } + + public void setLastPostedAt(String lastPostedAt) { + this.lastPostedAt = lastPostedAt; + } + + public Boolean getVisible() { + return visible; + } + + public void setVisible(Boolean visible) { + this.visible = visible; + } + + public Boolean getClosed() { + return closed; + } + + public void setClosed(Boolean closed) { + this.closed = closed; + } + + public Boolean getArchived() { + return archived; + } + + public void setArchived(Boolean archived) { + this.archived = archived; + } + + public Boolean getHasSummary() { + return hasSummary; + } + + public void setHasSummary(Boolean hasSummary) { + this.hasSummary = hasSummary; + } + + public String getArchetype() { + return archetype; + } + + public void setArchetype(String archetype) { + this.archetype = archetype; + } + + public String getSlug() { + return slug; + } + + public void setSlug(String slug) { + this.slug = slug; + } + + public Integer getCategoryId() { + return categoryId; + } + + public void setCategoryId(Integer categoryId) { + this.categoryId = categoryId; + } + + public Integer getWordCount() { + return wordCount; + } + + public void setWordCount(Integer wordCount) { + this.wordCount = wordCount; + } + + public String getDeletedAt() { + return deletedAt; + } + + public void setDeletedAt(String deletedAt) { + this.deletedAt = deletedAt; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getFeaturedLink() { + return featuredLink; + } + + public void setFeaturedLink(String featuredLink) { + this.featuredLink = featuredLink; + } + + public Boolean getPinnedGlobally() { + return pinnedGlobally; + } + + public void setPinnedGlobally(Boolean pinnedGlobally) { + this.pinnedGlobally = pinnedGlobally; + } + + public String getPinnedAt() { + return pinnedAt; + } + + public void setPinnedAt(String pinnedAt) { + this.pinnedAt = pinnedAt; + } + + public String getPinnedUntil() { + return pinnedUntil; + } + + public void setPinnedUntil(String pinnedUntil) { + this.pinnedUntil = pinnedUntil; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public Integer getSlowModeSeconds() { + return slowModeSeconds; + } + + public void setSlowModeSeconds(Integer slowModeSeconds) { + this.slowModeSeconds = slowModeSeconds; + } + + public String getDraft() { + return draft; + } + + public void setDraft(String draft) { + this.draft = draft; + } + + public String getDraftKey() { + return draftKey; + } + + public void setDraftKey(String draftKey) { + this.draftKey = draftKey; + } + + public Integer getDraftSequence() { + return draftSequence; + } + + public void setDraftSequence(Integer draftSequence) { + this.draftSequence = draftSequence; + } + + public String getUnpinned() { + return unpinned; + } + + public void setUnpinned(String unpinned) { + this.unpinned = unpinned; + } + + public Boolean getPinned() { + return pinned; + } + + public void setPinned(Boolean pinned) { + this.pinned = pinned; + } + + public Integer getCurrentPostNumber() { + return currentPostNumber; + } + + public void setCurrentPostNumber(Integer currentPostNumber) { + this.currentPostNumber = currentPostNumber; + } + + public Integer getHighestPostNumber() { + return highestPostNumber; + } + + public void setHighestPostNumber(Integer highestPostNumber) { + this.highestPostNumber = highestPostNumber; + } + + public String getDeletedBy() { + return deletedBy; + } + + public void setDeletedBy(String deletedBy) { + this.deletedBy = deletedBy; + } + + public Boolean getHasDeleted() { + return hasDeleted; + } + + public void setHasDeleted(Boolean hasDeleted) { + this.hasDeleted = hasDeleted; + } +} + + diff --git a/common/src/main/java/com/ossez/discourse/common/model/dto/Topics.java b/common/src/main/java/com/ossez/discourse/common/model/dto/Topics.java deleted file mode 100644 index 849c623..0000000 --- a/common/src/main/java/com/ossez/discourse/common/model/dto/Topics.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.ossez.discourse.common.model.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.experimental.Accessors; - -import java.util.List; - -public class Topics { - - @JsonProperty(value = "id", required = true) - private Long topicId; - - @JsonProperty(required = true) - private String postId; - - @JsonProperty(required = true) - private String title; - - @JsonProperty(required = true) - private String raw; - - @JsonProperty(value = "category_id", required = true) - private Integer category; - - @JsonProperty(value = "image_url") - private String imageUrl; - - @JsonProperty(value = "word_count") - private Integer wordCount; - - @JsonProperty(value = "tags") - private List tags; - - public Long getTopicId() { - return topicId; - } - - public void setTopicId(Long topicId) { - this.topicId = topicId; - } - - public String getPostId() { - return postId; - } - - public void setPostId(String postId) { - this.postId = postId; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getRaw() { - return raw; - } - - public void setRaw(String raw) { - this.raw = raw; - } - - public Integer getCategory() { - return category; - } - - public void setCategory(Integer category) { - this.category = category; - } - - public String getImageUrl() { - return imageUrl; - } - - public void setImageUrl(String imageUrl) { - this.imageUrl = imageUrl; - } - - public Integer getWordCount() { - return wordCount; - } - - public void setWordCount(Integer wordCount) { - this.wordCount = wordCount; - } - - public List getTags() { - return tags; - } - - public void setTags(List tags) { - this.tags = tags; - } -} - -