Skip to content

Commit 4faddea

Browse files
committed
feat: add pin and unpin
1 parent 10b7040 commit 4faddea

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
- 动态
4848
- [x] 获取用户动态
4949
- [x] 获取关注动态
50+
- [x] 置顶动态
51+
- [x] 取消置顶动态
5052
- 通知
5153
- [x] 获取通知列表
5254
- 上传

src/api/personal-update.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { request, toResponse } from '../request'
2+
import type { PostTypeRaw } from '../types/entity'
23
import type { PaginationOption } from '../types/options'
34
import type { PersonalUpdate } from '../types/api-responses'
45

@@ -42,3 +43,35 @@ export const followingUpdates = async <
4243
},
4344
})
4445
)
46+
47+
/**
48+
* 置顶动态
49+
*/
50+
export const pin = async <T = PersonalUpdate.PinResponse>(
51+
type: PostTypeRaw,
52+
id: string
53+
) =>
54+
toResponse<T>(
55+
request.post('1.0/personalUpdate/pin', {
56+
json: {
57+
id,
58+
type,
59+
},
60+
})
61+
)
62+
63+
/**
64+
* 取消置顶动态
65+
*/
66+
export const unpin = async <T = PersonalUpdate.UnpinResponse>(
67+
type: PostTypeRaw,
68+
id: string
69+
) =>
70+
toResponse<T>(
71+
request.post('1.0/personalUpdate/unpin', {
72+
json: {
73+
id,
74+
type,
75+
},
76+
})
77+
)

src/client/post.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ export class JikePost {
7373
return result.data.toast
7474
}
7575

76+
/**
77+
* 置顶动态
78+
* @returns 置顶提示文本
79+
*/
80+
async pin() {
81+
const result = await this.apiClient.personalUpdate.pin(
82+
enumTypeToRaw(this.type),
83+
this.id
84+
)
85+
if (!isSuccess(result)) throwRequestFailureError(result, '置顶动态')
86+
return result.data.toast
87+
}
88+
89+
/**
90+
* 取消置顶动态
91+
* @returns 取消置顶提示文本
92+
*/
93+
async unpin() {
94+
const result = await this.apiClient.personalUpdate.unpin(
95+
enumTypeToRaw(this.type),
96+
this.id
97+
)
98+
if (!isSuccess(result)) throwRequestFailureError(result, '取消置顶动态')
99+
return result.data.toast
100+
}
101+
76102
/**
77103
* 添加评论
78104
* @returns 评论信息

src/types/api-responses.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ export namespace PersonalUpdate {
139139

140140
export type FollowingUpdatesResponseMoreKey =
141141
FollowingUpdatesResponse['loadMoreKey']
142+
143+
export interface PinResponse {
144+
toast: LiteralUnion<'已置顶'>
145+
}
146+
147+
export interface UnpinResponse {
148+
toast: LiteralUnion<'已取消置顶'>
149+
}
142150
}
143151

144152
export namespace Comments {

0 commit comments

Comments
 (0)