Skip to content

Commit 84a91f4

Browse files
yes1amjpsong
andauthored
feat: add topic (#83)
* feat(api): 新增 topic api * 新增 getTabsSquareFeed, getTabsSelectedFeed * 更新 README.md, 新增 Development.md 便于新人参与开发 * style(Development.md): lint:fix * fix: fix type & file change rollback * style: add newline at end of file Co-authored-by: jpsong <[email protected]>
1 parent 010305c commit 84a91f4

File tree

8 files changed

+109
-2
lines changed

8 files changed

+109
-2
lines changed

src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as comments from './comments'
88
import * as upload from './upload'
99
import * as stories from './stories'
1010
import * as mediaMeta from './media-meta'
11+
import * as topic from './topic'
1112

1213
/**
1314
* API
@@ -20,6 +21,7 @@ import * as mediaMeta from './media-meta'
2021
* - {@link api/comments | `comments`}: 评论
2122
* - {@link api/upload | `upload`}: 上传
2223
* - {@link api/stories | `stories`}: 日记
24+
* - {@link api/topic | `topic`}: 圈子
2325
*/
2426
export const api = {
2527
users,
@@ -32,6 +34,7 @@ export const api = {
3234
upload,
3335
stories,
3436
mediaMeta,
37+
topic,
3538
}
3639
/**
3740
* API 集合

src/api/topic.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { request, toResponse } from '../request'
2+
import type { Topic } from '../types/api-responses'
3+
import type { PaginationOption } from '../types/options'
4+
5+
/**
6+
* 获取圈子动态
7+
* @param topicId 圈子 id
8+
* @param option 选项
9+
*/
10+
export const getTabsSquareFeed = <T = Topic.GetTabsSquareFeedResponse>(
11+
topicId: string,
12+
// NOTE: suppressed 应该传 false,但不知道这个参数是什么意思
13+
option: PaginationOption<{ lastId: string; suppressed: boolean }> = {}
14+
) =>
15+
toResponse<T>(
16+
request.post('1.0/topics/tabs/square/feed', {
17+
json: {
18+
topicId,
19+
limit: option.limit ?? 10,
20+
loadMoreKey: option.loadMoreKey,
21+
},
22+
})
23+
)
24+
25+
/**
26+
* 获取圈子热门动态
27+
* @param topicId 圈子 id
28+
* @param option 选项
29+
*/
30+
export const getTabsSelectedFeed = <T = Topic.GetTabsSelectedFeedResponse>(
31+
topicId: string,
32+
option: PaginationOption<{ offset: number }> = {}
33+
) =>
34+
toResponse<T>(
35+
request.post('1.0/topics/tabs/selected/feed', {
36+
json: {
37+
topicId,
38+
limit: option.limit ?? 10,
39+
loadMoreKey: option.loadMoreKey,
40+
},
41+
})
42+
)

src/types/api-responses.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
PersonalPost,
1010
Profile as ProfileEntity,
1111
RecommendPost,
12+
SquareFeed,
1213
Story,
1314
TabIcons,
1415
User,
@@ -209,3 +210,22 @@ export namespace Stories {
209210
export interface InteractiveResponse {
210211
url: string
211212
}
213+
214+
export namespace Topic {
215+
// 圈子动态
216+
export interface GetTabsSquareFeedResponse {
217+
data: SquareFeed[]
218+
loadMoreKey?: {
219+
lastId: string
220+
suppressed: boolean
221+
}
222+
}
223+
224+
// 圈子热门动态
225+
export interface GetTabsSelectedFeedResponse {
226+
data: SquareFeed[]
227+
loadMoreKey?: {
228+
offset: number
229+
}
230+
}
231+
}

src/types/entity/common.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ export interface CommonImage {
99
format: LiteralUnion<'jpeg' | 'heic' | 'png'>
1010
}
1111

12+
// 地图 POI
13+
export interface Poi {
14+
poiId: string // id
15+
name: string
16+
location: number[] // 经纬度
17+
countryname: string // 国家
18+
pname: string // 省份
19+
cityname: string // 城市
20+
formattedAddress: string
21+
}
22+
1223
export type Ref =
1324
| ''
1425
| 'FOLLOWINGS_FEED_FOLLOW_SECTION'

src/types/entity/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './profile'
66
export * from './topic'
77
export * from './user'
88
export * from './story'
9+
export * from './topic'

src/types/entity/topic.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LiteralUnion } from '../../utils'
2-
import type { CommonImage, Ref } from './common'
2+
import type { CommonImage, Poi, Ref } from './common'
3+
import type { OriginalPost } from './post'
34

45
export interface Topic {
56
type: 'TOPIC'
@@ -76,3 +77,9 @@ export interface SquarePicture extends CommonImage {
7677
livePhoto: any
7778
themes: any
7879
}
80+
81+
export interface SquareFeed extends OriginalPost {
82+
poi?: Poi
83+
isSuppressed: boolean
84+
subtitle: string
85+
}

tests/api/topic.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { api, isSuccess, setApiConfig } from '../../src'
3+
import { config } from '../config'
4+
5+
describe('topic should work', () => {
6+
setApiConfig(config)
7+
8+
const topicId = '562dfeb0daf87d13002cad92' // 深圳吃喝玩乐圈子
9+
const limit = 10
10+
11+
it('getTabsSquareFeed should work', async () => {
12+
const result = await api.topic.getTabsSquareFeed(topicId, { limit })
13+
expect(isSuccess(result)).toBe(true)
14+
expect(result.data.data.length).toBe(limit)
15+
})
16+
17+
it('getTabsSelectedFeed should work', async () => {
18+
const result = await api.topic.getTabsSelectedFeed(topicId, { limit })
19+
expect(isSuccess(result)).toBe(true)
20+
expect(result.data.data.length).toBe(limit)
21+
})
22+
})

typedoc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"src/api/comments.ts",
1111
"src/api/upload.ts",
1212
"src/api/stories.ts",
13-
"src/api/media-meta.ts"
13+
"src/api/media-meta.ts",
14+
"src/api/topic.ts"
1415
],
1516
"out": "docs",
1617
"name": "Ⓙ Jike SDK",

0 commit comments

Comments
 (0)