Skip to content

Commit 48fbf4f

Browse files
committed
refactor(app): new way for HTTP requests of bounty detail
1 parent ec0d096 commit 48fbf4f

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/app/bounties/[id]/actions.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@
1818

1919
import { revalidatePath } from 'next/cache';
2020

21-
import { post } from '@/utils/request';
21+
import { applyOne } from '#/domain/bounty/repository';
2222

2323
export async function applyAction(id, comment) {
2424
try {
25-
const res = await post(`ts/v1/build/general/bounties/${id}/builders`, { comment }, { isServer: true });
26-
if (res.code === 200) {
27-
return revalidatePath('/');
28-
} else {
29-
return res;
30-
}
25+
const res = await applyOne(id, { comment });
26+
return res.success ? revalidatePath('/') : res;
3127
} catch (e) {
3228
return { message: 'Failed to request' };
3329
}

src/app/bounties/[id]/page.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { Suspense } from 'react';
1818

1919
import { PreviewAlert } from '@/components/PreviewAlert';
2020
import { fromNow } from '@/utils/date';
21-
import { get } from '@/utils/request';
21+
22+
import { fetchOne } from '#/domain/bounty/repository';
2223

2324
import { ChainNetworkTips } from '../Tips';
2425
import { Activities } from './Activities';
@@ -27,11 +28,7 @@ import { Employers } from './Employers';
2728
import { BountiesHeader } from './Header';
2829

2930
export default async function Page({ params, searchParams }) {
30-
const datas = await Promise.all([
31-
get(`ts/v1/build/general/bounties/${params.id}`, {isServer: true}),
32-
// get(`ts/v1/build/general/bounties/${params.id}/builders`, {isServer: true})
33-
]);
34-
const [{ data }] = [...datas];
31+
const { data } = await fetchOne(params.id);
3532

3633
return (
3734
<>

src/domain/bounty/repository.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ async function fetchList(params = {}) {
3939
});
4040
}
4141

42+
async function fetchOne(id) {
43+
return httpClient.get(`/build/general/bounties/${id}`);
44+
}
45+
46+
async function applyOne(id, data) {
47+
return httpClient.post(`/build/general/bounties/${id}/builders`, data);
48+
}
49+
4250
async function fetchPublishedBountyList(params = {}) {
4351
const { userId, ...others } = params;
4452

@@ -53,4 +61,7 @@ async function fetchAppliedBountyList(params = {}) {
5361
});
5462
}
5563

56-
export { fetchList, fetchPublishedBountyList, fetchAppliedBountyList };
64+
export {
65+
fetchList, fetchOne, applyOne,
66+
fetchPublishedBountyList, fetchAppliedBountyList,
67+
};

0 commit comments

Comments
 (0)