This repository was archived by the owner on May 29, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathnotes.ts
More file actions
85 lines (71 loc) · 2.31 KB
/
Copy pathnotes.ts
File metadata and controls
85 lines (71 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { PaginateResult } from '~/models/base'
import type { NoteModel } from '~/models/note'
import { request } from '~/utils/request'
export type NoteSortKey =
| 'title'
| 'createdAt'
| 'modifiedAt'
| 'weather'
| 'mood'
export type SortOrder = 'asc' | 'desc'
export interface GetNotesParams {
page?: number
size?: number
sort_by?: NoteSortKey
sort_order?: SortOrder
/**
* @deprecated backend dropped db_query in v12.10.x pager refactor; param is silently ignored
*/
db_query?: Record<string, boolean>
}
export interface CreateNoteData {
title: string
text: string
slug?: string
mood?: string
weather?: string
password?: string | null
publicAt?: Date | null
bookmark?: boolean
location?: string | null
coordinates?: { longitude: number; latitude: number } | null
topicId?: string | null
isPublished?: boolean
meta?: Record<string, unknown>
/** 关联的草稿 ID,发布时传递以标记草稿为已发布 */
draftId?: string
}
export interface UpdateNoteData extends Partial<CreateNoteData> {}
// 用于 patch 操作的数据类型,允许将某些字段设为 null
export interface PatchNoteData {
topicId?: string | null
slug?: string | null
[key: string]: unknown
}
export const notesApi = {
// 获取日记列表
getList: (params?: GetNotesParams) =>
request.get<PaginateResult<NoteModel>>('/notes', { params }),
// 获取单篇日记
getById: (id: string, params?: { single?: boolean }) =>
request.get<NoteModel>(`/notes/${id}`, { params }),
// 创建日记
create: (data: CreateNoteData) => request.post<NoteModel>('/notes', { data }),
// 更新日记
update: (id: string, data: UpdateNoteData) =>
request.put<NoteModel>(`/notes/${id}`, { data }),
// 删除日记
delete: (id: string) => request.delete<void>(`/notes/${id}`),
// 更新部分字段
patch: (id: string, data: PatchNoteData) =>
request.patch<NoteModel>(`/notes/${id}`, { data }),
// 更新发布状态
patchPublish: (id: string, isPublished: boolean) =>
request.patch<NoteModel>(`/notes/${id}/publish`, { data: { isPublished } }),
// 获取专栏下的日记列表
getByTopic: (topicId: string, params?: { page?: number; size?: number }) =>
request.get<PaginateResult<Partial<NoteModel>>>(
`/notes/topics/${topicId}`,
{ params },
),
}