aboutsummaryrefslogtreecommitdiff
path: root/api/models.go
diff options
context:
space:
mode:
authorZach Berwaldt <zberwaldt@tutamail.com>2024-03-07 19:16:07 -0500
committerZach Berwaldt <zberwaldt@tutamail.com>2024-03-07 19:16:07 -0500
commit6651daca670664f3de8af9c7bcb74b1e7c6c6be9 (patch)
treef1bb35ef8b0e1d498842a17b84c87c6ee996274e /api/models.go
parent5fa57845052655883120ba4d19a85d8756fb8d8c (diff)
Add CORS middleware and authentication middleware to the API server.
The `setupRouter` function in `main.go` now includes a CORS middleware and a token authentication middleware. The CORS middleware allows cross-origin resource sharing by setting the appropriate response headers. The token authentication middleware checks for the presence of an `Authorization` header with a valid bearer token. If the token is missing or invalid, an unauthorized response is returned. In addition to these changes, a new test file `main_test.go` has been added to test the `/api/v1/auth` route. This test suite includes two test cases: one for successful authentication and one for failed authentication. Update go.mod to include new dependencies. The `go.mod` file has been modified to include two new dependencies: `github.com/spf13/viper` and `github.com/stretchr/testify`. Ignore go.sum changes. Ignore changes in the `go.sum` file, as they only include updates to existing dependencies.
Diffstat (limited to 'api/models.go')
-rw-r--r--api/models.go57
1 files changed, 0 insertions, 57 deletions
diff --git a/api/models.go b/api/models.go
deleted file mode 100644
index 0845d1d..0000000
--- a/api/models.go
+++ /dev/null
@@ -1,57 +0,0 @@
1package main
2
3import (
4 "time"
5 "github.com/google/uuid"
6)
7
8type Statistic struct {
9 ID int64 `json:"-"`
10 Date time.Time `json:"date"`
11 User User `json:"user"`
12 Quantity int `json:"quantity"`
13}
14
15type StatisticPost struct {
16 Date time.Time `json:"date"`
17 Quantity int64 `json:"quantity"`
18 UserID int64 `json:"user_id"`
19}
20
21type User struct {
22 ID int64 `json:"-"`
23 Name string `json:"name"`
24 UUID uuid.UUID `json:"uuid"`
25 Password string `json:"-"`
26}
27
28type Token struct {
29 ID int64 `json:"-"`
30 UserID int64 `json:"user_id"`
31 Token string `json:"token"`
32 CreatedAt time.Time `json:"created_at"`
33 ExpiredAt time.Time `json:"expired_at"`
34}
35
36type Preference struct {
37 ID int64 `json:"-"`
38 Color string `json:"color"`
39 UserID int64 `json:"-"`
40 Size Size `json:"size"`
41}
42
43type Size struct {
44 ID int64 `json:"-"`
45 Size int64 `json:"size"`
46 Unit string `json:"unit"`
47}
48
49type WeeklyStatistic struct {
50 Date string `json:"date"`
51 Total int64 `json:"total"`
52}
53
54type DailyUserTotals struct {
55 Name string `json:"name"`
56 Total int64 `json:"total"`
57} \ No newline at end of file