File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { request , toResponse } from '../request'
2
+ import type { LiteralUnion } from '../utils'
2
3
import type { Topics } from '../types/api-responses'
3
4
import type { PaginationOption } from '../types/options'
4
5
@@ -40,3 +41,29 @@ export const getTabsSelectedFeed = <T = Topics.GetTabsSelectedFeedResponse>(
40
41
} ,
41
42
} )
42
43
)
44
+
45
+ /**
46
+ * 搜索圈子
47
+ * @param keywords 关键词
48
+ * @param option 选项
49
+ */
50
+ export const search = < T = Topics . SearchResponse > (
51
+ keywords : string ,
52
+ option : PaginationOption < { skip : number } > & {
53
+ /** 类型 */
54
+ type ?: LiteralUnion < 'ALL' >
55
+ /** 仅用户发帖时为 true */
56
+ onlyUserPostEnabled ?: boolean
57
+ } = { }
58
+ ) =>
59
+ toResponse < T > (
60
+ request . post ( '1.0/users/topics/search' , {
61
+ json : {
62
+ type : option . type ?? 'ALL' ,
63
+ keywords,
64
+ onlyUserPostEnabled : option . onlyUserPostEnabled ,
65
+ limit : option . limit ?? 20 ,
66
+ loadMoreKey : option . loadMoreKey ,
67
+ } ,
68
+ } )
69
+ )
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import type {
12
12
SquareFeed ,
13
13
Story ,
14
14
TabIcons ,
15
+ Topic ,
15
16
User ,
16
17
} from './entity'
17
18
@@ -228,4 +229,18 @@ export namespace Topics {
228
229
offset : number
229
230
}
230
231
}
232
+
233
+ // 搜索圈子
234
+ export interface SearchResponse {
235
+ data : Topic [ ]
236
+ count : number
237
+ loadMoreKey ?: {
238
+ skip : number
239
+ }
240
+ highlightWord : {
241
+ words : string [ ]
242
+ singleMaxHighlightTime : number
243
+ totalMaxHighlightTime : number
244
+ }
245
+ }
231
246
}
Original file line number Diff line number Diff line change @@ -19,4 +19,10 @@ describe('topics should work', () => {
19
19
expect ( isSuccess ( result ) ) . toBe ( true )
20
20
expect ( result . data . data . length ) . toBe ( limit )
21
21
} )
22
+
23
+ it ( 'search should work' , async ( ) => {
24
+ const result = await api . topics . search ( '好' , { limit } )
25
+ expect ( isSuccess ( result ) ) . toBe ( true )
26
+ expect ( result . data . data . length ) . toBe ( limit )
27
+ } )
22
28
} )
You can’t perform that action at this time.
0 commit comments