Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions eunixmac_backend/app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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()
Expand Down
16 changes: 7 additions & 9 deletions eunixmac_backend/app/Http/Controllers/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 18 additions & 12 deletions eunixmac_frontend/src/pages/AdminBooksManagement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -433,11 +431,18 @@ const AdminBooksManagement = () => {
</Typography>
</TableCell>
<TableCell>
<Chip
label={book.category?.name}
size="small"
variant="outlined"
/>
<Box>
<Chip
label={book.category?.parent?.name || book.category?.name}
size="small"
variant="outlined"
/>
{book.category?.parent && (
<Typography variant="caption" color="text.secondary" display="block" mt={0.5}>
{book.category?.name}
</Typography>
)}
</Box>
</TableCell>
<TableCell>
<Chip
Expand Down Expand Up @@ -578,7 +583,8 @@ const AdminBooksManagement = () => {
</Grid>
<Grid item xs={6}>
<Typography variant="body2">
<strong>Category:</strong> {selectedBook.category?.name}
<strong>Category:</strong> {selectedBook.category?.parent?.name || selectedBook.category?.name}
{selectedBook.category?.parent && ` > ${selectedBook.category?.name}`}
</Typography>
</Grid>
<Grid item xs={6}>
Expand Down
8 changes: 3 additions & 5 deletions eunixmac_frontend/src/pages/UploadBook.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down