diff --git a/eunixmac_backend/app/Http/Controllers/AdminController.php b/eunixmac_backend/app/Http/Controllers/AdminController.php index b16cc76..e34852d 100644 --- a/eunixmac_backend/app/Http/Controllers/AdminController.php +++ b/eunixmac_backend/app/Http/Controllers/AdminController.php @@ -152,9 +152,9 @@ public function getDashboardStats() */ public function getBooks(Request $request) { - $query = Ad::where('category_id', 7) // Books and Media + $query = Ad::whereIn('category_id', [83, 84, 85, 86]) // Books, Past Questions, Ebooks, Publications ->whereNotNull('file_path') - ->with(['user:id,name,email', 'category:id,name']); + ->with(['user:id,name,email', 'category:id,name,parent_id', 'category.parent:id,name']); // Apply filters if ($request->filled('status')) { @@ -208,11 +208,11 @@ public function getBooks(Request $request) public function showBook(Ad $ad) { // Verify this is a book - if ($ad->category_id !== 7 || !$ad->file_path) { + if (!in_array($ad->category_id, [83, 84, 85, 86]) || !$ad->file_path) { return response()->json(['message' => 'Not a book'], 404); } - $ad->load(['user:id,name,email,phone_number', 'category:id,name']); + $ad->load(['user:id,name,email,phone_number', 'category:id,name,parent_id', 'category.parent:id,name']); // Add additional data $ad->file_size = $this->getFileSize($ad->file_path); @@ -244,7 +244,7 @@ public function showBook(Ad $ad) public function approveBook(Request $request, Ad $ad) { // Verify this is a book - if ($ad->category_id !== 7 || !$ad->file_path) { + if (!in_array($ad->category_id, [83, 84, 85, 86]) || !$ad->file_path) { return response()->json(['message' => 'Not a book'], 404); } @@ -281,7 +281,7 @@ public function rejectBook(Request $request, Ad $ad) ]); // Verify this is a book - if ($ad->category_id !== 7 || !$ad->file_path) { + if (!in_array($ad->category_id, [83, 84, 85, 86]) || !$ad->file_path) { return response()->json(['message' => 'Not a book'], 404); } @@ -320,7 +320,7 @@ public function deleteBook(Request $request, Ad $ad) ]); // Verify this is a book - if ($ad->category_id !== 7 || !$ad->file_path) { + if (!in_array($ad->category_id, [83, 84, 85, 86]) || !$ad->file_path) { return response()->json(['message' => 'Not a book'], 404); } @@ -373,15 +373,15 @@ public function deleteBook(Request $request, Ad $ad) public function getBooksStats() { $stats = [ - 'total_books' => Ad::where('category_id', 7) + 'total_books' => Ad::whereIn('category_id', [83, 84, 85, 86]) ->whereNotNull('file_path')->count(), - 'pending_approval' => Ad::where('category_id', 7) + 'pending_approval' => Ad::whereIn('category_id', [83, 84, 85, 86]) ->whereNotNull('file_path') ->where('status', 'pending_approval')->count(), - 'approved_books' => Ad::where('category_id', 7) + 'approved_books' => Ad::whereIn('category_id', [83, 84, 85, 86]) ->whereNotNull('file_path') ->where('status', 'active')->count(), - 'rejected_books' => Ad::where('category_id', 7) + 'rejected_books' => Ad::whereIn('category_id', [83, 84, 85, 86]) ->whereNotNull('file_path') ->where('status', 'rejected')->count(), 'total_sales' => Payment::where('payable_type', 'book') @@ -430,11 +430,11 @@ private function getTopAgents() { return User::where('is_agent', true) ->withCount(['ads as books_count' => function ($query) { - $query->where('category_id', 7) + $query->whereIn('category_id', [83, 84, 85, 86]) ->whereNotNull('file_path'); }]) ->with(['ads' => function ($query) { - $query->where('category_id', 7) + $query->whereIn('category_id', [83, 84, 85, 86]) ->whereNotNull('file_path'); }]) ->orderBy('books_count', 'desc') @@ -469,7 +469,7 @@ private function getTopAgents() */ private function getBooksByCategory() { - return Ad::where('category_id', 7) + return Ad::whereIn('category_id', [83, 84, 85, 86]) ->whereNotNull('file_path') ->join('categories', 'ads.category_id', '=', 'categories.id') ->selectRaw('categories.name as category_name, COUNT(*) as count') @@ -483,7 +483,7 @@ private function getBooksByCategory() */ private function getRecentUploads() { - return Ad::where('category_id', 7) + return Ad::whereIn('category_id', [83, 84, 85, 86]) ->whereNotNull('file_path') ->with(['user:id,name,email', 'category:id,name']) ->latest() diff --git a/eunixmac_backend/app/Http/Controllers/BookController.php b/eunixmac_backend/app/Http/Controllers/BookController.php index 1cde893..3c1942a 100644 --- a/eunixmac_backend/app/Http/Controllers/BookController.php +++ b/eunixmac_backend/app/Http/Controllers/BookController.php @@ -14,7 +14,7 @@ class BookController extends Controller public function index(Request $request) { $books = $request->user()->ads() - ->where('category_id', 7) // Books and Media + ->whereIn('category_id', [83, 84, 85, 86]) // Books, Past Questions, Ebooks, Publications ->whereNotNull('file_path') ->with(['category:id,name']) ->orderBy('created_at', 'desc') @@ -228,17 +228,15 @@ public function store(Request $request) private function getCategoryIdByName($categoryName) { - // Map category names to IDs based on your categories + // Map category names to IDs based on the Books category (ID 83) sub-categories $categoryMap = [ - 'Fiction Books' => 8, - 'Non-Fiction Books' => 9, - 'Music' => 10, - 'Movies' => 11, - 'TV Shows' => 12, - 'Book' => 7, // Default + 'Past Questions' => 84, + 'Ebooks' => 85, + 'Publications' => 86, + 'Books' => 83, // Default parent ]; - return $categoryMap[$categoryName] ?? 7; // Default to Books and Media category + return $categoryMap[$categoryName] ?? 83; // Default to Books parent category } public function download(Request $request, Ad $ad) diff --git a/eunixmac_frontend/src/pages/AdminBooksManagement.jsx b/eunixmac_frontend/src/pages/AdminBooksManagement.jsx index 8182478..b9fa572 100644 --- a/eunixmac_frontend/src/pages/AdminBooksManagement.jsx +++ b/eunixmac_frontend/src/pages/AdminBooksManagement.jsx @@ -93,12 +93,10 @@ const AdminBooksManagement = () => { }; const categories = [ - { id: 7, name: 'Books and Media' }, - { id: 8, name: 'Fiction Books' }, - { id: 9, name: 'Non-Fiction Books' }, - { id: 10, name: 'Music' }, - { id: 11, name: 'Movies' }, - { id: 12, name: 'TV Shows' } + { id: 83, name: 'Books' }, + { id: 84, name: 'Past Questions' }, + { id: 85, name: 'Ebooks' }, + { id: 86, name: 'Publications' } ]; useEffect(() => { @@ -433,11 +431,18 @@ const AdminBooksManagement = () => { - + + + {book.category?.parent && ( + + {book.category?.name} + + )} + { - Category: {selectedBook.category?.name} + Category: {selectedBook.category?.parent?.name || selectedBook.category?.name} + {selectedBook.category?.parent && ` > ${selectedBook.category?.name}`} diff --git a/eunixmac_frontend/src/pages/UploadBook.jsx b/eunixmac_frontend/src/pages/UploadBook.jsx index a37540d..c52ba45 100644 --- a/eunixmac_frontend/src/pages/UploadBook.jsx +++ b/eunixmac_frontend/src/pages/UploadBook.jsx @@ -55,11 +55,9 @@ const UploadBox = styled(Box)(({ theme }) => ({ const steps = ['Upload File', 'Book Details', 'Pricing & Settings', 'Review & Submit']; const bookCategories = [ - 'Fiction Books', - 'Non-Fiction Books', - 'Music', - 'Movies', - 'TV Shows' + 'Past Questions', + 'Ebooks', + 'Publications' ]; const subjectAreas = [