feat(closet): add sanity check on closet management
This commit is contained in:
parent
1a7f76ea69
commit
e965a53c18
@ -17,8 +17,15 @@ class ClosetManagementController extends Controller
|
||||
public function add(Request $request, Dispatcher $dispatcher, User $user)
|
||||
{
|
||||
$tid = $request->input('tid');
|
||||
/** @var Texture */
|
||||
$texture = Texture::findOrFail($tid);
|
||||
$texture = Texture::find($tid);
|
||||
if (!$texture) {
|
||||
return json(trans('user.closet.add.not-found'), 1);
|
||||
}
|
||||
|
||||
if ($user->closet()->where('tid', $request->tid)->count() > 0) {
|
||||
return json(trans('user.closet.add.repeated'), 1);
|
||||
}
|
||||
|
||||
$name = $texture->name;
|
||||
|
||||
$dispatcher->dispatch('closet.adding', [$tid, $name, $user]);
|
||||
@ -35,10 +42,14 @@ class ClosetManagementController extends Controller
|
||||
$tid = $request->input('tid');
|
||||
$dispatcher->dispatch('closet.removing', [$tid, $user]);
|
||||
|
||||
/** @var Texture */
|
||||
$texture = Texture::findOrFail($tid);
|
||||
$item = $user->closet()->find($tid);
|
||||
if (empty($item)) {
|
||||
return json(trans('user.closet.remove.non-existent'), 1);
|
||||
}
|
||||
|
||||
$user->closet()->detach($texture->tid);
|
||||
$user->closet()->detach($tid);
|
||||
|
||||
$texture = Texture::find($tid);
|
||||
|
||||
$dispatcher->dispatch('closet.removed', [$texture, $user]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user