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 11import { request , toResponse } from '../request'
2+ import type { LiteralUnion } from '../utils'
23import type { Topics } from '../types/api-responses'
34import type { PaginationOption } from '../types/options'
45
@@ -40,3 +41,29 @@ export const getTabsSelectedFeed = <T = Topics.GetTabsSelectedFeedResponse>(
4041 } ,
4142 } )
4243 )
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 {
1212 SquareFeed ,
1313 Story ,
1414 TabIcons ,
15+ Topic ,
1516 User ,
1617} from './entity'
1718
@@ -228,4 +229,18 @@ export namespace Topics {
228229 offset : number
229230 }
230231 }
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+ }
231246}
Original file line number Diff line number Diff line change @@ -19,4 +19,10 @@ describe('topics should work', () => {
1919 expect ( isSuccess ( result ) ) . toBe ( true )
2020 expect ( result . data . data . length ) . toBe ( limit )
2121 } )
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+ } )
2228} )
You can’t perform that action at this time.
0 commit comments