Skip to content

Commit b34470d

Browse files
author
Muhammad Fikri
committed
api perpus
1 parent 07dad1b commit b34470d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+6280
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.env.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
APP_NAME=Lumen
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
APP_TIMEZONE=UTC
7+
8+
LOG_CHANNEL=stack
9+
LOG_SLACK_WEBHOOK_URL=
10+
11+
DB_CONNECTION=mysql
12+
DB_HOST=127.0.0.1
13+
DB_PORT=3306
14+
DB_DATABASE=homestead
15+
DB_USERNAME=homestead
16+
DB_PASSWORD=secret
17+
18+
CACHE_DRIVER=file
19+
QUEUE_CONNECTION=sync

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor
2+
/.idea
3+
Homestead.json
4+
Homestead.yaml
5+
.env
6+
.phpunit.result.cache

.styleci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
php:
2+
preset: laravel
3+
disabled:
4+
- unused_use
5+
js: true
6+
css: true

app/Buku.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Buku extends Model
8+
{
9+
protected $table = 'buku';
10+
}

app/Console/Commands/.gitkeep

Whitespace-only changes.

app/Console/Kernel.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
//
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
//
28+
}
29+
}

app/Events/Event.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use Illuminate\Queue\SerializesModels;
6+
7+
abstract class Event
8+
{
9+
use SerializesModels;
10+
}

app/Events/ExampleEvent.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
class ExampleEvent extends Event
6+
{
7+
/**
8+
* Create a new event instance.
9+
*
10+
* @return void
11+
*/
12+
public function __construct()
13+
{
14+
//
15+
}
16+
}

app/Exceptions/Handler.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Illuminate\Auth\Access\AuthorizationException;
6+
use Illuminate\Database\Eloquent\ModelNotFoundException;
7+
use Illuminate\Validation\ValidationException;
8+
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
9+
use Symfony\Component\HttpKernel\Exception\HttpException;
10+
use Throwable;
11+
12+
class Handler extends ExceptionHandler
13+
{
14+
/**
15+
* A list of the exception types that should not be reported.
16+
*
17+
* @var array
18+
*/
19+
protected $dontReport = [
20+
AuthorizationException::class,
21+
HttpException::class,
22+
ModelNotFoundException::class,
23+
ValidationException::class,
24+
];
25+
26+
/**
27+
* Report or log an exception.
28+
*
29+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
30+
*
31+
* @param \Throwable $exception
32+
* @return void
33+
*
34+
* @throws \Exception
35+
*/
36+
public function report(Throwable $exception)
37+
{
38+
parent::report($exception);
39+
}
40+
41+
/**
42+
* Render an exception into an HTTP response.
43+
*
44+
* @param \Illuminate\Http\Request $request
45+
* @param \Throwable $exception
46+
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
47+
*
48+
* @throws \Throwable
49+
*/
50+
public function render($request, Throwable $exception)
51+
{
52+
return parent::render($request, $exception);
53+
}
54+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
use App\Buku;
5+
use Illuminate\Http\Request;
6+
7+
class BukuController extends Controller
8+
{
9+
/**
10+
* Create a new controller instance.
11+
*
12+
* @return void
13+
*/
14+
public function __construct()
15+
{
16+
//
17+
}
18+
19+
//
20+
public function index(){
21+
$buku = Buku::all();
22+
return response()->json($buku);
23+
}
24+
25+
public function create(Request $request)
26+
{
27+
$buku = new Buku;
28+
29+
$buku->judul= $request->judul;
30+
$buku->deskripsi = $request->deskripsi;
31+
$buku->penulis = $request->penulis;
32+
$buku->gambar = $request->gambar;
33+
$buku->Buku_id = $request->Buku_id;
34+
35+
$buku->save();
36+
37+
return response()->json($buku);
38+
}
39+
40+
public function show($id)
41+
{
42+
$buku = Buku::find($id);
43+
44+
return response()->json($buku);
45+
}
46+
47+
public function update(Request $request, $id)
48+
{
49+
$buku= Buku::find($id);
50+
51+
$buku->judul = $request->input('judul');
52+
$buku->deskripsi = $request->input('diskripsi');
53+
$buku->penulis = $request->input('penulis');
54+
$buku->gambar = $request->input('gambar');
55+
$buku->Buku_id = $request->input('Buku_id');
56+
57+
$buku->save();
58+
return response()->json($buku);
59+
}
60+
61+
public function destroy($id)
62+
{
63+
$buku = Buku::find($id);
64+
$buku->delete();
65+
66+
return response()->json('Buku removed successfully');
67+
}
68+
}

app/Http/Controllers/Controller.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Laravel\Lumen\Routing\Controller as BaseController;
6+
7+
class Controller extends BaseController
8+
{
9+
//
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
class ExampleController extends Controller
6+
{
7+
/**
8+
* Create a new controller instance.
9+
*
10+
* @return void
11+
*/
12+
public function __construct()
13+
{
14+
//
15+
}
16+
17+
//
18+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
use App\Kategori;
5+
use Illuminate\Http\Request;
6+
7+
class KategoriController extends Controller
8+
{
9+
/**
10+
* Create a new controller instance.
11+
*
12+
* @return void
13+
*/
14+
public function __construct()
15+
{
16+
//
17+
}
18+
19+
//
20+
public function index(){
21+
$kategori = Kategori::all();
22+
return response()->json($kategori);
23+
}
24+
25+
public function create(Request $request)
26+
{
27+
$kategori = new Kategori;
28+
29+
$kategori->judul= $request->judul;
30+
$kategori->deskripsi = $request->deskripsi;
31+
$kategori->penulis = $request->penulis;
32+
$kategori->gambar = $request->gambar;
33+
$kategori->kategori_id = $request->kategori_id;
34+
35+
$kategori->save();
36+
37+
return response()->json($kategori);
38+
}
39+
40+
public function show($id)
41+
{
42+
$kategori = Kategori::find($id);
43+
44+
return response()->json($kategori);
45+
}
46+
47+
public function update(Request $request, $id)
48+
{
49+
$kategori= Kategori::find($id);
50+
51+
$kategori->judul = $request->input('judul');
52+
$kategori->deskripsi = $request->input('diskripsi');
53+
$kategori->penulis = $request->input('penulis');
54+
$kategori->gambar = $request->input('gambar');
55+
$kategori->kategori_id = $request->input('kategori_id');
56+
57+
$kategori->save();
58+
return response()->json($kategori);
59+
}
60+
61+
public function destroy($id)
62+
{
63+
$kategori = Kategori::find($id);
64+
$kategori->delete();
65+
66+
return response()->json('Kategori removed successfully');
67+
}
68+
}

app/Http/Middleware/Authenticate.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Contracts\Auth\Factory as Auth;
7+
8+
class Authenticate
9+
{
10+
/**
11+
* The authentication guard factory instance.
12+
*
13+
* @var \Illuminate\Contracts\Auth\Factory
14+
*/
15+
protected $auth;
16+
17+
/**
18+
* Create a new middleware instance.
19+
*
20+
* @param \Illuminate\Contracts\Auth\Factory $auth
21+
* @return void
22+
*/
23+
public function __construct(Auth $auth)
24+
{
25+
$this->auth = $auth;
26+
}
27+
28+
/**
29+
* Handle an incoming request.
30+
*
31+
* @param \Illuminate\Http\Request $request
32+
* @param \Closure $next
33+
* @param string|null $guard
34+
* @return mixed
35+
*/
36+
public function handle($request, Closure $next, $guard = null)
37+
{
38+
if ($this->auth->guard($guard)->guest()) {
39+
return response('Unauthorized.', 401);
40+
}
41+
42+
return $next($request);
43+
}
44+
}

0 commit comments

Comments
 (0)