diff options
author | Zach Berwaldt <zberwaldt@tutamail.com> | 2024-03-15 22:00:10 -0400 |
---|---|---|
committer | Zach Berwaldt <zberwaldt@tutamail.com> | 2024-03-15 22:00:10 -0400 |
commit | fd1332a3df191577e91c6d846a8b5db1747099fd (patch) | |
tree | b3f045cd06d6622e23441b442e8f3861050ed444 | |
parent | cc49361bcbf689510035e7bbdcce9d8467a36282 (diff) |
cleanup
-rw-r--r-- | api/internal/router/router.go | 8 | ||||
-rw-r--r-- | fe/src/lib/DataView.svelte | 7 | ||||
-rw-r--r-- | fe/src/lib/LoginForm.svelte | 3 | ||||
-rw-r--r-- | fe/src/lib/PreferencesForm.svelte | 15 | ||||
-rw-r--r-- | fe/src/lib/forms/AddForm.svelte | 3 | ||||
-rw-r--r-- | fe/src/utils.ts | 5 |
6 files changed, 25 insertions, 16 deletions
diff --git a/api/internal/router/router.go b/api/internal/router/router.go index 3c86b8c..a71c3e6 100644 --- a/api/internal/router/router.go +++ b/api/internal/router/router.go | |||
@@ -30,10 +30,10 @@ func SetupRouter() *gin.Engine { | |||
30 | stats := api.Group("/stats") | 30 | stats := api.Group("/stats") |
31 | stats.Use(middleware.TokenRequired()) | 31 | stats.Use(middleware.TokenRequired()) |
32 | { | 32 | { |
33 | stats.GET("/", controllers.GetAllStatistics) | 33 | stats.GET("", controllers.GetAllStatistics) |
34 | stats.POST("/", controllers.PostNewStatistic) | 34 | stats.POST("", controllers.PostNewStatistic) |
35 | stats.GET("weekly/", controllers.GetWeeklyStatistics) | 35 | stats.GET("weekly", controllers.GetWeeklyStatistics) |
36 | stats.GET("daily/", controllers.GetDailyUserStatistics) | 36 | stats.GET("daily", controllers.GetDailyUserStatistics) |
37 | stats.GET("user/:uuid", controllers.GetUserStatistics) | 37 | stats.GET("user/:uuid", controllers.GetUserStatistics) |
38 | stats.PATCH("user/:uuid", controllers.UpdateUserStatistic) | 38 | stats.PATCH("user/:uuid", controllers.UpdateUserStatistic) |
39 | stats.DELETE("user/:uuid", controllers.DeleteUserStatistic) | 39 | stats.DELETE("user/:uuid", controllers.DeleteUserStatistic) |
diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 5e81a5a..ffc2fe8 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte | |||
@@ -9,6 +9,7 @@ | |||
9 | import Card from "./Card.svelte"; | 9 | import Card from "./Card.svelte"; |
10 | import Column from "./Column.svelte"; | 10 | import Column from "./Column.svelte"; |
11 | import AddForm from "./forms/AddForm.svelte"; | 11 | import AddForm from "./forms/AddForm.svelte"; |
12 | import { apiURL } from "../utils"; | ||
12 | 13 | ||
13 | let json: Promise<any>; | 14 | let json: Promise<any>; |
14 | 15 | ||
@@ -24,7 +25,7 @@ | |||
24 | let userTotalsData: number[]; | 25 | let userTotalsData: number[]; |
25 | 26 | ||
26 | async function fetchData() { | 27 | async function fetchData() { |
27 | const res = await fetch("http://localhost:8080/api/v1/stats/", { | 28 | const res = await fetch(apiURL("stats"), { |
28 | method: "GET", | 29 | method: "GET", |
29 | headers: { | 30 | headers: { |
30 | Authorization: `Bearer ${$token}` | 31 | Authorization: `Bearer ${$token}` |
@@ -38,7 +39,7 @@ | |||
38 | } | 39 | } |
39 | 40 | ||
40 | async function fetchDailyUserStatistics() { | 41 | async function fetchDailyUserStatistics() { |
41 | const res = await fetch("http://localhost:8080/api/v1/stats/daily/", { | 42 | const res = await fetch(apiURL("stats/daily"), { |
42 | method: "GET", | 43 | method: "GET", |
43 | headers: { | 44 | headers: { |
44 | Authorization: `Bearer ${$token}` | 45 | Authorization: `Bearer ${$token}` |
@@ -57,7 +58,7 @@ | |||
57 | } | 58 | } |
58 | 59 | ||
59 | async function fetchWeeklyTotals() { | 60 | async function fetchWeeklyTotals() { |
60 | const res = await fetch("http://localhost:8080/api/v1/stats/weekly/", { | 61 | const res = await fetch(apiURL("stats/weekly"), { |
61 | method: "GET", | 62 | method: "GET", |
62 | headers: { | 63 | headers: { |
63 | Authorization: `Bearer ${$token}` | 64 | Authorization: `Bearer ${$token}` |
diff --git a/fe/src/lib/LoginForm.svelte b/fe/src/lib/LoginForm.svelte index 8c3c288..cf5febf 100644 --- a/fe/src/lib/LoginForm.svelte +++ b/fe/src/lib/LoginForm.svelte | |||
@@ -1,6 +1,7 @@ | |||
1 | <script lang="ts"> | 1 | <script lang="ts"> |
2 | import { token, user, preferences } from "../stores/auth"; | 2 | import { token, user, preferences } from "../stores/auth"; |
3 | import Card from "./Card.svelte"; | 3 | import Card from "./Card.svelte"; |
4 | import { apiURL } from "../utils"; | ||
4 | 5 | ||
5 | let credentials: CredentialObject = { | 6 | let credentials: CredentialObject = { |
6 | username: "", | 7 | username: "", |
@@ -28,7 +29,7 @@ | |||
28 | } | 29 | } |
29 | const auth = prepareCredentials(credentials); | 30 | const auth = prepareCredentials(credentials); |
30 | 31 | ||
31 | const response = await fetch("http://localhost:8080/api/v1/auth", { | 32 | const response = await fetch(apiURL("auth"), { |
32 | method: "POST", | 33 | method: "POST", |
33 | headers: { | 34 | headers: { |
34 | Authorization: `Basic ${auth}`, | 35 | Authorization: `Basic ${auth}`, |
diff --git a/fe/src/lib/PreferencesForm.svelte b/fe/src/lib/PreferencesForm.svelte index 875393c..74b8a63 100644 --- a/fe/src/lib/PreferencesForm.svelte +++ b/fe/src/lib/PreferencesForm.svelte | |||
@@ -2,6 +2,7 @@ | |||
2 | import { user, preferences, token } from "../stores/auth"; | 2 | import { user, preferences, token } from "../stores/auth"; |
3 | import { createEventDispatcher, onDestroy, onMount } from "svelte"; | 3 | import { createEventDispatcher, onDestroy, onMount } from "svelte"; |
4 | import type { User } from "../types"; | 4 | import type { User } from "../types"; |
5 | import { apiURL } from "../utils"; | ||
5 | 6 | ||
6 | export let open: boolean; | 7 | export let open: boolean; |
7 | 8 | ||
@@ -13,9 +14,10 @@ | |||
13 | 14 | ||
14 | const unsubscribe = preferences.subscribe( | 15 | const unsubscribe = preferences.subscribe( |
15 | (value: any) => { | 16 | (value: any) => { |
16 | console.log('update value: ', value); | 17 | if (value) { |
17 | color = value.color; | 18 | color = value.color; |
18 | selectedSize = value.size_id; | 19 | selectedSize = value.size_id; |
20 | } | ||
19 | }, | 21 | }, |
20 | ); | 22 | ); |
21 | 23 | ||
@@ -24,7 +26,7 @@ | |||
24 | } | 26 | } |
25 | 27 | ||
26 | async function updateUserPreferences() { | 28 | async function updateUserPreferences() { |
27 | const res = await fetch("http://localhost:8080/api/v1/user/preferences", { | 29 | const res = await fetch(apiURL("user/preferences"), { |
28 | method: "PATCH", | 30 | method: "PATCH", |
29 | headers: { | 31 | headers: { |
30 | Authorization: `Bearer ${$token}`, | 32 | Authorization: `Bearer ${$token}`, |
@@ -34,8 +36,7 @@ | |||
34 | } | 36 | } |
35 | 37 | ||
36 | async function getUserPreferences() { | 38 | async function getUserPreferences() { |
37 | const res = await fetch( | 39 | const res = await fetch(apiURL(`user/${($user as User)!.id}/preferences`), |
38 | `http://localhost:8080/api/v1/user/${($user as User)!.id}/preferences`, | ||
39 | { | 40 | { |
40 | method: "GET", | 41 | method: "GET", |
41 | headers: { | 42 | headers: { |
@@ -61,7 +62,7 @@ | |||
61 | } | 62 | } |
62 | 63 | ||
63 | onMount(() => { | 64 | onMount(() => { |
64 | fetch("http://localhost:8080/api/v1/sizes", { | 65 | fetch(apiURL("sizes"), { |
65 | method: "GET", | 66 | method: "GET", |
66 | headers: { | 67 | headers: { |
67 | Authorization: `Bearer ${$token}`, | 68 | Authorization: `Bearer ${$token}`, |
diff --git a/fe/src/lib/forms/AddForm.svelte b/fe/src/lib/forms/AddForm.svelte index 4520b1b..f85cce6 100644 --- a/fe/src/lib/forms/AddForm.svelte +++ b/fe/src/lib/forms/AddForm.svelte | |||
@@ -2,6 +2,7 @@ | |||
2 | import { createEventDispatcher } from "svelte"; | 2 | import { createEventDispatcher } from "svelte"; |
3 | import { token, user } from "../../stores/auth"; | 3 | import { token, user } from "../../stores/auth"; |
4 | import type { Statistic } from "../../types"; | 4 | import type { Statistic } from "../../types"; |
5 | import { apiURL } from "../../utils"; | ||
5 | 6 | ||
6 | export let open: boolean; | 7 | export let open: boolean; |
7 | 8 | ||
@@ -37,7 +38,7 @@ | |||
37 | async function handleSubmitStat() | 38 | async function handleSubmitStat() |
38 | { | 39 | { |
39 | const { date, quantity } = statistic; | 40 | const { date, quantity } = statistic; |
40 | await fetch("http://localhost:8080/api/v1/stats/", { | 41 | await fetch(apiURL("stats"), { |
41 | method: "POST", | 42 | method: "POST", |
42 | headers: { | 43 | headers: { |
43 | Authorization: `Bearer ${$token}` | 44 | Authorization: `Bearer ${$token}` |
diff --git a/fe/src/utils.ts b/fe/src/utils.ts index e78556c..9fddf41 100644 --- a/fe/src/utils.ts +++ b/fe/src/utils.ts | |||
@@ -7,3 +7,8 @@ export function processFormInput(form: HTMLFormElement) { | |||
7 | } | 7 | } |
8 | return data; | 8 | return data; |
9 | } | 9 | } |
10 | |||
11 | export function apiURL (path: string): string { | ||
12 | const baseUrl = import.meta.env?.VITE_API_BASE_URL ?? "http://localhost:8080/api/v1"; | ||
13 | return `${baseUrl}${path}` | ||
14 | } | ||