mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
refactor: migrate memo to apiv1 (#1907)
* refactor: migrate memo to apiv1 * chore: update * chore: update * chore: update * chore: upate * chore: update * chore: update
This commit is contained in:
@@ -11,7 +11,7 @@ const MyAccountSection = () => {
|
||||
const { t } = useTranslation();
|
||||
const userStore = useUserStore();
|
||||
const user = userStore.state.user as User;
|
||||
const openAPIRoute = `${window.location.origin}/api/memo?openId=${user.openId}`;
|
||||
const openAPIRoute = `${window.location.origin}/api/v1/memo?openId=${user.openId}`;
|
||||
|
||||
const handleResetOpenIdBtnClick = async () => {
|
||||
showCommonDialog({
|
||||
|
@@ -52,7 +52,7 @@ const ShareMemoDialog: React.FC<Props> = (props: Props) => {
|
||||
|
||||
useEffect(() => {
|
||||
getMemoStats(user.id)
|
||||
.then(({ data: { data } }) => {
|
||||
.then(({ data }) => {
|
||||
setPartialState({
|
||||
memoAmount: data.length,
|
||||
});
|
||||
|
@@ -57,7 +57,7 @@ const UsageHeatMap = () => {
|
||||
|
||||
useEffect(() => {
|
||||
getMemoStats(currentUserId)
|
||||
.then(({ data: { data } }) => {
|
||||
.then(({ data }) => {
|
||||
setMemoAmount(data.length);
|
||||
const newStat: DailyUsageStat[] = getInitialUsageStat(usedDaysAmount, beginDayTimestamp);
|
||||
for (const record of data) {
|
||||
|
@@ -26,7 +26,7 @@ const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) => {
|
||||
}, [datestamp]);
|
||||
|
||||
useEffect(() => {
|
||||
getMemoStats(currentUserId).then(({ data: { data } }) => {
|
||||
getMemoStats(currentUserId).then(({ data }) => {
|
||||
const m = new Map();
|
||||
for (const record of data) {
|
||||
const date = getDateStampByDate(record * 1000);
|
||||
|
@@ -1,11 +1,5 @@
|
||||
import axios from "axios";
|
||||
|
||||
type ResponseObject<T> = {
|
||||
data: T;
|
||||
error?: string;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export function getSystemStatus() {
|
||||
return axios.get<SystemStatus>("/api/v1/status");
|
||||
}
|
||||
@@ -85,7 +79,7 @@ export function getAllMemos(memoFind?: MemoFind) {
|
||||
queryList.push(`limit=${memoFind.limit}`);
|
||||
}
|
||||
|
||||
return axios.get<ResponseObject<Memo[]>>(`/api/memo/all?${queryList.join("&")}`);
|
||||
return axios.get<Memo[]>(`/api/v1/memo/all?${queryList.join("&")}`);
|
||||
}
|
||||
|
||||
export function getMemoList(memoFind?: MemoFind) {
|
||||
@@ -105,39 +99,39 @@ export function getMemoList(memoFind?: MemoFind) {
|
||||
if (memoFind?.limit) {
|
||||
queryList.push(`limit=${memoFind.limit}`);
|
||||
}
|
||||
return axios.get<ResponseObject<Memo[]>>(`/api/memo?${queryList.join("&")}`);
|
||||
return axios.get<Memo[]>(`/api/v1/memo?${queryList.join("&")}`);
|
||||
}
|
||||
|
||||
export function getMemoStats(userId: UserId) {
|
||||
return axios.get<ResponseObject<number[]>>(`/api/memo/stats?creatorId=${userId}`);
|
||||
return axios.get<number[]>(`/api/v1/memo/stats?creatorId=${userId}`);
|
||||
}
|
||||
|
||||
export function getMemoById(id: MemoId) {
|
||||
return axios.get<ResponseObject<Memo>>(`/api/memo/${id}`);
|
||||
return axios.get<Memo>(`/api/v1/memo/${id}`);
|
||||
}
|
||||
|
||||
export function createMemo(memoCreate: MemoCreate) {
|
||||
return axios.post<ResponseObject<Memo>>("/api/memo", memoCreate);
|
||||
return axios.post<Memo>("/api/v1/memo", memoCreate);
|
||||
}
|
||||
|
||||
export function patchMemo(memoPatch: MemoPatch) {
|
||||
return axios.patch<ResponseObject<Memo>>(`/api/memo/${memoPatch.id}`, memoPatch);
|
||||
return axios.patch<Memo>(`/api/v1/memo/${memoPatch.id}`, memoPatch);
|
||||
}
|
||||
|
||||
export function pinMemo(memoId: MemoId) {
|
||||
return axios.post(`/api/memo/${memoId}/organizer`, {
|
||||
return axios.post(`/api/v1/memo/${memoId}/organizer`, {
|
||||
pinned: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function unpinMemo(memoId: MemoId) {
|
||||
return axios.post(`/api/memo/${memoId}/organizer`, {
|
||||
return axios.post(`/api/v1/memo/${memoId}/organizer`, {
|
||||
pinned: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteMemo(memoId: MemoId) {
|
||||
return axios.delete(`/api/memo/${memoId}`);
|
||||
return axios.delete(`/api/v1/memo/${memoId}`);
|
||||
}
|
||||
|
||||
export function getShortcutList(shortcutFind?: ShortcutFind) {
|
||||
@@ -192,17 +186,17 @@ export function deleteResourceById(id: ResourceId) {
|
||||
}
|
||||
|
||||
export function getMemoResourceList(memoId: MemoId) {
|
||||
return axios.get<ResponseObject<Resource[]>>(`/api/memo/${memoId}/resource`);
|
||||
return axios.get<Resource[]>(`/api/v1/memo/${memoId}/resource`);
|
||||
}
|
||||
|
||||
export function upsertMemoResource(memoId: MemoId, resourceId: ResourceId) {
|
||||
return axios.post(`/api/memo/${memoId}/resource`, {
|
||||
return axios.post(`/api/v1/memo/${memoId}/resource`, {
|
||||
resourceId,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteMemoResource(memoId: MemoId, resourceId: ResourceId) {
|
||||
return axios.delete(`/api/memo/${memoId}/resource/${resourceId}`);
|
||||
return axios.delete(`/api/v1/memo/${memoId}/resource/${resourceId}`);
|
||||
}
|
||||
|
||||
export function getTagList(tagFind?: TagFind) {
|
||||
|
@@ -21,7 +21,7 @@ export const useMemoStore = () => {
|
||||
const memoCacheStore = useMemoCacheStore();
|
||||
|
||||
const fetchMemoById = async (memoId: MemoId) => {
|
||||
const { data } = (await api.getMemoById(memoId)).data;
|
||||
const { data } = await api.getMemoById(memoId);
|
||||
const memo = convertResponseModelMemo(data);
|
||||
|
||||
return memo;
|
||||
@@ -42,7 +42,7 @@ export const useMemoStore = () => {
|
||||
if (userStore.isVisitorMode()) {
|
||||
memoFind.creatorId = userStore.getUserIdFromPath();
|
||||
}
|
||||
const { data } = (await api.getMemoList(memoFind)).data;
|
||||
const { data } = await api.getMemoList(memoFind);
|
||||
const fetchedMemos = data.map((m) => convertResponseModelMemo(m));
|
||||
store.dispatch(upsertMemos(fetchedMemos));
|
||||
store.dispatch(setIsFetching(false));
|
||||
@@ -60,7 +60,7 @@ export const useMemoStore = () => {
|
||||
offset,
|
||||
};
|
||||
|
||||
const { data } = (await api.getAllMemos(memoFind)).data;
|
||||
const { data } = await api.getAllMemos(memoFind);
|
||||
const fetchedMemos = data.map((m) => convertResponseModelMemo(m));
|
||||
|
||||
for (const m of fetchedMemos) {
|
||||
@@ -76,7 +76,7 @@ export const useMemoStore = () => {
|
||||
if (userStore.isVisitorMode()) {
|
||||
memoFind.creatorId = userStore.getUserIdFromPath();
|
||||
}
|
||||
const { data } = (await api.getMemoList(memoFind)).data;
|
||||
const { data } = await api.getMemoList(memoFind);
|
||||
const archivedMemos = data.map((m) => {
|
||||
return convertResponseModelMemo(m);
|
||||
});
|
||||
@@ -97,14 +97,14 @@ export const useMemoStore = () => {
|
||||
return state.memos.filter((m) => m.content.match(regex));
|
||||
},
|
||||
createMemo: async (memoCreate: MemoCreate) => {
|
||||
const { data } = (await api.createMemo(memoCreate)).data;
|
||||
const { data } = await api.createMemo(memoCreate);
|
||||
const memo = convertResponseModelMemo(data);
|
||||
store.dispatch(createMemo(memo));
|
||||
memoCacheStore.setMemoCache(memo);
|
||||
return memo;
|
||||
},
|
||||
patchMemo: async (memoPatch: MemoPatch): Promise<Memo> => {
|
||||
const { data } = (await api.patchMemo(memoPatch)).data;
|
||||
const { data } = await api.patchMemo(memoPatch);
|
||||
const memo = convertResponseModelMemo(data);
|
||||
store.dispatch(patchMemo(omit(memo, "pinned")));
|
||||
memoCacheStore.setMemoCache(memo);
|
||||
|
@@ -12,7 +12,7 @@ export const useMemoCacheStore = create(
|
||||
return memo;
|
||||
}
|
||||
|
||||
const { data } = (await api.getMemoById(memoId)).data;
|
||||
const { data } = await api.getMemoById(memoId);
|
||||
const formatedMemo = convertResponseModelMemo(data);
|
||||
|
||||
set((state) => {
|
||||
|
Reference in New Issue
Block a user