From d32667acd168e7e28e0dddb73f1d4db5e5ac1b96 Mon Sep 17 00:00:00 2001 From: vinchent Date: Tue, 6 Aug 2024 22:07:34 +0200 Subject: [PATCH] Creating database models --- internal/models/models.go | 52 +++++++++++++++++++ ...40806200424_add_image_to_widgets.down.fizz | 1 + ...0240806200424_add_image_to_widgets.up.fizz | 1 + 3 files changed, 54 insertions(+) create mode 100644 migrations/migrations/20240806200424_add_image_to_widgets.down.fizz create mode 100644 migrations/migrations/20240806200424_add_image_to_widgets.up.fizz diff --git a/internal/models/models.go b/internal/models/models.go index f76dea8..7f676b8 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -32,6 +32,58 @@ type Widget struct { Price int `json:"price"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` + Image string `json:"image"` +} + +// Order is the type for all orders +type Order struct { + ID int `json:"id"` + WidgetID int `json:"widget_id"` + TransactionID int `json:"transaction_id"` + StatusID int `json:"status_id"` + Quantity int `json:"quantity"` + Amount int `json:"amount"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` +} + +// Status is the type for orders statuses +type Status struct { + ID int `json:"id"` + Name string `json:"name"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` +} + +// TransactionStatus is the type for transaction statuses +type TransactionStatus struct { + ID int `json:"id"` + Name string `json:"name"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` +} + +// Transaction is the type for transactions +type Transaction struct { + ID int `json:"id"` + Amount int `json:"amount"` + Currency string `json:"currency"` + LastFour string `json:"last_four"` + BankReturnCode string `json:bank_return_code` + TransactionStatusID int `json:transaction_status_id` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` +} + +// User is the type for users +type User struct { + ID int `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email string `json:"email"` + Password string `json:"password"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` } func (m *DBModel) GetWidget(id int) (Widget, error) { diff --git a/migrations/migrations/20240806200424_add_image_to_widgets.down.fizz b/migrations/migrations/20240806200424_add_image_to_widgets.down.fizz new file mode 100644 index 0000000..a819158 --- /dev/null +++ b/migrations/migrations/20240806200424_add_image_to_widgets.down.fizz @@ -0,0 +1 @@ +drop_column("widgets", "image") diff --git a/migrations/migrations/20240806200424_add_image_to_widgets.up.fizz b/migrations/migrations/20240806200424_add_image_to_widgets.up.fizz new file mode 100644 index 0000000..78ed84d --- /dev/null +++ b/migrations/migrations/20240806200424_add_image_to_widgets.up.fizz @@ -0,0 +1 @@ +add_column("widgets", "image", "string", {"default":""})