35 lines
778 B
Go
35 lines
778 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitea.dwysokinski.me/twhelp/sessions/internal/domain"
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type APIKey struct {
|
|
bun.BaseModel `bun:"base_model,table:api_keys,alias:ak"`
|
|
|
|
ID int64 `bun:"id,pk,autoincrement,identity"`
|
|
Key string `bun:"key,nullzero,type:varchar(255),notnull,unique"`
|
|
UserID int64 `bun:"user_id,nullzero,notnull"`
|
|
CreatedAt time.Time `bun:"created_at,nullzero,notnull,default:current_timestamp"`
|
|
}
|
|
|
|
func NewAPIKey(p domain.CreateAPIKeyParams) APIKey {
|
|
return APIKey{
|
|
Key: p.Key(),
|
|
UserID: p.UserID(),
|
|
CreatedAt: time.Now(),
|
|
}
|
|
}
|
|
|
|
func (a *APIKey) ToDomain() domain.APIKey {
|
|
return domain.APIKey{
|
|
ID: a.ID,
|
|
Key: a.Key,
|
|
UserID: a.UserID,
|
|
CreatedAt: a.CreatedAt,
|
|
}
|
|
}
|