Files
Learn_System/backend
Maxim Dolgolyov 98ec1ed478 feat(shop): animated backgrounds — system-wide cosmetic + picker
A new cosmetic family: a fixed-position overlay painted behind every
page of the app, switchable from the profile shop. 4 free presets + 6
paid (250-1200 coins) so the new economy has another sink. Every
animation respects prefers-reduced-motion and falls back to its static
gradient.

Catalogue (migration 035):
  free:   none, gradient-soft, dots, dark
  paid:   gradient-flow, grid, bubbles, stars (mid)
          aurora, nebula                       (premium)

Backend:
  • migration 035 adds users.active_background + rebuilds shop_items
    CHECK to include 'background' (standard SQLite 'new + copy + swap')
    and seeds 10 items
  • shopController.getMyActive returns { background: { slug } } and
    activateItem handles type='background' (stores bare slug in
    active_background) + skips the user_purchases check for price=0
    so free presets work for everyone without per-user rows
  • routes/shop validate schema lets 'background' through

Frontend:
  • api.js applyCosmetics injects <div id='ls-bg-fx'> at body start
    and toggles class to bg-<slug>. Cleared backgrounds remove the
    element so dark→light transitions don't leave artifacts.
  • ls.css gains a self-contained 'ANIMATED BACKGROUNDS' block:
    keyframes per animated slug (ls-bg-flow, ls-bg-grid-scan,
    ls-bg-bubble-rise, ls-bg-stars-twinkle, ls-bg-aurora-spin,
    ls-bg-nebula-pan) wrapped in a prefers-reduced-motion kill-switch.
    Same .bg-<slug> classes are reused for the .bg-preview swatches.
  • profile.html shop:
    - new 'Фоны' filter button between Рамки and Титулы
    - _renderItemPreview type='background' draws a real 56-aspect swatch
      (same CSS as the page bg — what you see is what you apply)
    - _isItemActive matches by slug for background type
    - free items (price===0) treated as auto-owned in render so users
      can apply them without a fake 'purchase' step

Verified: getMyActive returns { background: { slug: 'nebula' } } after
flipping users.active_background; activate path updates the row.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-29 21:13:53 +03:00
..

LearnSpace Backend — Фаза 1

Быстрый старт

cd backend
npm install

# 1. Скопировать и заполнить переменные окружения
cp .env.example .env

# 2. Создать базу данных в PostgreSQL
createdb learnspace

# 3. Применить миграции (создать таблицы)
npm run migrate

# 4. Загрузить тестовые вопросы
npm run seed

# 5. Запустить сервер
npm run dev

API

Auth

Метод URL Тело Описание
POST /api/auth/register { email, password, name } Регистрация
POST /api/auth/login { email, password } Вход
GET /api/auth/me Текущий пользователь

Предметы

Метод URL Описание
GET /api/subjects Список предметов
GET /api/subjects/:slug/topics Темы предмета

Сессии тестирования

Метод URL Тело Описание
POST /api/sessions { subject_slug, mode, count, topic_id? } Начать тест
POST /api/sessions/:id/answer { question_id, option_id, time_spent_sec? } Отправить ответ
POST /api/sessions/:id/finish Завершить тест + разбор
GET /api/sessions/:id/result Результат завершённого теста
GET /api/sessions/history История тестов

Все /api/sessions/* требуют заголовок:

Authorization: Bearer <token>

Добавление вопросов

Создать JSON-файл в data/ по образцу questions-bio.json:

{
  "subject": "chem",
  "topics": [{ "name": "Органическая химия", "order": 1 }],
  "questions": [
    {
      "topic": "Органическая химия",
      "difficulty": 2,
      "text": "Текст вопроса",
      "options": ["А", "Б", "В", "Г"],
      "answer": 0,
      "explanation": "Объяснение правильного ответа"
    }
  ]
}

Затем повторно запустить npm run seed.

Структура проекта

backend/
├── data/                     ← JSON с вопросами
├── src/
│   ├── server.js             ← точка входа
│   ├── middleware/auth.js    ← JWT верификация
│   ├── db/
│   │   ├── pool.js           ← соединение с PostgreSQL
│   │   ├── migrate.js        ← запуск миграций
│   │   ├── seed.js           ← загрузка вопросов
│   │   └── migrations/       ← SQL-файлы схемы
│   ├── routes/               ← маршруты
│   └── controllers/          ← бизнес-логика
└── .env.example