Commit 5917f39a authored by Andrea Ruggiero's avatar Andrea Ruggiero
Browse files

Update to support latest db

parent e0a2fb5f
Pipeline #1549 failed with stage
in 0 seconds
......@@ -6,6 +6,7 @@ namespace App\Http\Controllers;
use App\Helpers\ApiResponse;
use App\Repositories\BookingRepository;
use App\Repositories\EventRepository;
use App\Repositories\PlaceRepository;
use App\Repositories\SessionRepository;
use Illuminate\Http\Request;
......@@ -20,7 +21,7 @@ class EventController extends Controller
}
public function getEvents(EventRepository $eventRepository, BookingRepository $bookingRepository,
SessionRepository $sessionRepository, Request $request) {
SessionRepository $sessionRepository, Request $request, PlaceRepository $placeRepository) {
$events = $eventRepository->all();
$response = [];
......@@ -34,13 +35,19 @@ class EventController extends Controller
"date" => $event->date,
"start" => $event->start,
"end" => $event->end,
"place" => $event->place,
"type" => $event->type,
"theme" => $event->theme,
"capacity" => $event->capacity,
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id))
];
if ($event->place_id == null) {
$temp["place"] = "all";
} else {
$place = $placeRepository->getById($event->place_id);
$temp["place"] = $place->name;
$temp["capacity"] = $place->capacity;
}
if ($user !== null) {
$temp["hasBooked"] = $bookingRepository->getBookingByEventAndUser($user->user_id, $event->event_id) !== null;
}
......@@ -52,7 +59,7 @@ class EventController extends Controller
}
public function getBookedEvents(EventRepository $eventRepository, BookingRepository $bookingRepository,
SessionRepository $sessionRepository, Request $request) {
SessionRepository $sessionRepository, Request $request, PlaceRepository $placeRepository) {
$events = $eventRepository->all();
$response = [];
......@@ -60,19 +67,27 @@ class EventController extends Controller
foreach ($events as $event) {
if ($bookingRepository->getBookingByEventAndUser($user->user_id, $event->event_id) === null) continue;
$response[] = [
$temp = [
"id" => $event->event_id,
"title" => $event->title,
"speaker" => $event->speaker,
"date" => $event->date,
"start" => $event->start,
"end" => $event->end,
"place" => $event->place,
"type" => $event->type,
"theme" => $event->theme,
"capacity" => $event->capacity,
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id))
];
if ($event->place_id == null) {
$temp["place"] = "all";
} else {
$place = $placeRepository->getById($event->place_id);
$temp["place"] = $place->name;
$temp["capacity"] = $place->capacity;
}
$response[] = $temp;
}
return ApiResponse::success($response);
......@@ -109,7 +124,7 @@ class EventController extends Controller
}
public function getEvent($id, EventRepository $eventRepository, Request $request,
BookingRepository $bookingRepository, SessionRepository $sessionRepository) {
BookingRepository $bookingRepository, SessionRepository $sessionRepository, PlaceRepository $placeRepository) {
$event = $eventRepository->get($id);
if ($event === null) return ApiResponse::error('Evento non trovato');
......@@ -133,6 +148,17 @@ class EventController extends Controller
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id))
];
if ($event->place_id == null) {
$response["place"] = "all";
} else {
$place = $placeRepository->getById($event->place_id);
$response["place"] = $place->name;
$response["capacity"] = $place->capacity;
$response["latitude"] = $place->latitude;
$response["longitude"] = $place->longitude;
$response["address"] = $place->address;
}
if ($user !== null) {
$response["hasBooked"] = $bookingRepository->getBookingByEventAndUser($user->user_id, $event->event_id) !== null;
}
......
<?php
namespace App\Repositories;
class PlaceRepository extends BaseRepository
{
protected $table = 'places';
public function getById($id) {
return $this->db()->where('place_id', $id)->first();
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment