aboutsummaryrefslogtreecommitdiff
path: root/api/models.go
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 /api/models.go
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 'api/models.go')
-rw-r--r--api/models.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/api/models.go b/api/models.go
new file mode 100644
index 0000000..0845d1d
--- /dev/null
+++ b/api/models.go
@@ -0,0 +1,57 @@
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