mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-31 10:45:53 +01:00
Add models
This commit is contained in:
7
database/models/account.go
Normal file
7
database/models/account.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package models
|
||||
|
||||
// Account : Account Model
|
||||
type Account struct {
|
||||
UserID uint
|
||||
Type string
|
||||
}
|
||||
20
database/models/invoice.go
Normal file
20
database/models/invoice.go
Normal 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
|
||||
}
|
||||
13
database/models/transactionentries.go
Normal file
13
database/models/transactionentries.go
Normal 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
|
||||
}
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user