39 lines
846 B
Go
39 lines
846 B
Go
package domain
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type SessionRepo interface {
|
|
Create(ctx context.Context, session *UserSession) error
|
|
GetByID(ctx context.Context, id uuid.UUID) (*UserSession, error)
|
|
Delete(ctx context.Context, id uuid.UUID) error
|
|
GetUserSessions(ctx context.Context, userID uuid.UUID) ([]UserSession, error)
|
|
}
|
|
|
|
// TODO: add IP and UserAgent
|
|
type UserSession struct {
|
|
ID uuid.UUID
|
|
UserID uuid.UUID
|
|
User User
|
|
WalletID string
|
|
ExpiresAt time.Time
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
DeletedAt *time.Time
|
|
}
|
|
|
|
func NewSession(userID uuid.UUID, walletID string, expiresAt time.Time) *UserSession {
|
|
return &UserSession{
|
|
ID: uuid.New(),
|
|
UserID: userID,
|
|
WalletID: walletID,
|
|
ExpiresAt: expiresAt,
|
|
CreatedAt: time.Now().UTC(),
|
|
UpdatedAt: time.Now().UTC(),
|
|
}
|
|
}
|