From da7701214e5b3dae3211403b079fddfedf6ac0f5 Mon Sep 17 00:00:00 2001 From: Viktor Patchev Date: Wed, 5 Jan 2022 19:29:47 +0100 Subject: [PATCH] Add models --- database/models/account.go | 7 +++++++ database/models/invoice.go | 20 ++++++++++++++++++++ database/models/transactionentries.go | 13 +++++++++++++ database/models/user.go | 9 +++++---- routes/auth/auth.ctrl.go | 2 +- 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 database/models/account.go create mode 100644 database/models/invoice.go create mode 100644 database/models/transactionentries.go diff --git a/database/models/account.go b/database/models/account.go new file mode 100644 index 0000000..eb30773 --- /dev/null +++ b/database/models/account.go @@ -0,0 +1,7 @@ +package models + +// Account : Account Model +type Account struct { + UserID uint + Type string +} diff --git a/database/models/invoice.go b/database/models/invoice.go new file mode 100644 index 0000000..2358771 --- /dev/null +++ b/database/models/invoice.go @@ -0,0 +1,20 @@ +package models + +import "time" + +// Invoice : Invoice Model +type Invoice struct { + ID uint `gorm:"primary_key"` + Type string + UserID uint + TransactionEntryID uint + Amount int64 + Memo string + DescriptionHash string + PaymentRequest string + RHash string + State string + CreatedAt time.Time + UpdatedAt time.Time + SettledAt time.Time +} diff --git a/database/models/transactionentries.go b/database/models/transactionentries.go new file mode 100644 index 0000000..2cd7463 --- /dev/null +++ b/database/models/transactionentries.go @@ -0,0 +1,13 @@ +package models + +import "time" + +// TransactionEntries : Transaction Entries Model +type TransactionEntries struct { + UserID uint + InvoiceID uint + CreditAccountID uint + DebitAccountID uint + Amount uint64 + CreatedAt time.Time +} diff --git a/database/models/user.go b/database/models/user.go index 702963d..d563e33 100644 --- a/database/models/user.go +++ b/database/models/user.go @@ -9,7 +9,7 @@ import ( // User : User Model type User struct { - Id uint `gorm:"primary_key"` + ID uint `gorm:"primary_key"` Email string Login string Password string @@ -20,16 +20,17 @@ type User struct { } // GenerateToken : Generate Token -func (u *User) GenerateToken(c echo.Context, user *User) error { - if u.Id == user.Id { +func (u *User) GenerateAccessToken(c echo.Context, user *User) error { + if u.ID == user.ID { token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ - "id": u.Id, + "id": u.ID, }) t, err := token.SignedString([]byte("secret")) if err != nil { return err } + return c.JSON(http.StatusOK, map[string]string{ u.AccessToken: t, }) diff --git a/routes/auth/auth.ctrl.go b/routes/auth/auth.ctrl.go index 5348081..6a8524c 100644 --- a/routes/auth/auth.ctrl.go +++ b/routes/auth/auth.ctrl.go @@ -39,7 +39,7 @@ func (AuthRouter) Auth(c echo.Context) error { return c.NoContent(http.StatusConflict) } - err = user.GenerateToken(c, &user) + err = user.GenerateAccessToken(c, &user) if err != nil { return err }