Skip to content

Commit d3f6194

Browse files
committed
fixes
1 parent 3feb1bc commit d3f6194

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

app/Api/V1/Controllers/AuthController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public function signup(Request $request)
7979

8080
User::unguard();
8181
$user = User::create([
82-
'name' => $userData['name'],
83-
'email' => $userData['email'],
84-
'password' => bcrypt($userData['password']),
82+
'name' => $userData['name'],
83+
'email' => $userData['email'],
84+
'password' => bcrypt($userData['password']),
8585
]);
8686
User::reguard();
8787

@@ -92,7 +92,7 @@ public function signup(Request $request)
9292
if($hasToReleaseToken) {
9393
return $this->login($request);
9494
}
95-
95+
9696
return $this->response->created();
9797
}
9898

app/Api/V1/Controllers/BookController.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,61 @@ public function store(Request $request) {
4343

4444

4545

46+
47+
public function show($id)
48+
{
49+
$currentUser = JWTAuth::parseToken()->authenticate();
50+
51+
$book = $currentUser->books()->find($id);
52+
53+
if(!$book)
54+
throw new NotFoundHttpException;
55+
56+
return $book;
57+
}
58+
59+
60+
61+
62+
63+
64+
public function update(Request $request, $id)
65+
{
66+
$currentUser = JWTAuth::parseToken()->authenticate();
67+
68+
$book = $currentUser->books()->find($id);
69+
if(!$book)
70+
throw new NotFoundHttpException;
71+
72+
$book->fill($request->all());
73+
74+
if($book->save())
75+
return $this->response->noContent();
76+
else
77+
return $this->response->error('could_not_update_book', 500);
78+
}
79+
80+
81+
82+
83+
84+
85+
public function destroy($id)
86+
{
87+
$currentUser = JWTAuth::parseToken()->authenticate();
88+
89+
$book = $currentUser->books()->find($id);
90+
91+
if(!$book)
92+
throw new NotFoundHttpException;
93+
94+
if($book->delete())
95+
return $this->response->noContent();
96+
else
97+
return $this->response->error('could_not_delete_book', 500);
98+
}
99+
100+
46101
}
47102

48103

0 commit comments

Comments
 (0)