Add full project files
This commit is contained in:
383
routes/application/academy/index.js
Normal file
383
routes/application/academy/index.js
Normal file
@@ -0,0 +1,383 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const academyController = require("../../../controllers/application/academy/academyControllers");
|
||||
const multer = require("multer");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
// const academyCategoryController = require("../../../controllers/application/academy/academyCategoryController");
|
||||
|
||||
// ==========================================
|
||||
// ⚙️ تنظیمات اولیه و دایرکتوریها
|
||||
// ==========================================
|
||||
|
||||
// اطمینان از وجود دایرکتوریها
|
||||
const ensureDir = (dir) => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
console.log("DEBUG: Created directory:", dir);
|
||||
}
|
||||
};
|
||||
|
||||
const BASE_DIR = process.cwd();
|
||||
const courseVideoDir = path.join(BASE_DIR, "storage", "courses", "videos");
|
||||
const courseImageDir = path.join(BASE_DIR, "storage", "courses", "images");
|
||||
|
||||
console.log("DEBUG: BASE_DIR:", BASE_DIR);
|
||||
console.log("DEBUG: courseVideoDir:", courseVideoDir);
|
||||
console.log("DEBUG: courseImageDir:", courseImageDir);
|
||||
|
||||
ensureDir(courseVideoDir);
|
||||
ensureDir(courseImageDir);
|
||||
|
||||
// ==========================================
|
||||
// 📁 تنظیمات آپلود فایل با Multer
|
||||
// ==========================================
|
||||
|
||||
// تنظیمات ذخیرهسازی فایلها
|
||||
const storage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
console.log("DEBUG: Multer destination - fieldname:", file.fieldname);
|
||||
// استفاده از دایرکتوری موقت برای آپلود اولیه
|
||||
const tempDir = "/tmp/modstagram-uploads";
|
||||
if (!fs.existsSync(tempDir)) {
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
}
|
||||
cb(null, tempDir);
|
||||
},
|
||||
filename: (req, file, cb) => {
|
||||
const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9);
|
||||
const filename = uniqueSuffix + path.extname(file.originalname);
|
||||
console.log("DEBUG: Generated filename:", filename);
|
||||
cb(null, filename);
|
||||
},
|
||||
});
|
||||
|
||||
// تنظیمات Multer با محدودیت حجم 500 مگابایت
|
||||
const upload = multer({
|
||||
storage: storage,
|
||||
limits: {
|
||||
fileSize: 500 * 1024 * 1024, // 500 MB
|
||||
},
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// 🏢 مسیرهای مربوط به آکادمی
|
||||
// ==========================================
|
||||
|
||||
// دریافت اطلاعات آکادمی کاربر جاری
|
||||
router.get("/", academyController.findAcademy);
|
||||
|
||||
// یافتن آکادمی با شناسه
|
||||
router.post("/findAcademyById", academyController.findAcademyById);
|
||||
|
||||
// تکمیل پروفایل آکادمی
|
||||
router.post("/academy/profile", academyController.academyProfile);
|
||||
|
||||
// ==========================================
|
||||
// 📚 مسیرهای مدیریت دورهها (Courses)
|
||||
// ==========================================
|
||||
|
||||
// ایجاد دوره جدید
|
||||
router.post("/academy/creat/course", academyController.creatCourse);
|
||||
|
||||
// ویرایش دوره
|
||||
router.patch("/academy/update/course", academyController.updateCourse);
|
||||
|
||||
// حذف دوره (تغییر وضعیت به reject)
|
||||
router.delete("/academy/delete/course", academyController.deleteCourse);
|
||||
|
||||
// دریافت لیست دورههای آکادمی جاری
|
||||
router.get("/academy/get/course", academyController.getCourse);
|
||||
|
||||
// دریافت لیست همه دورهها با فیلتر و صفحهبندی
|
||||
router.get("/academy/get/curses", academyController.getCourses);
|
||||
|
||||
// دریافت دورههای یک آکادمی خاص
|
||||
router.get("/academy/get/getAcademyCourse/:Id", academyController.getAcademyCourse);
|
||||
|
||||
// ==========================================
|
||||
// 💳 مسیرهای پرداخت و مالی
|
||||
// ==========================================
|
||||
|
||||
// پرداخت برای اشتراک پرو
|
||||
router.post("/academy/course/payment", academyController.proPayment);
|
||||
|
||||
// کالبک درگاه پرداخت زرینپال (اشتراک پرو)
|
||||
router.get("/academy/course/pro", academyController.handleCoursePaymentCallback);
|
||||
|
||||
// پرداخت برای خرید دوره
|
||||
router.post("/academy/course/payment-web", academyController.coursePayment);
|
||||
|
||||
// کالبک درگاه پرداخت زرینپال (خرید دوره)
|
||||
router.get("/academy/course/payment/verify", academyController.CoursePaymentCallback);
|
||||
|
||||
// ==========================================
|
||||
// 🎬 مسیرهای محتوای دوره (ویدیوها و فایلها)
|
||||
// ==========================================
|
||||
|
||||
// دریافت محتوای دوره (ویدیوها)
|
||||
router.get("/academy/course/content", academyController.getCourseContent);
|
||||
|
||||
// حذف ویدیو از دوره
|
||||
router.delete("/academy/course/content/video", academyController.deleteCourseVideo);
|
||||
|
||||
// ==========================================
|
||||
// 📹 مسیرهای آپلود ویدیو (۳ روش مختلف)
|
||||
// ==========================================
|
||||
|
||||
// روش 1: آپلود معمولی با Multipart (با استفاده از Multer)
|
||||
router.post(
|
||||
"/academy/course/creat/video",
|
||||
(req, res, next) => {
|
||||
console.log("===== STEP 1: Route hit =====");
|
||||
console.log("Content-Type:", req.headers["content-type"]);
|
||||
next();
|
||||
},
|
||||
(req, res, next) => {
|
||||
console.log("===== STEP 2: Before multer =====");
|
||||
next();
|
||||
},
|
||||
(req, res, next) => {
|
||||
// اجرای manual multer با try-catch
|
||||
upload.single("video")(req, res, (err) => {
|
||||
if (err) {
|
||||
console.log("===== MULTER ERROR =====");
|
||||
console.log("Error name:", err.name);
|
||||
console.log("Error message:", err.message);
|
||||
console.log("Full error:", err);
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: `خطا در آپلود: ${err.message}`,
|
||||
error: err.toString(),
|
||||
});
|
||||
}
|
||||
console.log("===== STEP 3: Multer completed successfully =====");
|
||||
next();
|
||||
});
|
||||
},
|
||||
(req, res, next) => {
|
||||
console.log("===== STEP 4: After multer =====");
|
||||
console.log("req.file:", req.file);
|
||||
console.log("req.body:", req.body);
|
||||
|
||||
if (!req.file) {
|
||||
console.log("ERROR: No file in req.file!");
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "فایلی دریافت نشد",
|
||||
});
|
||||
}
|
||||
next();
|
||||
},
|
||||
academyController.creatCourseVideo
|
||||
);
|
||||
|
||||
// روش 2: آپلود با Base64 (برای فایلهای کوچک)
|
||||
router.post(
|
||||
"/academy/course/creat/video-base64",
|
||||
academyController.creatCourseVideoBase64
|
||||
);
|
||||
|
||||
// روش 3: آپلود تکهتکه (Chunk Upload) - مناسب برای فایلهای بزرگ
|
||||
// دریافت هر تکه از ویدیو
|
||||
router.post(
|
||||
"/academy/course/creat/video-chunk",
|
||||
academyController.creatCourseVideoChunk
|
||||
);
|
||||
|
||||
// ادغام تکهها بعد از اتمام آپلود
|
||||
router.post(
|
||||
"/academy/course/creat/video-chunk/merge",
|
||||
academyController.mergeVideoChunks
|
||||
);
|
||||
|
||||
// بررسی وضعیت آپلود (برای قابلیت Resume)
|
||||
router.get("/academy/course/upload-status", academyController.getUploadStatus);
|
||||
|
||||
// ==========================================
|
||||
// ❤️ مسیرهای لایک و تعامل
|
||||
// ==========================================
|
||||
|
||||
// لایک کردن محتوای دوره
|
||||
router.post("/academy/course/like", academyController.likeCourseContent);
|
||||
|
||||
// حذف لایک (دیسلایک)
|
||||
router.post("/academy/course/dislike", academyController.dontLikeCourseContent);
|
||||
|
||||
// بررسی وضعیت لایک کاربر
|
||||
router.post("/academy/course/is-like", academyController.isLikeCourseContent);
|
||||
|
||||
// دریافت تعداد لایکهای یک دوره
|
||||
router.get(
|
||||
"/academy/course/likes-count/:courseId",
|
||||
academyController.getCourseLikesCount
|
||||
);
|
||||
|
||||
// دریافت لیست دورههای لایک شده توسط کاربر
|
||||
router.get(
|
||||
"/academy/user/liked-courses",
|
||||
academyController.getUserLikedCourses
|
||||
);
|
||||
|
||||
// ==========================================
|
||||
// 💬 مسیرهای کامنت و نظرات
|
||||
// ==========================================
|
||||
|
||||
// دریافت تعداد کل کامنتهای یک دوره
|
||||
router.get(
|
||||
"/course/:courseId/comments/count",
|
||||
academyController.getTotalCommentsCount
|
||||
);
|
||||
|
||||
// دریافت لیست کامنتهای یک دوره
|
||||
router.get("/course/:courseId/comments", academyController.getCourseComments);
|
||||
|
||||
// ایجاد کامنت جدید
|
||||
router.post("/comment/create", academyController.createComment);
|
||||
|
||||
// تغییر وضعیت کامنت (تایید/رد)
|
||||
router.patch(
|
||||
"/comment/:commentId/status",
|
||||
academyController.updateCommentStatus
|
||||
);
|
||||
|
||||
// حذف کامنت
|
||||
router.delete("/comment/:commentId/delete", academyController.deleteComment);
|
||||
|
||||
// ==========================================
|
||||
// 🛒 مسیرهای دورههای خریداری شده
|
||||
// ==========================================
|
||||
|
||||
// دریافت دورههای خریداری شده توسط کاربر جاری
|
||||
router.get(
|
||||
"/course/getUserPurchasedCourses",
|
||||
academyController.getUserPurchasedCourses
|
||||
);
|
||||
|
||||
// دریافت دورههای خریداری شده (با populate - روش بهینه)
|
||||
router.get(
|
||||
"/course/getUserPurchasedCoursesWithPopulate",
|
||||
academyController.getUserPurchasedCoursesWithPopulate
|
||||
);
|
||||
|
||||
// دریافت همه پرداختهای آکادمی
|
||||
router.get(
|
||||
"/course/getAllAcademyPayments",
|
||||
academyController.getAllAcademyPayments
|
||||
);
|
||||
|
||||
// بررسی خرید دوره توسط کاربر
|
||||
router.get(
|
||||
"/course/checkCoursePurchase/:courseId",
|
||||
academyController.checkCoursePurchase
|
||||
);
|
||||
|
||||
// ==========================================
|
||||
// 📊 مسیرهای آمار و گزارشات (STATIC)
|
||||
// ==========================================
|
||||
|
||||
// آمار پرداختها
|
||||
router.get("/payments/stats", academyController.getPaymentStats);
|
||||
|
||||
// آمار دورهها
|
||||
router.get("/courses/stats", academyController.getCourseStats);
|
||||
|
||||
// آمار دورههای خریداری شده
|
||||
router.get("/purchased/stats", academyController.getPurchasedStats);
|
||||
|
||||
// آمار آکادمیها
|
||||
router.get("/academies/stats", academyController.getAcademyStats);
|
||||
|
||||
// ==========================================
|
||||
// ⚙️ مسیرهای تنظیمات (Settings)
|
||||
// ==========================================
|
||||
|
||||
// دریافت همه تنظیمات
|
||||
router.get("/settings/all", academyController.getAllSettings);
|
||||
router.get("/settings", academyController.getAllSettings);
|
||||
|
||||
// بهروزرسانی همه تنظیمات
|
||||
router.put("/settings/all", academyController.updateAllSettings);
|
||||
router.put("/settings", academyController.updateAllSettings);
|
||||
|
||||
// دریافت و ویرایش قیمت دورهها
|
||||
router.get("/settings/course-prices", academyController.getCoursePrices);
|
||||
router.put("/settings/course-price", academyController.updateCoursePrice);
|
||||
|
||||
// دریافت و ویرایش مالیات
|
||||
router.get("/settings/tax", academyController.getTax);
|
||||
router.put("/settings/tax", academyController.updateTax);
|
||||
|
||||
// ==========================================
|
||||
// 🏷️ مسیرهای دستهبندی آکادمی (Categories)
|
||||
// ==========================================
|
||||
|
||||
// دریافت لیست دستهبندیها (با فیلتر و صفحهبندی)
|
||||
router.get('/categories', academyController.getAll);
|
||||
|
||||
// دریافت درخت دستهبندی (ساختار سلسلهمراتبی)
|
||||
router.get('/categories/tree', academyController.getTree);
|
||||
|
||||
// دریافت دستهبندیهای ویژه (برای نمایش در هوم پیج)
|
||||
router.get('/categories/featured', academyController.getFeatured);
|
||||
|
||||
// دریافت دستهبندی با اسلاگ (برای سئو و لینکهای زیبا)
|
||||
router.get('/categories/slug/:slug', academyController.getBySlug);
|
||||
|
||||
// دریافت یک دستهبندی با شناسه
|
||||
router.get('/categories/:id', academyController.getOne);
|
||||
|
||||
// ایجاد دستهبندی جدید
|
||||
router.post('/categories', academyController.create);
|
||||
|
||||
// ویرایش دستهبندی (هم PUT و هم PATCH پشتیبانی میشود)
|
||||
router.put('/categories/:id', academyController.update);
|
||||
router.patch('/categories/:id', academyController.update);
|
||||
|
||||
// حذف دستهبندی (سافت دیلیت - فقط غیرفعال میشود)
|
||||
router.delete('/categories/:id', academyController.remove);
|
||||
|
||||
// حذف فیزیکی دستهبندی (به همراه query string permanent=true)
|
||||
router.delete('/categories/:id/permanent', (req, res) => {
|
||||
req.query.permanent = 'true';
|
||||
academyController.remove(req, res);
|
||||
});
|
||||
|
||||
// تغییر وضعیت دستهبندی (فعال/غیرفعال)
|
||||
router.patch('/categories/:id/status', academyController.toggleStatus);
|
||||
|
||||
// افزایش تعداد دورههای دستهبندی (هر بار یک دوره جدید اضافه میشود)
|
||||
router.post('/categories/:id/increment-count', academyController.incrementCourseCount);
|
||||
|
||||
// ==========================================
|
||||
// 👑 مسیرهای مدیریتی (پنل ادمین)
|
||||
// ==========================================
|
||||
|
||||
// ------ مدیریت پرداختها ------
|
||||
router.get("/payments", academyController.getAllPayments);
|
||||
router.put("/payments/status", academyController.updatePaymentStatus);
|
||||
|
||||
// ------ مدیریت دورهها ------
|
||||
router.get("/courses", academyController.getAllCourses);
|
||||
router.get("/courses/:id", academyController.getCourseById);
|
||||
router.put("/courses/:id", academyController.updateCourse);
|
||||
router.post("/courses", academyController.createCourse);
|
||||
router.put("/academy/courses/status", academyController.updateCourseStatus);
|
||||
router.delete("/courses/:courseId", academyController.admindeleteCourse);
|
||||
|
||||
// ------ مدیریت دورههای خریداری شده ------
|
||||
router.get("/purchased", academyController.getAllPurchasedCourses);
|
||||
|
||||
// ------ مدیریت آکادمیها ------
|
||||
router.get("/academies", academyController.getAllAcademies);
|
||||
router.get("/academies/:id", academyController.getAcademyById);
|
||||
router.put("/academies/:id", academyController.updateAcademy);
|
||||
router.post("/academies", academyController.createAcademy);
|
||||
router.put("/academies/status", academyController.updateAcademyStatus);
|
||||
router.delete("/academies/:id", academyController.deleteAcademy);
|
||||
|
||||
// ==========================================
|
||||
// 📤 خروجی روتها
|
||||
// ==========================================
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user