Skip to content

Commit

Permalink
fixed too many requests - fixes #51
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDamminga committed Dec 19, 2018
1 parent 91ea953 commit 3d8dd68
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h3>Set range:</h3>
<div class="card" *ngFor="let event of events">
<div class="content">
<div class="header">
{{event.location.name}} ({{event.event_id}})
{{event.location.name}}
</div>
<div class="meta">
{{event.location.description}}
Expand All @@ -48,7 +48,7 @@ <h3>Set range:</h3>
<div class="extra content">
<div class="ui two buttons">
<div class="ui basic blue button disabled"><i class="fas fa-pen"></i></div>
<div class="ui basic red button" (click)="deleteLocation(event.location.id, event.event_id)"><i class="fas fa-trash-alt"></i></div>
<div class="ui basic red button" (click)="deleteLocation(event.location.id, event.id)"><i class="fas fa-trash-alt"></i></div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,10 @@ export class EventComponent implements OnInit {
this.adminService.getAdminById(1)
.subscribe((admin) => {
this.admin = admin[0];
this.eventService.getEventsById(this.admin.tour.id)
this.eventService.getEventsByTourId(this.admin.tour.id)
.subscribe((events) => {
events.forEach(event => {
this.locationService.getLocation(event.event.trigger.data.location_id)
.subscribe((location) => {
event.location = location[0];
this.events.push(event);
});
events.forEach(element => {
this.events.push(element[0]);
});
});
});
Expand Down
4 changes: 4 additions & 0 deletions intro-tour-admin/src/app/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class EventService {
return this.http.get(this.apiUrl + 'events/' + id);
}

public getEventsByTourId(id: number): Observable<any>{
return this.http.get(this.apiUrl + 'events-by-tour/' + id);
}

public createEvent(data): Observable<any>{
return this.http.post(this.apiUrl + 'events', data);
}
Expand Down
6 changes: 6 additions & 0 deletions intro_tour/app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ class Event extends Model
protected $fillable = [
'trigger', 'action'
];

public function question()
{
return $this->hasOne('App\Question', 'id', 'action->data->question_id');
}

public function location()
{
return $this->hasOne('App\Location', 'id', 'trigger["data"]["location_id"]');
}
}
23 changes: 23 additions & 0 deletions intro_tour/app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Http\Request;
use App\Event;
use App\EventTour;
use App\Tour;
use App\Location;
use App\Question;
use Response;
use DB;

Expand Down Expand Up @@ -111,4 +114,24 @@ public function deleteEventTour($id)

return response()->json(null, 204);
}

public function getEventsByTourId($id)
{
$eventTours = EventTour::where('tour_id', $id)->get();
$events = [];

foreach ($eventTours as $eventTour)
{
$event = Event::where('id', $eventTour->event_id)->get();
$location = Location::where('id', $event[0]->trigger['data']['location_id'])->get();
$question = Question::where('id', $event[0]->action['data']['question_id'])->with('answers')->get();

$event[0]->location = $location[0];
$event[0]->question = $question[0];

array_push($events, $event);
}

return response()->json($events, 200);
}
}
Empty file.
1 change: 1 addition & 0 deletions intro_tour/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
/* Events */
Route::get('events', 'EventController@index');
Route::get('events/{id}', 'EventController@show');
Route::get('events-by-tour/{id}', 'EventController@getEventsByTourId');
Route::post('events', 'EventController@store');
Route::post('event-tour', 'EventController@storeEventTour');
Route::delete('event-tour/{id}', 'EventController@deleteEventTour');
Expand Down

0 comments on commit 3d8dd68

Please sign in to comment.