Mehrsprachige Bedienung und versionierte Aufgabenvarianten einführen
Übersetzungskataloge, getrennte Sprachpräferenzen und einen versionierten Aufgabenpilot ergänzen. Historische Aufgaben und Bewertungen bleiben erhalten; äquivalente Ansichten teilen Nachweise. Lokal mit Race-Tests und PostgreSQL, Vet, Web-Build, Bank-Audits und Browser-Fixtures geprüft. Dieser Stand dient als Ausgangspunkt für die anschließend beauftragte Zusammenführung zur Muttersprache.
This commit is contained in:
@@ -182,9 +182,9 @@ func (s *PostgresStore) CreateUser(ctx context.Context, email, passwordHash, uiL
|
||||
row := s.db.QueryRowContext(ctx, `
|
||||
INSERT INTO users (id, email, password_hash, ui_language)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, email, ui_language, role, created_at
|
||||
RETURNING id, email, ui_language, instruction_language, role, created_at
|
||||
`, user.ID, user.Email, passwordHash, uiLanguage)
|
||||
if err := row.Scan(&user.ID, &user.Email, &user.UILanguage, &user.Role, &user.CreatedAt); err != nil {
|
||||
if err := row.Scan(&user.ID, &user.Email, &user.UILanguage, &user.InstructionLanguage, &user.Role, &user.CreatedAt); err != nil {
|
||||
return domain.User{}, err
|
||||
}
|
||||
return user, nil
|
||||
@@ -194,11 +194,11 @@ func (s *PostgresStore) GetPasswordHashByEmail(ctx context.Context, email string
|
||||
var user domain.User
|
||||
var hash string
|
||||
row := s.db.QueryRowContext(ctx, `
|
||||
SELECT id, email, password_hash, ui_language, role, created_at
|
||||
SELECT id, email, password_hash, ui_language, instruction_language, role, created_at
|
||||
FROM users
|
||||
WHERE email = $1
|
||||
`, strings.ToLower(strings.TrimSpace(email)))
|
||||
if err := row.Scan(&user.ID, &user.Email, &hash, &user.UILanguage, &user.Role, &user.CreatedAt); err != nil {
|
||||
if err := row.Scan(&user.ID, &user.Email, &hash, &user.UILanguage, &user.InstructionLanguage, &user.Role, &user.CreatedAt); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return domain.User{}, "", ErrNotFound
|
||||
}
|
||||
@@ -210,11 +210,11 @@ func (s *PostgresStore) GetPasswordHashByEmail(ctx context.Context, email string
|
||||
func (s *PostgresStore) GetUser(ctx context.Context, id string) (domain.User, error) {
|
||||
var user domain.User
|
||||
row := s.db.QueryRowContext(ctx, `
|
||||
SELECT id, email, ui_language, role, created_at
|
||||
SELECT id, email, ui_language, instruction_language, role, created_at
|
||||
FROM users
|
||||
WHERE id = $1
|
||||
`, id)
|
||||
if err := row.Scan(&user.ID, &user.Email, &user.UILanguage, &user.Role, &user.CreatedAt); err != nil {
|
||||
if err := row.Scan(&user.ID, &user.Email, &user.UILanguage, &user.InstructionLanguage, &user.Role, &user.CreatedAt); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return domain.User{}, ErrNotFound
|
||||
}
|
||||
@@ -265,20 +265,48 @@ func (s *PostgresStore) GetPrimaryProfile(ctx context.Context, userID string) (d
|
||||
}
|
||||
|
||||
func (s *PostgresStore) UpdatePreferences(ctx context.Context, userID, uiLanguage, targetLanguage, cefrLevel string, dailyGoalMinutes int) (domain.LearnerProfile, error) {
|
||||
if uiLanguage != "" {
|
||||
if _, err := s.db.ExecContext(ctx, `UPDATE users SET ui_language = $1 WHERE id = $2`, uiLanguage, userID); err != nil {
|
||||
return domain.LearnerProfile{}, err
|
||||
}
|
||||
if uiLanguage != "" && !domain.SupportedUILanguage(uiLanguage) {
|
||||
return domain.LearnerProfile{}, errors.New("unsupported UI language")
|
||||
}
|
||||
tx, err := s.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return domain.LearnerProfile{}, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
// Lock the account so partial preference updates preserve the active course
|
||||
// and cannot race with another language/profile switch.
|
||||
var accountID string
|
||||
if err = tx.QueryRowContext(ctx, `SELECT id FROM users WHERE id=$1 FOR UPDATE`, userID).Scan(&accountID); err != nil {
|
||||
return domain.LearnerProfile{}, err
|
||||
}
|
||||
var current domain.LearnerProfile
|
||||
err = tx.QueryRowContext(ctx, `SELECT p.target_language,p.cefr_level,p.daily_goal_minutes
|
||||
FROM learner_profiles p JOIN users u ON u.id=p.user_id WHERE p.user_id=$1
|
||||
ORDER BY (p.id=u.active_profile_id) DESC NULLS LAST,p.created_at,p.id LIMIT 1`, userID).Scan(¤t.TargetLanguage, ¤t.CEFRLevel, ¤t.DailyGoalMinutes)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return current, err
|
||||
}
|
||||
targetLanguage = valueOr(targetLanguage, valueOr(current.TargetLanguage, "en-US"))
|
||||
cefrLevel = valueOr(cefrLevel, valueOr(current.CEFRLevel, "A1"))
|
||||
if dailyGoalMinutes <= 0 {
|
||||
dailyGoalMinutes = current.DailyGoalMinutes
|
||||
}
|
||||
if dailyGoalMinutes <= 0 {
|
||||
dailyGoalMinutes = 10
|
||||
}
|
||||
profile, err := s.CreateLearnerProfile(ctx, userID, valueOr(targetLanguage, "en-US"), valueOr(cefrLevel, "A1"), dailyGoalMinutes)
|
||||
var profile domain.LearnerProfile
|
||||
err = tx.QueryRowContext(ctx, `INSERT INTO learner_profiles(id,user_id,target_language,cefr_level,daily_goal_minutes)
|
||||
VALUES($1,$2,$3,$4,$5) ON CONFLICT(user_id,target_language) DO UPDATE SET
|
||||
cefr_level=EXCLUDED.cefr_level,daily_goal_minutes=EXCLUDED.daily_goal_minutes
|
||||
RETURNING id,user_id,target_language,cefr_level,daily_goal_minutes,created_at`, NewID("lrn"), userID, targetLanguage, cefrLevel, dailyGoalMinutes).Scan(&profile.ID, &profile.UserID, &profile.TargetLanguage, &profile.CEFRLevel, &profile.DailyGoalMinutes, &profile.CreatedAt)
|
||||
if err != nil {
|
||||
return profile, err
|
||||
}
|
||||
_, err = s.db.ExecContext(ctx, `UPDATE users SET active_profile_id=$2 WHERE id=$1`, userID, profile.ID)
|
||||
return profile, err
|
||||
_, err = tx.ExecContext(ctx, `UPDATE users SET active_profile_id=$2,ui_language=CASE WHEN $3='' THEN ui_language ELSE $3 END WHERE id=$1`, userID, profile.ID, uiLanguage)
|
||||
if err != nil {
|
||||
return profile, err
|
||||
}
|
||||
return profile, tx.Commit()
|
||||
}
|
||||
|
||||
func (s *PostgresStore) ListLanguages(ctx context.Context) ([]domain.LanguageProfile, error) {
|
||||
@@ -665,6 +693,13 @@ CREATE TABLE IF NOT EXISTS users (
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS role TEXT NOT NULL DEFAULT 'learner'
|
||||
CHECK (role IN ('learner', 'admin'));
|
||||
|
||||
-- Previously ui_language also selected the language of explanations. Preserve
|
||||
-- that preference once, independently of all future interface-language changes.
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS instruction_language TEXT;
|
||||
UPDATE users SET instruction_language=ui_language WHERE instruction_language IS NULL;
|
||||
ALTER TABLE users ALTER COLUMN instruction_language SET DEFAULT 'de-DE';
|
||||
ALTER TABLE users ALTER COLUMN instruction_language SET NOT NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS learner_profiles (
|
||||
id TEXT PRIMARY KEY,
|
||||
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
|
||||
Reference in New Issue
Block a user