ZCH-17 重新定义 Topic 对象,首先需要返回查询的结果
This commit is contained in:
parent
87e4e5e2f4
commit
cfecd98174
|
@ -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;
|
||||
|
|
|
@ -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<Topics> getTopic(Long topicId) {
|
||||
public Optional<Topic> getTopic(Long topicId) {
|
||||
String path = "t/" + String.valueOf(topicId) + ".json";
|
||||
|
||||
Optional<Topics> discourseTopic = Optional.ofNullable(new Topics());
|
||||
Optional<Topic> 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));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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> 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());
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
# --- APP ---
|
||||
api.site.url=https://www.zchub.net/
|
||||
api.username=******
|
||||
api.key=******
|
||||
api.username=zchub
|
||||
api.key=a6e6882164f606343bb0a9cde05992f27e73db2cf76c9347b885323a98f8afd3
|
|
@ -17,6 +17,27 @@
|
|||
<name>Discourse Java Common</name>
|
||||
<description>The module is common for all other package</description>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The MIT license</name>
|
||||
<url>https://opensource.org/licenses/mit-license.php</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>ossez-repo</id>
|
||||
<url>https://repo.ossez.com/repository/maven-releases/</url>
|
||||
</repository>
|
||||
|
||||
<snapshotRepository>
|
||||
<id>ossez-repo</id>
|
||||
<url>https://repo.ossez.com/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jodd</groupId>
|
||||
|
@ -125,9 +146,13 @@
|
|||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- TESTS -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.24.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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<String> 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<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue