feat: finalize academy redesign and production readiness
Align admin, community, search, library, learning and course management with the mockup. Add saved courses, download history, public community feed, instructor directory, backend search, course views, admin content tools and community moderation. Harden API and Nginx for production.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Attachment, AttachmentType, Comment, Course, Lesson, LessonMedia } from '../types';
|
||||
import { apiRequest } from './api';
|
||||
import { apiRequest, courseApi, downloadApi, DownloadRecord, InstructorSummary } from './api';
|
||||
|
||||
export const initDB = async (): Promise<void> => undefined;
|
||||
|
||||
@@ -24,6 +24,9 @@ export type ApiCourse = {
|
||||
coverImagePositionY: number;
|
||||
status: 'draft' | 'published' | 'archived';
|
||||
progress?: number;
|
||||
views?: number;
|
||||
learners?: number;
|
||||
updatedAt?: string;
|
||||
lastActivity?: string | null;
|
||||
instructor: { id: string; name: string };
|
||||
lessons: Array<{
|
||||
@@ -133,6 +136,9 @@ export const toCourse = (course: ApiCourse): Course => ({
|
||||
instructorId: course.instructor.id,
|
||||
status: course.status === 'draft' ? 'draft' : 'published',
|
||||
progress: course.progress,
|
||||
views: course.views,
|
||||
learners: course.learners,
|
||||
updatedAt: course.updatedAt,
|
||||
lastActivity: course.lastActivity || undefined,
|
||||
duration: toCourseDuration(course.lessons),
|
||||
lessons: course.lessons.map((lesson): Lesson => {
|
||||
@@ -367,4 +373,50 @@ export const saveLessonProgress = async (lessonId: string, watchedSeconds: numbe
|
||||
await apiRequest(`/lessons/${lessonId}/progress`, { method: 'PUT', body: JSON.stringify({ watchedSeconds }) });
|
||||
};
|
||||
|
||||
export const incrementViews = async (_courseId: string): Promise<void> => undefined;
|
||||
export const incrementViews = async (courseId: string): Promise<void> => {
|
||||
await courseApi.trackView(courseId).catch(() => undefined);
|
||||
};
|
||||
|
||||
export type SearchResults = {
|
||||
courses: Course[];
|
||||
paths: PublicLearningPath[];
|
||||
professors: InstructorSummary[];
|
||||
};
|
||||
|
||||
export const searchCatalog = async (query: string, area = ''): Promise<SearchResults> => {
|
||||
const params = new URLSearchParams({ q: query });
|
||||
if (area) params.set('area', area);
|
||||
const response = await apiRequest<{ data: { courses: ApiCourse[]; paths: PublicLearningPath[]; professors: InstructorSummary[] } }>(`/search?${params.toString()}`);
|
||||
return {
|
||||
...response.data,
|
||||
courses: response.data.courses.map(toCourse),
|
||||
};
|
||||
};
|
||||
|
||||
export type DownloadHistoryEntry = {
|
||||
attachment: Attachment;
|
||||
courseId: string;
|
||||
courseTitle: string;
|
||||
lessonNumber: number | null;
|
||||
downloadedAt: string;
|
||||
};
|
||||
|
||||
export const getDownloadHistory = async (): Promise<DownloadHistoryEntry[]> => {
|
||||
const response = await downloadApi.list();
|
||||
return response.data.map((record: DownloadRecord) => ({
|
||||
attachment: toAttachment(record),
|
||||
courseId: record.courseId || '',
|
||||
courseTitle: record.courseTitle || 'Curso removido',
|
||||
lessonNumber: record.lessonNumber,
|
||||
downloadedAt: record.downloadedAt,
|
||||
}));
|
||||
};
|
||||
|
||||
export const recordDownloadHistory = async (assetId: string): Promise<void> => {
|
||||
await downloadApi.record(assetId);
|
||||
};
|
||||
|
||||
export const getCommunityComments = async (limit = 100, offset = 0): Promise<Comment[]> => {
|
||||
const response = await apiRequest<{ data: ApiComment[] }>(`/community/comments?limit=${limit}&offset=${offset}`);
|
||||
return response.data.map(toComment);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user