1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Http/Controllers/UserApiController.php

76 lines
2.1 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;
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()
{
$user = Auth::user();
$users = User::whereAccountId($user->account_id)->withTrashed();
$users = $users->paginate();
$paginator = User::whereAccountId($user->account_id)->withTrashed()->paginate();
$transformer = new UserTransformer(Auth::user()->account, $this->serializer);
$data = $this->createCollection($users, $transformer, 'users', $paginator);
return $this->response($data);
}
/*
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)
{
/*
// temporary fix for ids starting at 0
$userPublicId -= 1;
$user = User::scope($userPublicId)->firstOrFail();
*/
$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);
}
}