- AI驱动的网球训练助手
+ AI网球训练助手
- 在家也能提升
- 网球技术水平
+ 精准分析
+ 高效提升
- 只需一支球拍,通过AI姿势识别和智能训练计划,在家高效训练。
- 实时分析挥拍动作,自动评分,持续进步。
+ AI姿势识别 · 智能训练计划 · 实时动作分析 · 自动评分反馈
@@ -57,37 +56,37 @@ export default function Home() {
{
icon: Video,
title: "AI姿势识别",
- desc: "基于MediaPipe的浏览器端实时姿势分析,识别33个身体关键点,精准评估挥拍动作",
+ desc: "MediaPipe实时分析33个关键点,精准评估挥拍动作",
color: "bg-blue-50 text-blue-600",
},
{
icon: Target,
title: "智能训练计划",
- desc: "根据您的水平和分析结果,AI自动生成和调整个性化训练方案,只需球拍即可在家训练",
+ desc: "根据水平和分析结果,AI自动生成和调整训练方案",
color: "bg-green-50 text-green-600",
},
{
icon: Award,
title: "NTRP自动评分",
- desc: "基于美国网球协会标准,从5个维度综合评估您的技术水平,自动更新评分",
+ desc: "USTA标准五维度评估,每次分析自动更新评分",
color: "bg-purple-50 text-purple-600",
},
{
icon: Zap,
- title: "击球统计分析",
- desc: "自动检测击球次数、挥拍速度、击球一致性,量化每次训练效果",
+ title: "击球统计",
+ desc: "击球次数、挥拍速度、一致性,量化训练效果",
color: "bg-orange-50 text-orange-600",
},
{
icon: Footprints,
- title: "运动轨迹追踪",
- desc: "记录身体重心移动轨迹,分析脚步移动模式,提升步法灵活性",
+ title: "运动轨迹",
+ desc: "重心移动轨迹分析,优化脚步移动模式",
color: "bg-teal-50 text-teal-600",
},
{
icon: TrendingUp,
- title: "进度可视化",
- desc: "直观展示训练历史、能力提升趋势和评分变化,激励持续进步",
+ title: "进度追踪",
+ desc: "训练历史、能力趋势、评分变化一目了然",
color: "bg-indigo-50 text-indigo-600",
},
].map((feature) => (
@@ -107,10 +106,10 @@ export default function Home() {
使用流程
{[
- { step: "1", title: "输入用户名", desc: "无需注册,输入用户名即可开始" },
- { step: "2", title: "生成训练计划", desc: "选择水平,AI生成个性化方案" },
- { step: "3", title: "上传训练视频", desc: "录制挥拍视频并上传分析" },
- { step: "4", title: "获取评分建议", desc: "查看分析结果和矫正建议" },
+ { step: "1", title: "输入用户名", desc: "用户名登录即可" },
+ { step: "2", title: "生成计划", desc: "AI个性化训练方案" },
+ { step: "3", title: "上传视频", desc: "录制挥拍并分析" },
+ { step: "4", title: "获取反馈", desc: "评分与矫正建议" },
].map((item) => (
@@ -126,8 +125,8 @@ export default function Home() {
{/* CTA */}
-
准备好提升网球技术了吗?
-
完全免费,无需注册,输入用户名即可开始
+
提升技术,从这里开始
+
输入用户名即可使用全部功能
diff --git a/client/src/pages/Login.tsx b/client/src/pages/Login.tsx
index c2e0507..3670bf1 100644
--- a/client/src/pages/Login.tsx
+++ b/client/src/pages/Login.tsx
@@ -36,8 +36,8 @@ export default function Login() {
- Tennis Training Hub
- AI驱动的在家网球训练助手
+ Tennis Hub
+ AI网球训练助手
@@ -94,7 +94,7 @@ export default function Login() {
- 无需注册,输入用户名即可使用全部功能
+ 输入用户名即可使用全部功能
diff --git a/client/src/pages/Reminders.tsx b/client/src/pages/Reminders.tsx
new file mode 100644
index 0000000..9688a26
--- /dev/null
+++ b/client/src/pages/Reminders.tsx
@@ -0,0 +1,472 @@
+import { useAuth } from "@/_core/hooks/useAuth";
+import { trpc } from "@/lib/trpc";
+import { Button } from "@/components/ui/button";
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
+import { Badge } from "@/components/ui/badge";
+import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, DialogFooter } from "@/components/ui/dialog";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
+import { Switch } from "@/components/ui/switch";
+import { Textarea } from "@/components/ui/textarea";
+import { ScrollArea } from "@/components/ui/scroll-area";
+import { Separator } from "@/components/ui/separator";
+import { toast } from "sonner";
+import { useState, useEffect, useCallback, useMemo } from "react";
+import {
+ Bell, BellRing, Plus, Trash2, Clock, Calendar,
+ CheckCircle2, XCircle, Settings, BellOff, Volume2
+} from "lucide-react";
+
+const DAY_NAMES = ["日", "一", "二", "三", "四", "五", "六"];
+
+const REMINDER_TYPES = [
+ { value: "training", label: "训练提醒", icon:
},
+ { value: "checkin", label: "打卡提醒", icon:
},
+ { value: "analysis", label: "分析提醒", icon:
},
+];
+
+export default function Reminders() {
+ const { user } = useAuth();
+ const [showCreate, setShowCreate] = useState(false);
+ const [newReminder, setNewReminder] = useState({
+ reminderType: "training",
+ title: "",
+ message: "",
+ timeOfDay: "08:00",
+ daysOfWeek: [1, 2, 3, 4, 5] as number[],
+ });
+
+ const utils = trpc.useUtils();
+ const { data: reminders, isLoading } = trpc.reminder.list.useQuery(undefined, { enabled: !!user });
+ const { data: notifications } = trpc.notification.list.useQuery(undefined, { enabled: !!user });
+ const { data: unreadCount } = trpc.notification.unreadCount.useQuery(undefined, { enabled: !!user });
+
+ const createReminder = trpc.reminder.create.useMutation({
+ onSuccess: () => {
+ toast.success("提醒已创建");
+ setShowCreate(false);
+ setNewReminder({ reminderType: "training", title: "", message: "", timeOfDay: "08:00", daysOfWeek: [1, 2, 3, 4, 5] });
+ utils.reminder.list.invalidate();
+ },
+ });
+
+ const deleteReminder = trpc.reminder.delete.useMutation({
+ onSuccess: () => {
+ toast.success("提醒已删除");
+ utils.reminder.list.invalidate();
+ },
+ });
+
+ const toggleReminder = trpc.reminder.toggle.useMutation({
+ onSuccess: () => {
+ utils.reminder.list.invalidate();
+ },
+ });
+
+ const markAllRead = trpc.notification.markAllRead.useMutation({
+ onSuccess: () => {
+ utils.notification.list.invalidate();
+ utils.notification.unreadCount.invalidate();
+ toast.success("全部已读");
+ },
+ });
+
+ const markRead = trpc.notification.markRead.useMutation({
+ onSuccess: () => {
+ utils.notification.list.invalidate();
+ utils.notification.unreadCount.invalidate();
+ },
+ });
+
+ const toggleDay = useCallback((day: number) => {
+ setNewReminder(prev => ({
+ ...prev,
+ daysOfWeek: prev.daysOfWeek.includes(day)
+ ? prev.daysOfWeek.filter(d => d !== day)
+ : [...prev.daysOfWeek, day].sort(),
+ }));
+ }, []);
+
+ const handleCreate = () => {
+ if (!newReminder.title.trim()) {
+ toast.error("请输入提醒标题");
+ return;
+ }
+ if (newReminder.daysOfWeek.length === 0) {
+ toast.error("请至少选择一天");
+ return;
+ }
+ createReminder.mutate(newReminder);
+ };
+
+ // Browser notification permission
+ const [notifPermission, setNotifPermission] = useState
("default");
+
+ useEffect(() => {
+ if ("Notification" in window) {
+ setNotifPermission(Notification.permission);
+ }
+ }, []);
+
+ const requestPermission = async () => {
+ if ("Notification" in window) {
+ const perm = await Notification.requestPermission();
+ setNotifPermission(perm);
+ if (perm === "granted") {
+ toast.success("通知权限已开启");
+ new Notification("Tennis Training Hub", { body: "训练提醒已开启!" });
+ }
+ }
+ };
+
+ // Check reminders and trigger browser notifications
+ useEffect(() => {
+ if (!reminders || notifPermission !== "granted") return;
+
+ const checkInterval = setInterval(() => {
+ const now = new Date();
+ const currentTime = `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}`;
+ const currentDay = now.getDay();
+
+ reminders.forEach((r: any) => {
+ if (r.isActive && r.timeOfDay === currentTime) {
+ const days = typeof r.daysOfWeek === "string" ? JSON.parse(r.daysOfWeek) : r.daysOfWeek;
+ if (Array.isArray(days) && days.includes(currentDay)) {
+ new Notification(r.title, {
+ body: r.message || "该训练了!",
+ icon: "/favicon.ico",
+ });
+ }
+ }
+ });
+ }, 60000); // Check every minute
+
+ return () => clearInterval(checkInterval);
+ }, [reminders, notifPermission]);
+
+ const activeReminders = useMemo(() => reminders?.filter((r: any) => r.isActive) || [], [reminders]);
+ const inactiveReminders = useMemo(() => reminders?.filter((r: any) => !r.isActive) || [], [reminders]);
+
+ if (isLoading) {
+ return (
+
+ );
+ }
+
+ return (
+
+ {/* Header */}
+
+
+
+
+ 训练提醒
+
+
设置定时提醒,保持训练节奏
+
+
+ {notifPermission !== "granted" && (
+
+ )}
+
+
+
+
+ {/* Notification Permission Banner */}
+ {notifPermission === "default" && (
+
+
+
+
+
+
开启浏览器通知
+
允许通知后,到达设定时间时会收到提醒
+
+
+
+
+
+ )}
+
+ {notifPermission === "denied" && (
+
+
+
+
+
通知已被禁用
+
请在浏览器设置中手动开启本站通知权限
+
+
+
+ )}
+
+ {/* Active Reminders */}
+
+
+
+ 活跃提醒 ({activeReminders.length})
+
+ {activeReminders.length === 0 ? (
+
+
+
+ 暂无活跃提醒,点击"新建提醒"开始
+
+
+ ) : (
+
+ {activeReminders.map((reminder: any) => {
+ const days = typeof reminder.daysOfWeek === "string" ? JSON.parse(reminder.daysOfWeek) : reminder.daysOfWeek;
+ const type = REMINDER_TYPES.find(t => t.value === reminder.reminderType);
+ return (
+
+
+
+
+
+ {type?.icon}
+ {reminder.title}
+
+ {reminder.message && (
+
{reminder.message}
+ )}
+
+
+
+ {reminder.timeOfDay}
+
+
+ {DAY_NAMES.map((name, i) => (
+
+ {name}
+
+ ))}
+
+
+
+
+ toggleReminder.mutate({ reminderId: reminder.id, isActive: checked ? 1 : 0 })}
+ />
+
+
+
+
+
+ );
+ })}
+
+ )}
+
+
+ {/* Inactive Reminders */}
+ {inactiveReminders.length > 0 && (
+
+
+
+ 已暂停 ({inactiveReminders.length})
+
+
+ {inactiveReminders.map((reminder: any) => {
+ const days = typeof reminder.daysOfWeek === "string" ? JSON.parse(reminder.daysOfWeek) : reminder.daysOfWeek;
+ return (
+
+
+
+
+
{reminder.title}
+
+
+ {reminder.timeOfDay}
+
+
+
+ toggleReminder.mutate({ reminderId: reminder.id, isActive: checked ? 1 : 0 })}
+ />
+
+
+
+
+
+ );
+ })}
+
+
+ )}
+
+
+
+ {/* Notification History */}
+
+
+
+
+ 通知记录
+ {(unreadCount as number) > 0 && (
+ {unreadCount as number}
+ )}
+
+ {(unreadCount as number) > 0 && (
+
+ )}
+
+
+ {(!notifications || notifications.length === 0) ? (
+
+ ) : (
+
+ {notifications.map((notif: any) => (
+
!notif.isRead && markRead.mutate({ notificationId: notif.id })}
+ >
+
+
+ {notif.isRead ? (
+
+ ) : (
+
+ )}
+
+
{notif.title}
+ {notif.message &&
{notif.message}
}
+
+
+
+ {new Date(notif.createdAt).toLocaleString("zh-CN", { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" })}
+
+
+
+ ))}
+
+ )}
+
+
+
+ );
+}
diff --git a/client/src/pages/Training.tsx b/client/src/pages/Training.tsx
index 1c3249a..609694d 100644
--- a/client/src/pages/Training.tsx
+++ b/client/src/pages/Training.tsx
@@ -96,7 +96,7 @@ export default function Training() {
训练计划
-
AI为您定制的在家网球训练方案
+
AI个性化训练方案
@@ -109,7 +109,7 @@ export default function Training() {
生成训练计划
- 根据您的水平和目标,AI将生成个性化的在家训练方案(只需球拍)
+ 根据水平和目标,AI生成个性化训练方案
diff --git a/client/src/pages/Tutorials.tsx b/client/src/pages/Tutorials.tsx
new file mode 100644
index 0000000..42056a1
--- /dev/null
+++ b/client/src/pages/Tutorials.tsx
@@ -0,0 +1,320 @@
+import { useAuth } from "@/_core/hooks/useAuth";
+import { trpc } from "@/lib/trpc";
+import { Button } from "@/components/ui/button";
+import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
+import { Badge } from "@/components/ui/badge";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
+import { Textarea } from "@/components/ui/textarea";
+import { Progress } from "@/components/ui/progress";
+import { ScrollArea } from "@/components/ui/scroll-area";
+import { toast } from "sonner";
+import { useState, useMemo } from "react";
+import {
+ BookOpen, Play, CheckCircle2, Star, Target,
+ ChevronRight, Filter, AlertTriangle, Lightbulb,
+ ArrowUpDown, Clock, Dumbbell
+} from "lucide-react";
+
+const CATEGORY_LABELS: Record = {
+ forehand: { label: "正手", icon: , color: "bg-green-100 text-green-700" },
+ backhand: { label: "反手", icon: , color: "bg-blue-100 text-blue-700" },
+ serve: { label: "发球", icon: , color: "bg-purple-100 text-purple-700" },
+ volley: { label: "截击", icon: , color: "bg-orange-100 text-orange-700" },
+ footwork: { label: "脚步", icon: , color: "bg-yellow-100 text-yellow-700" },
+ shadow: { label: "影子挥拍", icon: , color: "bg-indigo-100 text-indigo-700" },
+ wall: { label: "墙壁练习", icon: , color: "bg-pink-100 text-pink-700" },
+ fitness: { label: "体能", icon: , color: "bg-red-100 text-red-700" },
+ strategy: { label: "战术", icon: , color: "bg-teal-100 text-teal-700" },
+};
+
+const SKILL_LABELS: Record = {
+ beginner: { label: "初级", color: "bg-emerald-100 text-emerald-700" },
+ intermediate: { label: "中级", color: "bg-amber-100 text-amber-700" },
+ advanced: { label: "高级", color: "bg-rose-100 text-rose-700" },
+};
+
+export default function Tutorials() {
+ const { user } = useAuth();
+ const [selectedCategory, setSelectedCategory] = useState("all");
+ const [selectedSkill, setSelectedSkill] = useState("all");
+ const [selectedTutorial, setSelectedTutorial] = useState(null);
+ const [notes, setNotes] = useState("");
+
+ const { data: tutorials, isLoading } = trpc.tutorial.list.useQuery({
+ category: selectedCategory === "all" ? undefined : selectedCategory,
+ skillLevel: selectedSkill === "all" ? undefined : selectedSkill,
+ });
+
+ const { data: progressData } = trpc.tutorial.progress.useQuery(undefined, { enabled: !!user });
+
+ const updateProgress = trpc.tutorial.updateProgress.useMutation({
+ onSuccess: () => toast.success("进度已更新"),
+ });
+
+ const progressMap = useMemo(() => {
+ const map: Record = {};
+ progressData?.forEach((p: any) => { map[p.tutorialId] = p; });
+ return map;
+ }, [progressData]);
+
+ const totalTutorials = tutorials?.length || 0;
+ const watchedCount = tutorials?.filter((t: any) => progressMap[t.id]?.watched).length || 0;
+ const progressPercent = totalTutorials > 0 ? Math.round((watchedCount / totalTutorials) * 100) : 0;
+
+ const categories = useMemo(() => {
+ const cats = new Set();
+ tutorials?.forEach((t: any) => cats.add(t.category));
+ return Array.from(cats);
+ }, [tutorials]);
+
+ const handleMarkWatched = (tutorialId: number) => {
+ updateProgress.mutate({ tutorialId, watched: 1 });
+ };
+
+ const handleSaveNotes = (tutorialId: number) => {
+ updateProgress.mutate({ tutorialId, notes });
+ setNotes("");
+ toast.success("笔记已保存");
+ };
+
+ const handleSelfScore = (tutorialId: number, score: number) => {
+ updateProgress.mutate({ tutorialId, selfScore: score });
+ };
+
+ if (isLoading) {
+ return (
+
+ );
+ }
+
+ return (
+
+ {/* Header */}
+
+
+
+ 教程库
+
+
专业动作分解与要领,对照标准动作提升技术
+
+
+ {/* Progress Overview */}
+
+
+
+ 学习进度
+ {watchedCount}/{totalTutorials} 已学习
+
+
+ {progressPercent}% 完成
+
+
+
+ {/* Filters */}
+
+
+
+ 分类:
+
+
+
+ {Object.entries(CATEGORY_LABELS).map(([key, { label, icon }]) => (
+
+ ))}
+
+
+
+
+
+
+ 级别:
+
+
+
+ {Object.entries(SKILL_LABELS).map(([key, { label }]) => (
+
+ ))}
+
+
+
+ {/* Tutorial Grid */}
+
+ {tutorials?.map((tutorial: any) => {
+ const cat = CATEGORY_LABELS[tutorial.category] || { label: tutorial.category, color: "bg-gray-100 text-gray-700" };
+ const skill = SKILL_LABELS[tutorial.skillLevel] || { label: tutorial.skillLevel, color: "bg-gray-100 text-gray-700" };
+ const progress = progressMap[tutorial.id];
+ const isWatched = progress?.watched === 1;
+ const keyPoints = typeof tutorial.keyPoints === "string" ? JSON.parse(tutorial.keyPoints) : tutorial.keyPoints || [];
+ const mistakes = typeof tutorial.commonMistakes === "string" ? JSON.parse(tutorial.commonMistakes) : tutorial.commonMistakes || [];
+
+ return (
+
+ );
+ })}
+
+
+ {tutorials?.length === 0 && (
+
+ )}
+
+ );
+}
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index f08d85b..7f12ebf 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -1,5 +1,30 @@
# Tennis Training Hub - 变更日志
+## v3.0.0 (2026-03-14)
+
+### 新增功能
+
+- **训练视频教程库**:分类浏览(正手/反手/发球/截击/脚步/体能),含要点说明和常见错误
+- **教程自评系统**:星级自评、学习笔记、已学标记、学习进度追踪
+- **训练提醒通知**:支持训练/打卡/分析多类型提醒,自定义时间和重复日期
+- **浏览器通知推送**:Notification API集成,权限管理和状态提示
+- **通知记录管理**:未读计数、全部标记已读、历史记录浏览
+- **文案优化**:去除“在家”等冗余描述,简化为直接信息反馈
+
+### 数据库变更
+
+- 新增 `tutorial_videos` 表(教程视频库)
+- 新增 `tutorial_progress` 表(学习进度追踪)
+- 新增 `training_reminders` 表(训练提醒设置)
+- 新增 `notification_log` 表(通知记录)
+
+### 测试
+
+- 测试用例从47个增加到65个
+- 新增教程库、提醒、通知相关测试
+
+---
+
## v2.0.0 (2026-03-14)
### 新增功能
diff --git a/docs/FEATURES.md b/docs/FEATURES.md
index 5bb7efe..828f3d2 100644
--- a/docs/FEATURES.md
+++ b/docs/FEATURES.md
@@ -53,6 +53,17 @@
| F-030 | 移动端全面适配 | 已完成 | v2.0 | 响应式设计、安全区域、触摸优化 |
| F-031 | 手机摄像头优化 | 已完成 | v2.0 | 前后摄像头切换、自适应分辨率 |
+### v3.0 新增功能
+
+| 编号 | 功能 | 状态 | 版本 | 说明 |
+|------|------|------|------|------|
+| F-032 | 训练视频教程库 | 已完成 | v3.0 | 分类浏览、要点说明、常见错误、学习进度 |
+| F-033 | 教程自评系统 | 已完成 | v3.0 | 星级自评、学习笔记、已学标记 |
+| F-034 | 训练提醒通知 | 已完成 | v3.0 | 多类型提醒、自定义时间和重复日期 |
+| F-035 | 浏览器通知推送 | 已完成 | v3.0 | Notification API集成、权限管理 |
+| F-036 | 通知记录管理 | 已完成 | v3.0 | 未读计数、全部已读、历史记录 |
+| F-037 | 去除冗余文字 | 已完成 | v3.0 | 简化UI文案,直接信息反馈 |
+
## 开发时间线
| 日期 | 版本 | 里程碑 |
@@ -61,6 +72,7 @@
| 2026-03-14 | v1.0 | 完成所有核心页面、MediaPipe集成、NTRP评分 |
| 2026-03-14 | v2.0 | 添加排行榜、打卡、徽章、实时摄像头、在线录制 |
| 2026-03-14 | v2.0 | 移动端适配、测试套件、文档编写 |
+| 2026-03-14 | v3.0 | 教程库、训练提醒、通知系统、文案优化 |
## 测试覆盖
@@ -76,4 +88,7 @@
| checkin | 5 | 今日状态、打卡、历史 |
| badge | 5 | 列表、检查、定义、数据完整性 |
| leaderboard | 3 | 认证、排序参数、无效参数 |
-| **总计** | **47** | **全部通过** |
+| tutorial | 4 | 列表查询、分类过滤、进度更新 |
+| reminder | 5 | 创建验证、切换、删除、认证 |
+| notification | 4 | 列表、未读计数、标记已读 |
+| **总计** | **65** | **全部通过** |
diff --git a/drizzle/0004_exotic_randall.sql b/drizzle/0004_exotic_randall.sql
new file mode 100644
index 0000000..8d4d334
--- /dev/null
+++ b/drizzle/0004_exotic_randall.sql
@@ -0,0 +1,57 @@
+CREATE TABLE `notification_log` (
+ `id` int AUTO_INCREMENT NOT NULL,
+ `userId` int NOT NULL,
+ `reminderId` int,
+ `notificationType` varchar(32) NOT NULL,
+ `title` varchar(256) NOT NULL,
+ `message` text,
+ `isRead` int DEFAULT 0,
+ `createdAt` timestamp NOT NULL DEFAULT (now()),
+ CONSTRAINT `notification_log_id` PRIMARY KEY(`id`)
+);
+--> statement-breakpoint
+CREATE TABLE `training_reminders` (
+ `id` int AUTO_INCREMENT NOT NULL,
+ `userId` int NOT NULL,
+ `reminderType` varchar(32) NOT NULL,
+ `title` varchar(256) NOT NULL,
+ `message` text,
+ `timeOfDay` varchar(5) NOT NULL,
+ `daysOfWeek` json NOT NULL,
+ `isActive` int DEFAULT 1,
+ `lastTriggered` timestamp,
+ `createdAt` timestamp NOT NULL DEFAULT (now()),
+ `updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
+ CONSTRAINT `training_reminders_id` PRIMARY KEY(`id`)
+);
+--> statement-breakpoint
+CREATE TABLE `tutorial_progress` (
+ `id` int AUTO_INCREMENT NOT NULL,
+ `userId` int NOT NULL,
+ `tutorialId` int NOT NULL,
+ `watched` int DEFAULT 0,
+ `comparisonVideoId` int,
+ `selfScore` float,
+ `notes` text,
+ `createdAt` timestamp NOT NULL DEFAULT (now()),
+ `updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
+ CONSTRAINT `tutorial_progress_id` PRIMARY KEY(`id`)
+);
+--> statement-breakpoint
+CREATE TABLE `tutorial_videos` (
+ `id` int AUTO_INCREMENT NOT NULL,
+ `title` varchar(256) NOT NULL,
+ `category` varchar(64) NOT NULL,
+ `skillLevel` enum('beginner','intermediate','advanced') DEFAULT 'beginner',
+ `description` text,
+ `keyPoints` json,
+ `commonMistakes` json,
+ `videoUrl` text,
+ `thumbnailUrl` text,
+ `duration` int,
+ `sortOrder` int DEFAULT 0,
+ `isPublished` int DEFAULT 1,
+ `createdAt` timestamp NOT NULL DEFAULT (now()),
+ `updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
+ CONSTRAINT `tutorial_videos_id` PRIMARY KEY(`id`)
+);
diff --git a/drizzle/meta/0004_snapshot.json b/drizzle/meta/0004_snapshot.json
new file mode 100644
index 0000000..c81774f
--- /dev/null
+++ b/drizzle/meta/0004_snapshot.json
@@ -0,0 +1,1233 @@
+{
+ "version": "5",
+ "dialect": "mysql",
+ "id": "7ad15229-2bf8-4777-8cac-bd8fddf7cc6b",
+ "prevId": "0892fd57-f758-43a7-a72d-e372aca4d4e3",
+ "tables": {
+ "daily_checkins": {
+ "name": "daily_checkins",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "checkinDate": {
+ "name": "checkinDate",
+ "type": "varchar(10)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "streakCount": {
+ "name": "streakCount",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "notes": {
+ "name": "notes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "minutesTrained": {
+ "name": "minutesTrained",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "daily_checkins_id": {
+ "name": "daily_checkins_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "notification_log": {
+ "name": "notification_log",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "reminderId": {
+ "name": "reminderId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "notificationType": {
+ "name": "notificationType",
+ "type": "varchar(32)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "varchar(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message": {
+ "name": "message",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "isRead": {
+ "name": "isRead",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "notification_log_id": {
+ "name": "notification_log_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "pose_analyses": {
+ "name": "pose_analyses",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "videoId": {
+ "name": "videoId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "overallScore": {
+ "name": "overallScore",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "poseMetrics": {
+ "name": "poseMetrics",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "detectedIssues": {
+ "name": "detectedIssues",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "corrections": {
+ "name": "corrections",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "exerciseType": {
+ "name": "exerciseType",
+ "type": "varchar(64)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "framesAnalyzed": {
+ "name": "framesAnalyzed",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "shotCount": {
+ "name": "shotCount",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "avgSwingSpeed": {
+ "name": "avgSwingSpeed",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "maxSwingSpeed": {
+ "name": "maxSwingSpeed",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "totalMovementDistance": {
+ "name": "totalMovementDistance",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "strokeConsistency": {
+ "name": "strokeConsistency",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "footworkScore": {
+ "name": "footworkScore",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "fluidityScore": {
+ "name": "fluidityScore",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "keyMoments": {
+ "name": "keyMoments",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "movementTrajectory": {
+ "name": "movementTrajectory",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "pose_analyses_id": {
+ "name": "pose_analyses_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "rating_history": {
+ "name": "rating_history",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "rating": {
+ "name": "rating",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "reason": {
+ "name": "reason",
+ "type": "varchar(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "dimensionScores": {
+ "name": "dimensionScores",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "analysisId": {
+ "name": "analysisId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "rating_history_id": {
+ "name": "rating_history_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "training_plans": {
+ "name": "training_plans",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "varchar(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "skillLevel": {
+ "name": "skillLevel",
+ "type": "enum('beginner','intermediate','advanced')",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "durationDays": {
+ "name": "durationDays",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 7
+ },
+ "exercises": {
+ "name": "exercises",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "isActive": {
+ "name": "isActive",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "adjustmentNotes": {
+ "name": "adjustmentNotes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "version": {
+ "name": "version",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "training_plans_id": {
+ "name": "training_plans_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "training_records": {
+ "name": "training_records",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "planId": {
+ "name": "planId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "exerciseName": {
+ "name": "exerciseName",
+ "type": "varchar(128)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "durationMinutes": {
+ "name": "durationMinutes",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "completed": {
+ "name": "completed",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "notes": {
+ "name": "notes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "poseScore": {
+ "name": "poseScore",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "trainingDate": {
+ "name": "trainingDate",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "training_records_id": {
+ "name": "training_records_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "training_reminders": {
+ "name": "training_reminders",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "reminderType": {
+ "name": "reminderType",
+ "type": "varchar(32)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "varchar(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message": {
+ "name": "message",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "timeOfDay": {
+ "name": "timeOfDay",
+ "type": "varchar(5)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "daysOfWeek": {
+ "name": "daysOfWeek",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "isActive": {
+ "name": "isActive",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 1
+ },
+ "lastTriggered": {
+ "name": "lastTriggered",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "training_reminders_id": {
+ "name": "training_reminders_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "training_videos": {
+ "name": "training_videos",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "varchar(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "fileKey": {
+ "name": "fileKey",
+ "type": "varchar(512)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "format": {
+ "name": "format",
+ "type": "varchar(16)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "fileSize": {
+ "name": "fileSize",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "duration": {
+ "name": "duration",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "exerciseType": {
+ "name": "exerciseType",
+ "type": "varchar(64)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "analysisStatus": {
+ "name": "analysisStatus",
+ "type": "enum('pending','analyzing','completed','failed')",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "training_videos_id": {
+ "name": "training_videos_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "tutorial_progress": {
+ "name": "tutorial_progress",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tutorialId": {
+ "name": "tutorialId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "watched": {
+ "name": "watched",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "comparisonVideoId": {
+ "name": "comparisonVideoId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "selfScore": {
+ "name": "selfScore",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "notes": {
+ "name": "notes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "tutorial_progress_id": {
+ "name": "tutorial_progress_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "tutorial_videos": {
+ "name": "tutorial_videos",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "title": {
+ "name": "title",
+ "type": "varchar(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "category": {
+ "name": "category",
+ "type": "varchar(64)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "skillLevel": {
+ "name": "skillLevel",
+ "type": "enum('beginner','intermediate','advanced')",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'beginner'"
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "keyPoints": {
+ "name": "keyPoints",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "commonMistakes": {
+ "name": "commonMistakes",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "videoUrl": {
+ "name": "videoUrl",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "thumbnailUrl": {
+ "name": "thumbnailUrl",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "duration": {
+ "name": "duration",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "sortOrder": {
+ "name": "sortOrder",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "isPublished": {
+ "name": "isPublished",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 1
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "tutorial_videos_id": {
+ "name": "tutorial_videos_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "user_badges": {
+ "name": "user_badges",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "badgeKey": {
+ "name": "badgeKey",
+ "type": "varchar(64)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "earnedAt": {
+ "name": "earnedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "user_badges_id": {
+ "name": "user_badges_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "username_accounts": {
+ "name": "username_accounts",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "username": {
+ "name": "username",
+ "type": "varchar(64)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "username_accounts_id": {
+ "name": "username_accounts_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "username_accounts_username_unique": {
+ "name": "username_accounts_username_unique",
+ "columns": [
+ "username"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "users": {
+ "name": "users",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "openId": {
+ "name": "openId",
+ "type": "varchar(64)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "varchar(320)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "loginMethod": {
+ "name": "loginMethod",
+ "type": "varchar(64)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "enum('user','admin')",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'user'"
+ },
+ "skillLevel": {
+ "name": "skillLevel",
+ "type": "enum('beginner','intermediate','advanced')",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'beginner'"
+ },
+ "trainingGoals": {
+ "name": "trainingGoals",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "ntrpRating": {
+ "name": "ntrpRating",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 1.5
+ },
+ "totalSessions": {
+ "name": "totalSessions",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "totalMinutes": {
+ "name": "totalMinutes",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "currentStreak": {
+ "name": "currentStreak",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "longestStreak": {
+ "name": "longestStreak",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "totalShots": {
+ "name": "totalShots",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ },
+ "lastSignedIn": {
+ "name": "lastSignedIn",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "users_id": {
+ "name": "users_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "users_openId_unique": {
+ "name": "users_openId_unique",
+ "columns": [
+ "openId"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ }
+ },
+ "views": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "tables": {},
+ "indexes": {}
+ }
+}
\ No newline at end of file
diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json
index 29c2b9c..324c54e 100644
--- a/drizzle/meta/_journal.json
+++ b/drizzle/meta/_journal.json
@@ -29,6 +29,13 @@
"when": 1773488765349,
"tag": "0003_married_iron_lad",
"breakpoints": true
+ },
+ {
+ "idx": 4,
+ "version": "5",
+ "when": 1773490358606,
+ "tag": "0004_exotic_randall",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/drizzle/schema.ts b/drizzle/schema.ts
index 3615ca5..5d19678 100644
--- a/drizzle/schema.ts
+++ b/drizzle/schema.ts
@@ -222,3 +222,82 @@ export const userBadges = mysqlTable("user_badges", {
export type UserBadge = typeof userBadges.$inferSelect;
export type InsertUserBadge = typeof userBadges.$inferInsert;
+
+/**
+ * Tutorial video library - professional coaching reference videos
+ */
+export const tutorialVideos = mysqlTable("tutorial_videos", {
+ id: int("id").autoincrement().primaryKey(),
+ title: varchar("title", { length: 256 }).notNull(),
+ category: varchar("category", { length: 64 }).notNull(),
+ skillLevel: mysqlEnum("skillLevel", ["beginner", "intermediate", "advanced"]).default("beginner"),
+ description: text("description"),
+ keyPoints: json("keyPoints"),
+ commonMistakes: json("commonMistakes"),
+ videoUrl: text("videoUrl"),
+ thumbnailUrl: text("thumbnailUrl"),
+ duration: int("duration"),
+ sortOrder: int("sortOrder").default(0),
+ isPublished: int("isPublished").default(1),
+ createdAt: timestamp("createdAt").defaultNow().notNull(),
+ updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
+});
+
+export type TutorialVideo = typeof tutorialVideos.$inferSelect;
+export type InsertTutorialVideo = typeof tutorialVideos.$inferInsert;
+
+/**
+ * User tutorial progress tracking
+ */
+export const tutorialProgress = mysqlTable("tutorial_progress", {
+ id: int("id").autoincrement().primaryKey(),
+ userId: int("userId").notNull(),
+ tutorialId: int("tutorialId").notNull(),
+ watched: int("watched").default(0),
+ comparisonVideoId: int("comparisonVideoId"),
+ selfScore: float("selfScore"),
+ notes: text("notes"),
+ createdAt: timestamp("createdAt").defaultNow().notNull(),
+ updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
+});
+
+export type TutorialProgress = typeof tutorialProgress.$inferSelect;
+export type InsertTutorialProgress = typeof tutorialProgress.$inferInsert;
+
+/**
+ * Training reminders
+ */
+export const trainingReminders = mysqlTable("training_reminders", {
+ id: int("id").autoincrement().primaryKey(),
+ userId: int("userId").notNull(),
+ reminderType: varchar("reminderType", { length: 32 }).notNull(),
+ title: varchar("title", { length: 256 }).notNull(),
+ message: text("message"),
+ timeOfDay: varchar("timeOfDay", { length: 5 }).notNull(),
+ daysOfWeek: json("daysOfWeek").notNull(),
+ isActive: int("isActive").default(1),
+ lastTriggered: timestamp("lastTriggered"),
+ createdAt: timestamp("createdAt").defaultNow().notNull(),
+ updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
+});
+
+export type TrainingReminder = typeof trainingReminders.$inferSelect;
+export type InsertTrainingReminder = typeof trainingReminders.$inferInsert;
+
+/**
+ * Notification log
+ */
+export const notificationLog = mysqlTable("notification_log", {
+ id: int("id").autoincrement().primaryKey(),
+ userId: int("userId").notNull(),
+ reminderId: int("reminderId"),
+ notificationType: varchar("notificationType", { length: 32 }).notNull(),
+ title: varchar("title", { length: 256 }).notNull(),
+ message: text("message"),
+ isRead: int("isRead").default(0),
+ createdAt: timestamp("createdAt").defaultNow().notNull(),
+});
+
+export type NotificationLogEntry = typeof notificationLog.$inferSelect;
+export type InsertNotificationLog = typeof notificationLog.$inferInsert;
+
diff --git a/server/db.ts b/server/db.ts
index 32b7de5..b0eccb2 100644
--- a/server/db.ts
+++ b/server/db.ts
@@ -10,6 +10,10 @@ import {
ratingHistory, InsertRatingHistory,
dailyCheckins, InsertDailyCheckin,
userBadges, InsertUserBadge,
+ tutorialVideos, InsertTutorialVideo,
+ tutorialProgress, InsertTutorialProgress,
+ trainingReminders, InsertTrainingReminder,
+ notificationLog, InsertNotificationLog,
} from "../drizzle/schema";
import { ENV } from './_core/env';
@@ -429,6 +433,233 @@ export async function getLeaderboard(sortBy: "ntrpRating" | "totalMinutes" | "to
}).from(users).orderBy(desc(sortColumn)).limit(limit);
}
+// ===== TUTORIAL OPERATIONS =====
+
+export const TUTORIAL_SEED_DATA: Omit[] = [
+ {
+ title: "正手击球基础",
+ category: "forehand",
+ skillLevel: "beginner",
+ description: "学习正手击球的基本站位、握拍方式和挥拍轨迹,建立稳定的正手基础。",
+ keyPoints: JSON.stringify(["东方式或半西方式握拍", "侧身引拍,肩膀转动90度", "从低到高的挥拍轨迹", "随挥至对侧肩膀", "重心转移从后脚到前脚"]),
+ commonMistakes: JSON.stringify(["手腕过度发力", "没有转体", "击球点太靠后", "随挥不充分"]),
+ duration: 300,
+ sortOrder: 1,
+ },
+ {
+ title: "反手击球基础",
+ category: "backhand",
+ skillLevel: "beginner",
+ description: "掌握单手和双手反手的核心技术,包括握拍转换和击球时机。",
+ keyPoints: JSON.stringify(["双手反手更适合初学者", "早引拍,肩膀充分转动", "击球点在身体前方", "保持手臂伸展"]),
+ commonMistakes: JSON.stringify(["只用手臂发力", "击球点太迟", "缺少随挥", "脚步不到位"]),
+ duration: 300,
+ sortOrder: 2,
+ },
+ {
+ title: "发球技术",
+ category: "serve",
+ skillLevel: "beginner",
+ description: "从抛球、引拍到击球的完整发球动作分解与练习。",
+ keyPoints: JSON.stringify(["稳定的抛球是关键", "大陆式握拍", "引拍时身体充分弓身", "最高点击球", "手腕内旋加速"]),
+ commonMistakes: JSON.stringify(["抛球不稳定", "手臂弯曲击球", "重心没有向前", "发力时机不对"]),
+ duration: 360,
+ sortOrder: 3,
+ },
+ {
+ title: "截击技术",
+ category: "volley",
+ skillLevel: "intermediate",
+ description: "网前截击的站位、准备姿势和击球技巧。",
+ keyPoints: JSON.stringify(["分腿弯膝准备姿势", "拍头保持在视线前方", "短促的击球动作", "步伐迎向球"]),
+ commonMistakes: JSON.stringify(["挥拍幅度太大", "站位太远", "拍面角度不对", "重心太高"]),
+ duration: 240,
+ sortOrder: 4,
+ },
+ {
+ title: "脚步移动训练",
+ category: "footwork",
+ skillLevel: "beginner",
+ description: "网球基础脚步训练,包括分步、交叉步、滑步和回位。",
+ keyPoints: JSON.stringify(["分步判断球的方向", "交叉步快速移动", "小碎步调整位置", "击球后快速回中"]),
+ commonMistakes: JSON.stringify(["脚步懒散不移动", "重心太高", "回位太慢", "没有分步"]),
+ duration: 240,
+ sortOrder: 5,
+ },
+ {
+ title: "正手上旋",
+ category: "forehand",
+ skillLevel: "intermediate",
+ description: "掌握正手上旋球的发力技巧和拍面角度控制。",
+ keyPoints: JSON.stringify(["半西方式或西方式握拍", "从低到高的刷球动作", "加速手腕内旋", "随挥结束在头部上方"]),
+ commonMistakes: JSON.stringify(["拍面太开放", "没有刷球动作", "随挥不充分"]),
+ duration: 300,
+ sortOrder: 6,
+ },
+ {
+ title: "发球变化(切削/上旋)",
+ category: "serve",
+ skillLevel: "advanced",
+ description: "高级发球技术,包括切削发球和Kick发球的动作要领。",
+ keyPoints: JSON.stringify(["切削发球:侧旋切球", "Kick发球:从下到上刷球", "抛球位置根据发球类型调整", "手腕加速是关键"]),
+ commonMistakes: JSON.stringify(["抛球位置没有变化", "旋转不足", "发力方向错误"]),
+ duration: 360,
+ sortOrder: 7,
+ },
+ {
+ title: "影子挥拍练习",
+ category: "shadow",
+ skillLevel: "beginner",
+ description: "不需要球的挥拍练习,专注于动作轨迹和肌肉记忆。",
+ keyPoints: JSON.stringify(["慢动作分解每个环节", "关注脚步和重心转移", "对着镜子检查姿势", "逐渐加快速度"]),
+ commonMistakes: JSON.stringify(["动作太快不规范", "忽略脚步", "没有完整的随挥"]),
+ duration: 180,
+ sortOrder: 8,
+ },
+ {
+ title: "墙壁练习技巧",
+ category: "wall",
+ skillLevel: "beginner",
+ description: "利用墙壁进行的各种练习方法,提升控球和反应能力。",
+ keyPoints: JSON.stringify(["保持适当距离", "控制力量和方向", "交替练习正反手", "注意脚步移动"]),
+ commonMistakes: JSON.stringify(["力量太大控制不住", "站位太近或太远", "只练习一种击球"]),
+ duration: 240,
+ sortOrder: 9,
+ },
+ {
+ title: "体能训练",
+ category: "fitness",
+ skillLevel: "beginner",
+ description: "网球专项体能训练,提升爆发力、敏捷性和耐力。",
+ keyPoints: JSON.stringify(["核心力量训练", "下肢爆发力练习", "敏捷性梯子训练", "拉伸和灵活性"]),
+ commonMistakes: JSON.stringify(["忽略热身", "训练过度", "动作不标准"]),
+ duration: 300,
+ sortOrder: 10,
+ },
+ {
+ title: "比赛策略基础",
+ category: "strategy",
+ skillLevel: "intermediate",
+ description: "网球比赛中的基本战术和策略运用。",
+ keyPoints: JSON.stringify(["控制球场深度", "变换节奏和方向", "利用对手弱点", "网前战术时机"]),
+ commonMistakes: JSON.stringify(["打法单一", "没有计划", "心态波动大"]),
+ duration: 300,
+ sortOrder: 11,
+ },
+];
+
+export async function seedTutorials() {
+ const db = await getDb();
+ if (!db) return;
+ const existing = await db.select().from(tutorialVideos).limit(1);
+ if (existing.length > 0) return; // Already seeded
+ for (const t of TUTORIAL_SEED_DATA) {
+ await db.insert(tutorialVideos).values(t);
+ }
+}
+
+export async function getTutorials(category?: string, skillLevel?: string) {
+ const db = await getDb();
+ if (!db) return [];
+ let conditions = [eq(tutorialVideos.isPublished, 1)];
+ if (category) conditions.push(eq(tutorialVideos.category, category));
+ if (skillLevel) conditions.push(eq(tutorialVideos.skillLevel, skillLevel as any));
+ return db.select().from(tutorialVideos).where(and(...conditions)).orderBy(tutorialVideos.sortOrder);
+}
+
+export async function getTutorialById(id: number) {
+ const db = await getDb();
+ if (!db) return undefined;
+ const result = await db.select().from(tutorialVideos).where(eq(tutorialVideos.id, id)).limit(1);
+ return result.length > 0 ? result[0] : undefined;
+}
+
+export async function getUserTutorialProgress(userId: number) {
+ const db = await getDb();
+ if (!db) return [];
+ return db.select().from(tutorialProgress).where(eq(tutorialProgress.userId, userId));
+}
+
+export async function updateTutorialProgress(userId: number, tutorialId: number, data: { watched?: number; selfScore?: number; notes?: string; comparisonVideoId?: number }) {
+ const db = await getDb();
+ if (!db) return;
+ const existing = await db.select().from(tutorialProgress)
+ .where(and(eq(tutorialProgress.userId, userId), eq(tutorialProgress.tutorialId, tutorialId)))
+ .limit(1);
+ if (existing.length > 0) {
+ await db.update(tutorialProgress).set(data).where(eq(tutorialProgress.id, existing[0].id));
+ } else {
+ await db.insert(tutorialProgress).values({ userId, tutorialId, ...data });
+ }
+}
+
+// ===== TRAINING REMINDER OPERATIONS =====
+
+export async function getUserReminders(userId: number) {
+ const db = await getDb();
+ if (!db) return [];
+ return db.select().from(trainingReminders).where(eq(trainingReminders.userId, userId)).orderBy(desc(trainingReminders.createdAt));
+}
+
+export async function createReminder(data: InsertTrainingReminder) {
+ const db = await getDb();
+ if (!db) throw new Error("Database not available");
+ const result = await db.insert(trainingReminders).values(data);
+ return result[0].insertId;
+}
+
+export async function updateReminder(reminderId: number, userId: number, data: Partial) {
+ const db = await getDb();
+ if (!db) return;
+ await db.update(trainingReminders).set(data).where(and(eq(trainingReminders.id, reminderId), eq(trainingReminders.userId, userId)));
+}
+
+export async function deleteReminder(reminderId: number, userId: number) {
+ const db = await getDb();
+ if (!db) return;
+ await db.delete(trainingReminders).where(and(eq(trainingReminders.id, reminderId), eq(trainingReminders.userId, userId)));
+}
+
+export async function toggleReminder(reminderId: number, userId: number, isActive: number) {
+ const db = await getDb();
+ if (!db) return;
+ await db.update(trainingReminders).set({ isActive }).where(and(eq(trainingReminders.id, reminderId), eq(trainingReminders.userId, userId)));
+}
+
+// ===== NOTIFICATION OPERATIONS =====
+
+export async function getUserNotifications(userId: number, limit = 50) {
+ const db = await getDb();
+ if (!db) return [];
+ return db.select().from(notificationLog).where(eq(notificationLog.userId, userId)).orderBy(desc(notificationLog.createdAt)).limit(limit);
+}
+
+export async function createNotification(data: InsertNotificationLog) {
+ const db = await getDb();
+ if (!db) return;
+ await db.insert(notificationLog).values(data);
+}
+
+export async function markNotificationRead(notificationId: number, userId: number) {
+ const db = await getDb();
+ if (!db) return;
+ await db.update(notificationLog).set({ isRead: 1 }).where(and(eq(notificationLog.id, notificationId), eq(notificationLog.userId, userId)));
+}
+
+export async function markAllNotificationsRead(userId: number) {
+ const db = await getDb();
+ if (!db) return;
+ await db.update(notificationLog).set({ isRead: 1 }).where(eq(notificationLog.userId, userId));
+}
+
+export async function getUnreadNotificationCount(userId: number) {
+ const db = await getDb();
+ if (!db) return 0;
+ const result = await db.select({ count: sql`count(*)` }).from(notificationLog)
+ .where(and(eq(notificationLog.userId, userId), eq(notificationLog.isRead, 0)));
+ return result[0]?.count || 0;
+}
+
// ===== STATS HELPERS =====
export async function getUserStats(userId: number) {
diff --git a/server/features.test.ts b/server/features.test.ts
index 4022e10..e406266 100644
--- a/server/features.test.ts
+++ b/server/features.test.ts
@@ -554,3 +554,222 @@ describe("BADGE_DEFINITIONS via badge.definitions endpoint", () => {
expect(badges.length).toBeGreaterThanOrEqual(20);
});
});
+
+// ===== TUTORIAL TESTS =====
+
+describe("tutorial.list", () => {
+ it("works without authentication (public)", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+
+ try {
+ const result = await caller.tutorial.list({});
+ expect(Array.isArray(result)).toBe(true);
+ } catch (e: any) {
+ // DB error expected, but should not be auth error
+ expect(e.code).not.toBe("UNAUTHORIZED");
+ }
+ });
+
+ it("accepts category filter", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+
+ try {
+ await caller.tutorial.list({ category: "forehand" });
+ } catch (e: any) {
+ expect(e.message).not.toContain("invalid_type");
+ }
+ });
+
+ it("accepts skillLevel filter", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+
+ try {
+ await caller.tutorial.list({ skillLevel: "beginner" });
+ } catch (e: any) {
+ expect(e.message).not.toContain("invalid_type");
+ }
+ });
+});
+
+describe("tutorial.progress", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(caller.tutorial.progress()).rejects.toThrow();
+ });
+});
+
+describe("tutorial.updateProgress input validation", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(
+ caller.tutorial.updateProgress({ tutorialId: 1 })
+ ).rejects.toThrow();
+ });
+
+ it("requires tutorialId", async () => {
+ const user = createTestUser();
+ const { ctx } = createMockContext(user);
+ const caller = appRouter.createCaller(ctx);
+
+ await expect(
+ caller.tutorial.updateProgress({ tutorialId: undefined as any })
+ ).rejects.toThrow();
+ });
+
+ it("accepts optional watched, selfScore, notes", async () => {
+ const user = createTestUser();
+ const { ctx } = createMockContext(user);
+ const caller = appRouter.createCaller(ctx);
+
+ try {
+ await caller.tutorial.updateProgress({
+ tutorialId: 1,
+ watched: 1,
+ selfScore: 4,
+ notes: "Great tutorial",
+ });
+ } catch (e: any) {
+ expect(e.message).not.toContain("invalid_type");
+ }
+ });
+});
+
+// ===== REMINDER TESTS =====
+
+describe("reminder.list", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(caller.reminder.list()).rejects.toThrow();
+ });
+});
+
+describe("reminder.create input validation", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(
+ caller.reminder.create({
+ reminderType: "training",
+ title: "Test",
+ timeOfDay: "08:00",
+ daysOfWeek: [1, 2, 3],
+ })
+ ).rejects.toThrow();
+ });
+
+ it("accepts empty title (no min validation on server)", async () => {
+ const user = createTestUser();
+ const { ctx } = createMockContext(user);
+ const caller = appRouter.createCaller(ctx);
+
+ try {
+ await caller.reminder.create({
+ reminderType: "training",
+ title: "",
+ timeOfDay: "08:00",
+ daysOfWeek: [1],
+ });
+ } catch (e: any) {
+ // DB error expected, but input validation should pass
+ expect(e.message).not.toContain("invalid_type");
+ }
+ });
+
+ it("accepts any string as reminderType (no enum validation on server)", async () => {
+ const user = createTestUser();
+ const { ctx } = createMockContext(user);
+ const caller = appRouter.createCaller(ctx);
+
+ try {
+ await caller.reminder.create({
+ reminderType: "custom_type",
+ title: "Test",
+ timeOfDay: "08:00",
+ daysOfWeek: [1],
+ });
+ } catch (e: any) {
+ expect(e.message).not.toContain("invalid_type");
+ }
+ });
+
+ it("accepts valid reminder creation", async () => {
+ const user = createTestUser();
+ const { ctx } = createMockContext(user);
+ const caller = appRouter.createCaller(ctx);
+
+ try {
+ await caller.reminder.create({
+ reminderType: "training",
+ title: "Morning Training",
+ message: "Time to practice!",
+ timeOfDay: "08:00",
+ daysOfWeek: [1, 2, 3, 4, 5],
+ });
+ } catch (e: any) {
+ expect(e.message).not.toContain("invalid_type");
+ expect(e.message).not.toContain("invalid_enum_value");
+ }
+ });
+});
+
+describe("reminder.toggle input validation", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(
+ caller.reminder.toggle({ reminderId: 1, isActive: 1 })
+ ).rejects.toThrow();
+ });
+});
+
+describe("reminder.delete input validation", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(
+ caller.reminder.delete({ reminderId: 1 })
+ ).rejects.toThrow();
+ });
+});
+
+// ===== NOTIFICATION TESTS =====
+
+describe("notification.list", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(caller.notification.list()).rejects.toThrow();
+ });
+});
+
+describe("notification.unreadCount", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(caller.notification.unreadCount()).rejects.toThrow();
+ });
+});
+
+describe("notification.markRead input validation", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(
+ caller.notification.markRead({ notificationId: 1 })
+ ).rejects.toThrow();
+ });
+});
+
+describe("notification.markAllRead", () => {
+ it("requires authentication", async () => {
+ const { ctx } = createMockContext(null);
+ const caller = appRouter.createCaller(ctx);
+ await expect(caller.notification.markAllRead()).rejects.toThrow();
+ });
+});
diff --git a/server/routers.ts b/server/routers.ts
index cfc96de..354341c 100644
--- a/server/routers.ts
+++ b/server/routers.ts
@@ -471,6 +471,120 @@ ${recentScores.length > 0 ? `- 用户最近的分析数据: ${JSON.stringify(rec
return db.getLeaderboard(input?.sortBy || "ntrpRating", input?.limit || 50);
}),
}),
+
+ // Tutorial video library
+ tutorial: router({
+ list: publicProcedure
+ .input(z.object({
+ category: z.string().optional(),
+ skillLevel: z.string().optional(),
+ }).optional())
+ .query(async ({ input }) => {
+ // Auto-seed tutorials on first request
+ await db.seedTutorials();
+ return db.getTutorials(input?.category, input?.skillLevel);
+ }),
+
+ get: publicProcedure
+ .input(z.object({ id: z.number() }))
+ .query(async ({ input }) => {
+ return db.getTutorialById(input.id);
+ }),
+
+ progress: protectedProcedure.query(async ({ ctx }) => {
+ return db.getUserTutorialProgress(ctx.user.id);
+ }),
+
+ updateProgress: protectedProcedure
+ .input(z.object({
+ tutorialId: z.number(),
+ watched: z.number().optional(),
+ selfScore: z.number().optional(),
+ notes: z.string().optional(),
+ comparisonVideoId: z.number().optional(),
+ }))
+ .mutation(async ({ ctx, input }) => {
+ const { tutorialId, ...data } = input;
+ await db.updateTutorialProgress(ctx.user.id, tutorialId, data);
+ return { success: true };
+ }),
+ }),
+
+ // Training reminders
+ reminder: router({
+ list: protectedProcedure.query(async ({ ctx }) => {
+ return db.getUserReminders(ctx.user.id);
+ }),
+
+ create: protectedProcedure
+ .input(z.object({
+ reminderType: z.string(),
+ title: z.string(),
+ message: z.string().optional(),
+ timeOfDay: z.string(),
+ daysOfWeek: z.array(z.number()),
+ }))
+ .mutation(async ({ ctx, input }) => {
+ const reminderId = await db.createReminder({
+ userId: ctx.user.id,
+ ...input,
+ });
+ return { reminderId };
+ }),
+
+ update: protectedProcedure
+ .input(z.object({
+ reminderId: z.number(),
+ title: z.string().optional(),
+ message: z.string().optional(),
+ timeOfDay: z.string().optional(),
+ daysOfWeek: z.array(z.number()).optional(),
+ }))
+ .mutation(async ({ ctx, input }) => {
+ const { reminderId, ...data } = input;
+ await db.updateReminder(reminderId, ctx.user.id, data);
+ return { success: true };
+ }),
+
+ delete: protectedProcedure
+ .input(z.object({ reminderId: z.number() }))
+ .mutation(async ({ ctx, input }) => {
+ await db.deleteReminder(input.reminderId, ctx.user.id);
+ return { success: true };
+ }),
+
+ toggle: protectedProcedure
+ .input(z.object({ reminderId: z.number(), isActive: z.number() }))
+ .mutation(async ({ ctx, input }) => {
+ await db.toggleReminder(input.reminderId, ctx.user.id, input.isActive);
+ return { success: true };
+ }),
+ }),
+
+ // Notifications
+ notification: router({
+ list: protectedProcedure
+ .input(z.object({ limit: z.number().default(50) }).optional())
+ .query(async ({ ctx, input }) => {
+ return db.getUserNotifications(ctx.user.id, input?.limit || 50);
+ }),
+
+ unreadCount: protectedProcedure.query(async ({ ctx }) => {
+ return db.getUnreadNotificationCount(ctx.user.id);
+ }),
+
+ markRead: protectedProcedure
+ .input(z.object({ notificationId: z.number() }))
+ .mutation(async ({ ctx, input }) => {
+ await db.markNotificationRead(input.notificationId, ctx.user.id);
+ return { success: true };
+ }),
+
+ markAllRead: protectedProcedure.mutation(async ({ ctx }) => {
+ await db.markAllNotificationsRead(ctx.user.id);
+ return { success: true };
+ }),
+ }),
});
// NTRP Rating calculation function
diff --git a/todo.md b/todo.md
index 6548feb..31fd16e 100644
--- a/todo.md
+++ b/todo.md
@@ -52,3 +52,15 @@
- [x] 功能列表清单文档
- [x] 测试驱动开发(TDD)完整测试套件
- [x] 代码规范文档
+- [x] 训练视频教程库 - 预置专业教练标准动作示范视频
+- [x] 训练视频教程库 - 分类浏览(正手/反手/发球/截击/脚步等)
+- [x] 训练视频教程库 - 用户姿势与标准动作对比功能
+- [x] 训练视频教程库 - 教程详情页(要点说明、常见错误)
+- [x] 训练提醒通知 - 用户设定训练时间
+- [x] 训练提醒通知 - 打卡提醒推送
+- [x] 训练提醒通知 - 训练计划提醒
+- [x] 训练提醒通知 - 提醒设置管理页面
+- [x] 更新导航添加新页面入口
+- [x] 编写新功能测试
+- [x] 推送更新到Gitea仓库
+- [x] 去除“在家”等冗余说明文字,简化为直接信息反馈