Add complete database schema and ORM models (#4)
This commit was merged in pull request #4.
This commit is contained in:
27
internal/models/session.go
Normal file
27
internal/models/session.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Session represents a server-held user session.
|
||||
type Session struct {
|
||||
Base
|
||||
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"userId"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
LastActiveAt time.Time `json:"lastActiveAt"`
|
||||
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
|
||||
}
|
||||
|
||||
// User returns the user who owns this session.
|
||||
func (s *Session) User(ctx context.Context) (*User, error) {
|
||||
if ul := s.GetUserLookup(); ul != nil {
|
||||
return ul.GetUserByID(ctx, s.UserID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("user lookup not available")
|
||||
}
|
||||
Reference in New Issue
Block a user