1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/UserApiController.php

67 lines
1.8 KiB
PHP
Raw Normal View History

2016-02-04 21:35:28 +01:00
<?php namespace App\Http\Controllers;
use App\Services\UserService;
use App\Ninja\Repositories\UserRepository;
use App\Ninja\Transformers\UserTransformer;
use Auth;
use App\Models\User;
use App\Http\Requests\CreateUserRequest;
use App\Http\Requests\UpdateUserRequest;
class UserApiController extends BaseAPIController
{
protected $userService;
protected $userRepo;
2016-05-01 22:55:13 +02:00
protected $entityType = ENTITY_USER;
2016-02-04 21:35:28 +01:00
public function __construct(UserService $userService, UserRepository $userRepo)
{
2016-03-02 15:36:46 +01:00
parent::__construct();
2016-02-04 21:35:28 +01:00
$this->userService = $userService;
$this->userRepo = $userRepo;
}
public function index()
{
2016-05-01 22:55:13 +02:00
$users = User::whereAccountId(Auth::user()->account_id)
->withTrashed()
->orderBy('created_at', 'desc');
2016-05-02 10:38:01 +02:00
return $this->listResponse($users);
2016-02-04 21:35:28 +01:00
}
/*
public function store(CreateUserRequest $request)
{
return $this->save($request);
}
*/
2016-03-02 14:36:42 +01:00
2016-02-04 21:35:28 +01:00
public function update(UpdateUserRequest $request, $userPublicId)
{
$user = Auth::user();
if ($request->action == ACTION_ARCHIVE) {
$this->userRepo->archive($user);
$transformer = new UserTransformer(Auth::user()->account, $request->serializer);
$data = $this->createItem($user, $transformer, 'users');
return $this->response($data);
} else {
return $this->save($request, $user);
}
}
private function save($request, $user = false)
{
$user = $this->userRepo->save($request->input(), $user);
$transformer = new UserTransformer(\Auth::user()->account, $request->serializer);
$data = $this->createItem($user, $transformer, 'users');
return $this->response($data);
}
}