ZCH-18 重构 Topic 对象用于处理返回和数据描述
This commit is contained in:
parent
b911e962d8
commit
ea9e13e304
|
@ -2,6 +2,7 @@ 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.common.model.dto.Topic;
|
||||
import com.ossez.discourse.client.DiscourseClient;
|
||||
import okhttp3.*;
|
||||
|
@ -42,6 +43,7 @@ public class TopicsService extends DiscourseClient {
|
|||
if (response.code() == HttpStatus.SC_OK) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
|
||||
discourseTopic = Optional.of(objectMapper.readValue(responseStr, Topic.class));
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ public class TopicServiceTest extends TestBase {
|
|||
Optional<Topic> topic = topicsService.getTopic(DISCOURSE_TOPIC_ID);
|
||||
assertThat(topic).isNotEmpty();
|
||||
|
||||
assertThat(topic.get().getPostStream().getPosts().size()).isGreaterThan(1);
|
||||
assertThat(topic.get().getPostStream().getPosts().get(0).getId()).isEqualTo(DISCOURSE_POST_ID);
|
||||
assertThat(topic.get().getId()).isEqualTo(DISCOURSE_TOPIC_ID);
|
||||
assertThat(topic.get().getTitle()).isNotEmpty();
|
||||
log.debug("{}", topic.get().getTitle());
|
||||
|
|
|
@ -2,8 +2,12 @@ package com.ossez.discourse.common.model.dto;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Topic {
|
||||
|
||||
private PostStream postStream;
|
||||
private List<List<Integer>> timelineLookup;
|
||||
@JsonProperty(value = "id", required = true)
|
||||
private Long id;
|
||||
@JsonProperty(required = true)
|
||||
|
@ -41,6 +45,22 @@ public class Topic {
|
|||
private String deletedBy;
|
||||
private Boolean hasDeleted;
|
||||
|
||||
public PostStream getPostStream() {
|
||||
return postStream;
|
||||
}
|
||||
|
||||
public void setPostStream(PostStream postStream) {
|
||||
this.postStream = postStream;
|
||||
}
|
||||
|
||||
public List<List<Integer>> getTimelineLookup() {
|
||||
return timelineLookup;
|
||||
}
|
||||
|
||||
public void setTimelineLookup(List<List<Integer>> timelineLookup) {
|
||||
this.timelineLookup = timelineLookup;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue