Fetch Post
The getPost() function is used to fetch a post. It takes a GetPostRequest as input, which includes the postId, page, and pageSize. The function returns a GetPostResponse as a Future.
Steps to Get a Post
- Create an instance of
GetPostRequestwith the required parameters:postId,page, andpageSize. - Call the
getPost()function using the instance of theLMFeedClientclass, passing the request as a parameter. - Use the response as per your requirement.
// Create an instance of GetPostRequest
GetPostRequest request = (GetPostRequestBuilder()
..page(1)
..pageSize(10)
..postId("post_id"))
.build();
// Get the response from calling the function
final GetPostResponse getPostResponse = await lmFeedClient.getPost(getPostRequest);
// Process the response, as per requirement
if (getPostResponse.success) {
// your function to handle successful retrieval of the post
handleGetPostSuccess(getPostResponse.post, getPostResponse.users, getPostResponse.topics, getPostResponse.widgets, getPostResponse.repostedPosts);
} else {
// your function to handle error message
handleGetPostError(getPostResponse.errorMessage);
}
Models
GetPostRequest
List of parameters for the GetPostRequest class
| Variable | Type | Description | Optional |
|---|---|---|---|
| postId | String | Unique identifier of the post | |
| page | int | Page number for pagination | |
| pageSize | int | Number of items per page |
GetPostResponse
List of parameters for the GetPostResponse class
| Variable | Type | Description | Optional |
|---|---|---|---|
| success | bool | API success status | |
| errorMessage | String | Error message in case of failure | ✔ |
| post | Post | The fetched post entity | |
| users | Map<String, User> | Map of user UUIDs to User entities | |
| topics | Map<String, Topic> | Map of topic IDs to Topic entities | |
| widgets | Map<String, WidgetModel> | Map of widget IDs to WidgetModel entities | |
| repostedPosts | Map<String, Post> | Map of post IDs to reposted Post entities | |
| userTopics | Map<String, List<String>> | Map of user topics (key: user ID) | ✔ |