Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.
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
7 changes: 7 additions & 0 deletions app/Http/Controllers/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Shelf;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
Expand All @@ -15,4 +16,10 @@ public function index()
{
return view('app.pages.index');
}

public function read($shelf_slug){
$shelf = Shelf::where('slug', '=', $shelf_slug)->first();

return view('app.pages.read')->withShelf($shelf);
}
}
6 changes: 5 additions & 1 deletion optional.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ Use this space to write your solution:

```

A new table called book_meta_data with the fields meta_id, book_id, name, value.
It would have a many to one relation with the books table with any amount of name => value records.
For now every book has there names published_at, author and cover. It leaves open the option to add
more meta data names in future as meta data suggests you can attach any amount of data to books.

```
```
47 changes: 47 additions & 0 deletions resources/views/app/pages/read.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@extends('layouts.app')

<script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>

<script>
$(document).on("click", "a.book-link", function(){
var bookID = $(this).attr('data-id');

$.ajax({
type:'GET',
url:'/api/metadata/read/all',
data:'_token = <?php echo csrf_token() ?>',
success:function(data) {
if(data[bookID] !== undefined){
console.log(data[bookID]);

$('dl#metadata dd#published_at').text( data[bookID].published_at );
$('dl#metadata dd#author').text( data[bookID].author );
$('dl#metadata dd#cover').html( '<img src='+data[bookID].cover+' height="100">' );
}
}
});
});
</script>

@section('content')
<div class="row">
<div class="col-12">
<h1>{{ $shelf->name }}</h1>
<dl id="metadata">
<dt>Published</dt>
<dd id="published_at"></dd>
<dt>Author</dt>
<dd id="author"></dd>
<dt>Cover</dt>
<dd id="cover"></dd>
</dl>

<ul class="content-navigation content-navigation-icon">
@foreach($shelf->books as $book)
<li><a href="#" data-id="{{ $book->book_id }}" class="book-link">{{ $book->name }} ({{ $book->isbn }})</a></li>
@endforeach
</ul>
</div>
</div>
@endsection
6 changes: 5 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
|
*/

Route::get('/', ['as'=> 'welcome','uses' => 'WebController@index']);
Route::get('/', ['as'=> 'welcome','uses' => 'WebController@index']);

Route::get('shelf/{shelf_slug}/read/',
['as'=> 'read','uses' => 'WebController@read'])
->where('shelf_slug', '[\w\d\-\_]+');