aboutsummaryrefslogtreecommitdiff
path: root/fe/src/lib/forms
diff options
context:
space:
mode:
authorZach Berwaldt <zberwaldt@tutamail.com>2024-03-06 21:53:07 -0500
committerZach Berwaldt <zberwaldt@tutamail.com>2024-03-06 21:53:07 -0500
commit5fa57845052655883120ba4d19a85d8756fb8d8c (patch)
treed2d5ad1dd3fd8d9acaca9ced09612b50218f06b0 /fe/src/lib/forms
parentcf2113e77edabf8e3a632c7b76c769752039ba88 (diff)
[FEAT] Refactor API main file and models
This commit refactors the `main.go` file in the API directory, as well as the related models in the `models.go` file. The changes include: - Reordering imports and removing unnecessary imports - Fixing error messages to be more descriptive - Handling database connections more efficiently with deferred closures - Handling errors and returning appropriate error responses - Adding proper JSON bindings for POST requests - Adding new views in the database scripts for aggregated statistics and daily user statistics No changes were made to imports and requires.
Diffstat (limited to 'fe/src/lib/forms')
-rw-r--r--fe/src/lib/forms/AddForm.svelte13
1 files changed, 8 insertions, 5 deletions
diff --git a/fe/src/lib/forms/AddForm.svelte b/fe/src/lib/forms/AddForm.svelte
index f22e5f4..4520b1b 100644
--- a/fe/src/lib/forms/AddForm.svelte
+++ b/fe/src/lib/forms/AddForm.svelte
@@ -34,20 +34,23 @@
34 dispatch("close"); 34 dispatch("close");
35 } 35 }
36 36
37 async function handleSubmitStat() { 37 async function handleSubmitStat()
38 const response = await fetch("http://localhost:8080/api/v1/stats/", { 38 {
39 const { date, quantity } = statistic;
40 await fetch("http://localhost:8080/api/v1/stats/", {
39 method: "POST", 41 method: "POST",
40 headers: { 42 headers: {
41 Authorization: `Bearer ${$token}` 43 Authorization: `Bearer ${$token}`
42 }, 44 },
43 body: JSON.stringify({ 45 body: JSON.stringify({
44 date: new Date(), 46 date: new Date(date),
45 user_id: 1, 47 user_id: 2,
46 quantity: 3 48 quantity
47 }) 49 })
48 }); 50 });
49 dispatch("submit"); 51 dispatch("submit");
50 } 52 }
53
51</script> 54</script>
52 55
53<dialog {open} on:submit={handleSubmitStat}> 56<dialog {open} on:submit={handleSubmitStat}>