1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Working on User Crud

This commit is contained in:
David Bomba 2019-06-06 14:51:28 +10:00
parent cd84cd48ba
commit 51c5b96b68
3 changed files with 90 additions and 9 deletions

View File

@ -23,11 +23,11 @@ class UserFactory
$user->last_name = '';
$user->phone = '';
$user->email = '';
$user->theme_id = 0;
$user->last_login = now();
$user->failed_logins = 0;
$user->signature = '';
$user->theme_id = 0;
return $user;
}
}
}

View File

@ -21,6 +21,7 @@ use App\Http\Requests\User\ShowUserRequest;
use App\Http\Requests\User\StoreUserRequest;
use App\Http\Requests\User\UpdateUserRequest;
use App\Models\User;
use App\Repositories\UserRepository;
use App\Transformers\UserTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
@ -39,11 +40,14 @@ class UserController extends BaseController
protected $entity_transformer = UserTransformer::class;
public function __construct()
protected $user_repo;
public function __construct(UserRepository $user_repo)
{
parent::__construct();
$this->user_repo = $user_repo;
}
/**
@ -78,10 +82,22 @@ class UserController extends BaseController
*/
public function store(StoreUserRequest $request)
{
$company = auth()->user()->company();
//save user
$user = $this->user_repo->save($request->all(), UserFactory::create($company->id, auth()->user()->id));
//attach user to company
$user->companies()->attach($company->id, [
'account_id' => $company->account->id,
'is_owner' => 0,
'is_admin' => $request->input('is_admin'),
'is_locked' => 0,
'permissions' => $request->input('permissions'),
'settings' => $request->input('settings'),
]);
$user->load('companies');
return $this->itemResponse($user);
}
@ -120,7 +136,10 @@ class UserController extends BaseController
*/
public function update(UpdateUserRequest $request, User $user)
{
//
$user = $this->user_repo->save($request->all(), $user);
return $this->itemResponse($user);
}
/**
@ -129,9 +148,11 @@ class UserController extends BaseController
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(DestroyUserRequest $request)
public function destroy(DestroyUserRequest $request, User $user)
{
//
$user->delete();
return response()->json([], 200);
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Repositories;
use App\Models\User;
use Illuminate\Http\Request;
/**
* UserRepository
*/
class UserRepository extends BaseRepository
{
public function __construct()
{
}
/**
* Gets the class name.
*
* @return string The class name.
*/
public function getClassName()
{
return User::class;
}
/**
* Saves the user and its contacts
*
* @param array $data The data
* @param \App\Models\user $user The user
*
* @return user|\App\Models\user|null user Object
*/
public function save(array $data, User $user) : ?user
{
$user->fill($data);
$user->save();
return $user;
}
}