Skip to content

Commit

Permalink
Ostatnie poprawki
Browse files Browse the repository at this point in the history
  • Loading branch information
Prawy126 committed Jun 5, 2024
1 parent f9619f2 commit 2cc004b
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 29 deletions.
18 changes: 15 additions & 3 deletions Projekt/app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,24 @@ public function dashboard()
// Średnia cena ofert
$averageBidPrice = Bid::avg('amount');

return view('admin.dashboard', compact('users', 'announcements', 'userCount', 'announcementCount', 'userStats', 'announcementStats', 'userAnnouncements', 'averageAnnouncementsPerUser', 'averageOffersPerDay', 'averageBidPrice'));
return view('admin.dashboard', [
'users' => $users,
'announcements' => $announcements,
'userCount' => $userCount,
'announcementCount' => $announcementCount,
'userStats' => $userStats,
'announcementStats' => $announcementStats,
'userAnnouncements' => $userAnnouncements,
'averageAnnouncementsPerUser' => $averageAnnouncementsPerUser,
'averageOffersPerDay' => $averageOffersPerDay,
'averageBidPrice' => $averageBidPrice
]);

}
public function editUser($id)
{
$user = User::findOrFail($id);
return view('admin.edit_user', compact('user'));
return view('admin.edit_user', ['user' => $user]);
}

public function updateUser(Request $request, $id)
Expand Down Expand Up @@ -99,7 +111,7 @@ public function updateUser(Request $request, $id)
public function editAnnouncement($id)
{
$announcement = Announcement::findOrFail($id);
return view('admin.edit_announcement', compact('announcement'));
return view('admin.edit_announcement', ['announcement' => $announcement]);
}

public function updateAnnouncement(Request $request, $id)
Expand Down
4 changes: 2 additions & 2 deletions Projekt/app/Http/Controllers/AnnouncementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function destroy($id)
return redirect()->route('cars.index')->with('error', 'Ogłoszenie nie zostało znalezione.');
}

// Sprawdzenie, czy zalogowany użytkownik jest właścicielem ogłoszenia lub administratorem

if ((Auth::check())&&(Auth::user()->id !== $announcement->user_id && Auth::user()->role !== 'admin')) {
return redirect()->route('cars.index')->with('error', 'Nie masz uprawnień do aktualizacji tego ogłoszenia.');
}
Expand All @@ -103,7 +103,7 @@ public function edit($id)
return redirect()->route('cars.index')->with('error', 'Ogłoszenie nie zostało znalezione.');
}

// Sprawdzenie, czy zalogowany użytkownik jest właścicielem ogłoszenia lub administratorem

if ((Auth::check())&&(Auth::user()->id !== $announcement->user_id && Auth::user()->role !== 'admin')) {
return redirect()->route('cars.index')->with('error', 'Nie masz uprawnień do aktualizacji tego ogłoszenia.');
}
Expand Down
8 changes: 4 additions & 4 deletions Projekt/app/Http/Controllers/BidController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ public function store(Request $request, $announcementId)
$announcement = Announcement::findOrFail($announcementId);
$currentDateTime = now();

// Sprawdzenie, czy licytacja nie jest zakończona

if ($announcement->is_end || $announcement->end_date < $currentDateTime) {
return redirect()->route('cars.show', ['id' => $announcementId])
->withErrors(['Licytacja jest zakończona i nie można składać nowych ofert.']);
}

$highestBid = $announcement->bids()->orderBy('amount', 'desc')->first();

// Sprawdzenie, czy kwota jest większa od aktualnie najwyższej oferty lub minimalnej ceny

if ($request->amount <= $announcement->min_price || ($highestBid && $request->amount <= $highestBid->amount)) {
return redirect()->route('cars.show', ['id' => $announcementId])
->withErrors(['Kwota musi być większa niż minimalna cena i aktualnie najwyższa oferta.']);
}

// Sprawdzenie, czy użytkownik nie przebija samego siebie

if ($highestBid && $highestBid->user_id == Auth::id()) {
return redirect()->route('cars.show', ['id' => $announcementId])
->withErrors(['Nie możesz przebijać swojej własnej oferty.']);
}

// Tworzenie nowej oferty

Bid::create([
'announcement_id' => $announcementId,
'user_id' => Auth::id(),
Expand Down
7 changes: 2 additions & 5 deletions Projekt/app/Models/Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ public function photos(): HasMany

public function randomPhoto()
{
if ($this->photos->isEmpty()) {
// Zwraca domyślne zdjęcie, jeśli nie ma zdjęć
return (object) ['photo_name' => 'samochod1.png'];
}
return $this->photos->random();
return $this->photos()->inRandomOrder()->first();
}


}
4 changes: 2 additions & 2 deletions Projekt/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
return $renderException($e, $request, 'errors.400', 'Bad Request', 400);
});

/*$exceptions->render(function (QueryException $e, Request $request) use ($renderException) {
$exceptions->render(function (QueryException $e, Request $request) use ($renderException) {
return $renderException($e, $request, 'errors.500', 'Internal Server Error', 500);
});*/
});
})
->withMiddleware(function (Middleware $middleware) {
// Dodaj swoje middleware tutaj
Expand Down
6 changes: 3 additions & 3 deletions Projekt/database/seeders/AnnouncementSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function run(): void
'year' => 2019,
'mileage' => 23000.75,
'description' => 'Sprzedam szybko, cena do negocjacji.',
'end_date' => '2024-05-12',
'end_date' => '2024-06-12 14:20',
'is_end' => false,
'min_price' => 15000
],
Expand All @@ -72,7 +72,7 @@ public function run(): void
'year' => 2018,
'mileage' => 40000.80,
'description' => 'Samochód w świetnym stanie, bezwypadkowy.',
'end_date' => '2024-05-15',
'end_date' => '2024-06-15',
'is_end' => false,
'min_price' => 18000
],
Expand All @@ -83,7 +83,7 @@ public function run(): void
'year' => 2017,
'mileage' => 55000.20,
'description' => 'Sprzedam tanio, szybka transakcja.',
'end_date' => '2024-05-18',
'end_date' => '2024-07-18 20:21',
'is_end' => false,
'min_price' => 12000
]
Expand Down
4 changes: 3 additions & 1 deletion Projekt/public/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
}

.card-body{
margin-bottom: 40px;
margin-bottom: 20px;

}


Binary file added Projekt/public/img/brak.webp
Binary file not shown.
File renamed without changes.
14 changes: 8 additions & 6 deletions Projekt/resources/views/cars/oferty.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
@forelse ($cars as $car)
<div class="col-12 col-sm-6 col-lg-3">
<div class="card">
@if (!empty($car->randomPhoto()) && !empty($car->randomPhoto()->photo_name))
<img src="{{ asset('storage/' . $car->randomPhoto()->photo_name) }}" class="card-img-top"
alt="{{ $car->name }}">
@if ($photo = $car->randomPhoto())
@if (!empty($photo->photo_name))
<img src="{{ asset('storage/' . $photo->photo_name) }}" class="card-img-top" alt="{{ $car->name }}">
@else
<img src="{{ asset('img/brak.webp') }}" class="d-block w-100" alt="Brak zdjęć">
@endif
@else
<img src="img/brak.webp" class="card-img-top" alt="{{ $car->name }}">
<img src="{{ asset('img/brak.webp') }}" class="d-block w-100" alt="Brak zdjęć">
@endif

<div class="card-body">
<h5 class="card-title">{{ $car->name }}</h5>
<p class="card-text">{{ $car->description }}</p>
<a href="{{ route('cars.show', ['id' => $car->id]) }}" class="btn btn-primary">Więcej
szczegółów...</a>
<a href="{{ route('cars.show', ['id' => $car->id]) }}" class="btn btn-primary">Więcej szczegółów...</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Projekt/resources/views/errors/405.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@include('shared.html')

@include('shared.head', ['pageTitle' => 'Błąd 403'])
@include('shared.head', ['pageTitle' => 'Błąd 405'])

<style>
body{
Expand Down
4 changes: 2 additions & 2 deletions Projekt/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
Route::prefix('admin')->middleware('auth')->group(function () {
Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('admin.dashboard');
Route::get('/user/edit/{id}', [AdminController::class, 'editUser'])->name('admin.editUser');
Route::put('/user/update/{id}', [AdminController::class, 'updateUser'])->name('admin.updateUser'); // Dodaj tę trasę
Route::put('/user/update/{id}', [AdminController::class, 'updateUser'])->name('admin.updateUser');
Route::delete('/user/delete/{id}', [AdminController::class, 'deleteUser'])->name('admin.deleteUser');
Route::get('/announcement/edit/{id}', [AdminController::class, 'editAnnouncement'])->name('admin.editAnnouncement');
Route::put('/announcement/update/{id}', [AdminController::class, 'updateAnnouncement'])->name('admin.updateAnnouncement'); // Dodaj tę trasę
Route::put('/announcement/update/{id}', [AdminController::class, 'updateAnnouncement'])->name('admin.updateAnnouncement');
Route::delete('/announcement/delete/{id}', [AdminController::class, 'deleteAnnouncement'])->name('admin.deleteAnnouncement');
});

Expand Down

0 comments on commit 2cc004b

Please sign in to comment.