mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 09:27:33 -04:00 
			
		
		
		
	Working on Company CRUD
This commit is contained in:
		
							parent
							
								
									42e7369c08
								
							
						
					
					
						commit
						a793100f79
					
				
							
								
								
									
										35
									
								
								app/Factory/CompanyFactory.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								app/Factory/CompanyFactory.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | |||||||
|  | <?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\Factory; | ||||||
|  | 
 | ||||||
|  | use App\DataMapper\CompanySettings; | ||||||
|  | use App\Models\Company; | ||||||
|  | use App\Utils\Traits\MakesHash; | ||||||
|  | 
 | ||||||
|  | class CompanyFactory | ||||||
|  | { | ||||||
|  | 	use MakesHash; | ||||||
|  | 
 | ||||||
|  | 	public static function create(int $account_id) :Company | ||||||
|  | 	{ | ||||||
|  | 
 | ||||||
|  |         $company = new Company; | ||||||
|  |         $company->name = ''; | ||||||
|  |         $company->account_id = $account_id; | ||||||
|  |         $company->company_key = $this->createHash(); | ||||||
|  |         $company->settings = new CompanySettings(CompanySettings::defaults()); | ||||||
|  |         $company->db = config('database.default'); | ||||||
|  | 
 | ||||||
|  |         return $company; | ||||||
|  |          | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -12,11 +12,16 @@ | |||||||
| namespace App\Http\Controllers; | namespace App\Http\Controllers; | ||||||
| 
 | 
 | ||||||
| use App\Http\Requests\Company\CreateCompanyRequest; | use App\Http\Requests\Company\CreateCompanyRequest; | ||||||
|  | use App\Http\Requests\Company\DestroyCompanyRequest; | ||||||
|  | use App\Http\Requests\Company\EditCompanyRequest; | ||||||
| use App\Http\Requests\Company\ShowCompanyRequest; | use App\Http\Requests\Company\ShowCompanyRequest; | ||||||
|  | use App\Http\Requests\Company\StoreCompanyRequest; | ||||||
|  | use App\Http\Requests\Company\UpdateCompanyRequest; | ||||||
| use App\Http\Requests\SignupRequest; | use App\Http\Requests\SignupRequest; | ||||||
| use App\Jobs\Company\CreateCompany; | use App\Jobs\Company\CreateCompany; | ||||||
| use App\Jobs\RegisterNewAccount; | use App\Jobs\RegisterNewAccount; | ||||||
| use App\Models\Company; | use App\Models\Company; | ||||||
|  | use App\Repositories\CompanyRepository; | ||||||
| use App\Transformers\CompanyTransformer; | use App\Transformers\CompanyTransformer; | ||||||
| use App\Utils\Traits\MakesHash; | use App\Utils\Traits\MakesHash; | ||||||
| use Illuminate\Foundation\Bus\DispatchesJobs; | use Illuminate\Foundation\Bus\DispatchesJobs; | ||||||
| @ -37,14 +42,17 @@ class CompanyController extends BaseController | |||||||
| 
 | 
 | ||||||
|     protected $entity_transformer = CompanyTransformer::class; |     protected $entity_transformer = CompanyTransformer::class; | ||||||
| 
 | 
 | ||||||
|  |     protected $company_repo; | ||||||
|     /** |     /** | ||||||
|      * CompanyController constructor. |      * CompanyController constructor. | ||||||
|      */ |      */ | ||||||
|     public function __construct() |     public function __construct(CompanyRepository $company_repo) | ||||||
|     { |     { | ||||||
|      |      | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
| 
 | 
 | ||||||
|  |         $this->company_repo = $company_repo; | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -54,7 +62,10 @@ class CompanyController extends BaseController | |||||||
|      */ |      */ | ||||||
|     public function index() |     public function index() | ||||||
|     { |     { | ||||||
| //        return view('signup.index');
 | 
 | ||||||
|  |         $companies = Company::whereAccountId(auth()->user()->id); | ||||||
|  | 
 | ||||||
|  |         return $this->listResponse($companies); | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -63,9 +74,12 @@ class CompanyController extends BaseController | |||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\Response |      * @return \Illuminate\Http\Response | ||||||
|      */ |      */ | ||||||
|     public function create() |     public function create(CreateCompanyRequest $request) | ||||||
|     { |     { | ||||||
|         //
 | 
 | ||||||
|  |         $company = CompanyFactory::create(auth()->user()->company()->account->id); | ||||||
|  |          | ||||||
|  |         return $this->itemResponse($company); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -74,7 +88,7 @@ class CompanyController extends BaseController | |||||||
|      * @param  \App\Http\Requests\SignupRequest $request |      * @param  \App\Http\Requests\SignupRequest $request | ||||||
|      * @return \Illuminate\Http\Response |      * @return \Illuminate\Http\Response | ||||||
|      */ |      */ | ||||||
|     public function store(CreateCompanyRequest $request) |     public function store(StoreCompanyRequest $request) | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
|         $company = CreateCompany::dispatchNow($request, auth()->user()->company()->account); |         $company = CreateCompany::dispatchNow($request, auth()->user()->company()->account); | ||||||
| @ -91,7 +105,9 @@ class CompanyController extends BaseController | |||||||
|      */ |      */ | ||||||
|     public function show(ShowCompanyRequest $request, Company $company) |     public function show(ShowCompanyRequest $request, Company $company) | ||||||
|     { |     { | ||||||
|         //
 | 
 | ||||||
|  |         return $this->itemResponse($company); | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -100,9 +116,11 @@ class CompanyController extends BaseController | |||||||
|      * @param  int  $id |      * @param  int  $id | ||||||
|      * @return \Illuminate\Http\Response |      * @return \Illuminate\Http\Response | ||||||
|      */ |      */ | ||||||
|     public function edit($id) |     public function edit(EditCompanyRequest $request, Company $company) | ||||||
|     { |     { | ||||||
|         //
 | 
 | ||||||
|  |         return $this->itemResponse($company);        | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -112,9 +130,11 @@ class CompanyController extends BaseController | |||||||
|      * @param  int  $id |      * @param  int  $id | ||||||
|      * @return \Illuminate\Http\Response |      * @return \Illuminate\Http\Response | ||||||
|      */ |      */ | ||||||
|     public function update(Request $request, $id) |     public function update(UpdateCompanyRequest $request, Company $company) | ||||||
|     { |     { | ||||||
|         //
 |         $company = $this->company_repo->save($request->all(), $company); | ||||||
|  | 
 | ||||||
|  |         return $this->itemResponse($company); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -123,8 +143,11 @@ class CompanyController extends BaseController | |||||||
|      * @param  int  $id |      * @param  int  $id | ||||||
|      * @return \Illuminate\Http\Response |      * @return \Illuminate\Http\Response | ||||||
|      */ |      */ | ||||||
|     public function destroy($id) |     public function destroy(DestroyCompanyRequest $request, Company $company) | ||||||
|     { |     { | ||||||
|         //
 | 
 | ||||||
|  |         $company->delete(); | ||||||
|  | 
 | ||||||
|  |         return response()->json([], 200); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -29,13 +29,4 @@ class CreateCompanyRequest extends Request | |||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function rules() |  | ||||||
|     { |  | ||||||
| 
 |  | ||||||
|     	return [ |  | ||||||
|             'name' => 'required' |  | ||||||
|     	]; |  | ||||||
|     	 |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
| @ -33,7 +33,7 @@ class StoreCompanyRequest extends Request | |||||||
|         //$this->sanitize();
 |         //$this->sanitize();
 | ||||||
| 
 | 
 | ||||||
|         return [ |         return [ | ||||||
|       //      'client_id' => 'required',
 |             'name' => 'required', | ||||||
|       //      'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
 |       //      'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
 | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -40,9 +40,8 @@ class Company extends BaseModel | |||||||
| 
 | 
 | ||||||
|     protected $presenter = 'App\Models\Presenters\CompanyPresenter'; |     protected $presenter = 'App\Models\Presenters\CompanyPresenter'; | ||||||
| 
 | 
 | ||||||
|     protected $guarded = [ |     protected $fillable = [ | ||||||
|         'id', |         'name', | ||||||
|         'company_id' |  | ||||||
|     ]; |     ]; | ||||||
| 
 | 
 | ||||||
|     protected $appends = [ |     protected $appends = [ | ||||||
|  | |||||||
							
								
								
									
										59
									
								
								app/Repositories/CompanyRepository.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								app/Repositories/CompanyRepository.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,59 @@ | |||||||
|  | <?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\Company; | ||||||
|  | use Illuminate\Http\Request; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * CompanyRepository | ||||||
|  |  */ | ||||||
|  | class CompanyRepository extends BaseRepository | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Gets the class name. | ||||||
|  |      * | ||||||
|  |      * @return     string The class name. | ||||||
|  |      */ | ||||||
|  |     public function getClassName() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         return Company::class; | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  |      * Saves the client and its contacts | ||||||
|  |      * | ||||||
|  |      * @param      array                           $data    The data | ||||||
|  |      * @param      \App\Models\Company              $client  The Company | ||||||
|  |      * | ||||||
|  |      * @return     Client|\App\Models\Company|null  Company Object | ||||||
|  |      */ | ||||||
|  |     public function save(array $data, Company $company) : ?Company | ||||||
|  | 	{ | ||||||
|  | 
 | ||||||
|  |         $company->fill($data); | ||||||
|  | 
 | ||||||
|  |         $company->save(); | ||||||
|  | 
 | ||||||
|  |         return $company; | ||||||
|  |          | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -65,6 +65,8 @@ Route::group(['middleware' => ['db','api_secret_check','token_auth'], 'prefix' = | |||||||
| 
 | 
 | ||||||
|   Route::post('users/bulk', 'UserController@bulk')->name('users.bulk'); |   Route::post('users/bulk', 'UserController@bulk')->name('users.bulk'); | ||||||
| 
 | 
 | ||||||
|  |   Route::resource('companies', 'CompanyController'); // name = (companies. index / create / show / update / destroy / edit
 | ||||||
|  | 
 | ||||||
| /* | /* | ||||||
|   Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
 |   Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
 | ||||||
|    |    | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user