Skip to content

Commit 7883ab6

Browse files
committed
feat: getting resady to deploy
1 parent daece75 commit 7883ab6

File tree

6 files changed

+63
-540
lines changed

6 files changed

+63
-540
lines changed

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_URL=http://localhost:8080/

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function Home() {
1717
</h1>
1818

1919
<div className='bg-white rounded-xl shadow-lg p-6 '>
20-
<StatementWizard onComplete={() => {}} username={USERNAME} />
20+
<StatementWizard username={USERNAME} />
2121
<StatementBuilder username={USERNAME} />
2222
<StatementList username={USERNAME} />
2323
</div>

src/api/statementsApi.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const API_URL = import.meta.env.VITE_API_URL;
2+
console.log('Backend API:', API_URL);
3+
4+
import type { Statement } from '../../types/types';
5+
6+
export async function postNewStatement(statement: Statement): Promise<void> {
7+
try {
8+
// POST operation
9+
const postResponse = await fetch(`${API_URL}newEntry`, {
10+
method: 'POST',
11+
headers: {
12+
'Content-Type': 'application/json',
13+
},
14+
body: JSON.stringify(statement),
15+
});
16+
if (!postResponse.ok) {
17+
throw new Error(`HTTP error on POST! status: ${postResponse.status}`);
18+
}
19+
const postData = await postResponse.json();
20+
console.log('Successfully posted:', postData);
21+
22+
// Optionally, if you want to fetch updated data after posting:
23+
const getResponse = await fetch(`${API_URL}n/s/${statement.subject}`);
24+
if (!getResponse.ok) {
25+
throw new Error(`HTTP error on GET! status: ${getResponse.status}`);
26+
}
27+
const getData = await getResponse.json();
28+
console.log(`Fetched updated data: ${JSON.stringify(getData, null, 2)}`);
29+
} catch (error) {
30+
console.error('Error posting new statement:', error);
31+
}
32+
}

0 commit comments

Comments
 (0)