package store import ( "context" "time" ) func (s *Store) AdminByUsername(ctx context.Context, username string) (AdminUser, error) { var u AdminUser err := s.db.QueryRowContext(ctx, `select id, username, password_hash from admin_users where username = ?`, username).Scan(&u.ID, &u.Username, &u.PasswordHash) return u, err } func (s *Store) CreateSession(ctx context.Context, tokenHash string, userID int64, expiresAt time.Time) error { _, err := s.db.ExecContext(ctx, `insert into sessions (token_hash, user_id, expires_at) values (?, ?, ?)`, tokenHash, userID, expiresAt) return err } func (s *Store) SessionUser(ctx context.Context, tokenHash string) (AdminUser, error) { var u AdminUser err := s.db.QueryRowContext(ctx, `select u.id, u.username, u.password_hash from sessions s join admin_users u on u.id = s.user_id where s.token_hash = ? and s.expires_at > ?`, tokenHash, time.Now()). Scan(&u.ID, &u.Username, &u.PasswordHash) return u, err } func (s *Store) DeleteSession(ctx context.Context, tokenHash string) error { _, err := s.db.ExecContext(ctx, `delete from sessions where token_hash = ?`, tokenHash) return err }