Add models

This commit is contained in:
Viktor Patchev
2022-01-05 19:29:47 +01:00
parent 9b82f56bfb
commit da7701214e
5 changed files with 46 additions and 5 deletions

View File

@@ -0,0 +1,7 @@
package models
// Account : Account Model
type Account struct {
UserID uint
Type string
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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,
})

View File

@@ -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
}