profile API's almost finished

This commit is contained in:
Mahri Ilmedova 2022-08-08 11:26:01 +05:00
parent 86e478abe8
commit fefc8d5acb
9 changed files with 458 additions and 7 deletions

View File

@ -5,8 +5,13 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\API\BankAccountRequest;
use App\Http\Requests\API\ContactsRequest;
use App\Http\Requests\API\DocumentRequest;
use App\Http\Requests\API\ManagementRequest;
use App\Http\Requests\API\ProfileRequest;
use App\Http\Resources\AccountResource;
use App\Models\Account;
use App\Models\Business;
use App\Models\Company;
use Illuminate\Http\Request;
class AccountController extends Controller
@ -32,7 +37,13 @@ public function storeContacts(ContactsRequest $request){
$data['contacts'] = json_encode($request->all());
$account->fill($data)->save();
return AccountResource::make($account);
if(!empty($account)){
return AccountResource::make($account);
}
return response()->json([
'message'=> trans('app.account.not_found')
],404 );
}
@ -43,11 +54,54 @@ public function storeBankAccount(BankAccountRequest $request){
$data['bank'] = json_encode($request->all());
$account->fill($data)->save();
return AccountResource::make($account);
if(!empty($account)){
return AccountResource::make($account);
}
return response()->json([
'message'=> trans('app.account.not_found')
],404 );
}
public function storeProfile(){
public function storePersonal(DocumentRequest $request){
$account = Account::with('profile')->find($request->user()->account_id);
$data['document'] = json_encode($request->all());
$account->profile()->fill($data);
$account->profile()->save();
return AccountResource::make($account);
}
public function storeManagement(ManagementRequest $request){
}
public function storeProfile(ProfileRequest $request){
$account = Account::with('profile')->find($request->user()->account_id);
if(!empty($account)){
if($account->type == 'business'){
$data['personal'] = $request->all();
$profile = new Business($data);
$account->profile = $profile;
$account->save;
$profile->save();
}
else{
$profile = new Company($request->all());
$account->profile = $profile;
$account->save;
$profile->save();
}
return AccountResource::make($account);
}
return response()->json([
'message'=> trans('app.account.not_found')
],404 );
}
}

View File

@ -88,7 +88,21 @@ protected function setupCreateOperation()
CRUD::field('registration_address');
CRUD::field('fond_capital');
CRUD::field('management_types');
CRUD::field('signers');
CRUD::field([
'name' => 'signers',
'label' => 'Signers',
'type' => 'table',
'entity_singular' => 'option', // used on the "Add X" button
'columns' => [
'fullname' => 'Fullname',
'birthdate_n_birthplace' => 'Birthdate, place',
'citizenzhip' => 'Citizenship',
'registratino_address' => 'Registration address',
'' => '',
],
'max' => 15, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
]);
CRUD::field('share_holders');
CRUD::field('organizational_form');
CRUD::field('is_agent');

View File

@ -0,0 +1,37 @@
<?php
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
class DocumentRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'work_address' => $this->work_address,
'position' => $this->position,
'license_category' => $this->license_category,
'identity_doc_name' => $this->identity_doc_name,
'identity_doc_series' => $this->identity_doc_series,
'identity_doc_number' => $this->identity_doc_number,
'identity_doc_date' => $this->identity_doc_date,
'identity_doc_issuedby' => $this->identity_doc_issuedby
];
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
class ManagementRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
class ProfileRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
$type = $this->get('account_type');
if ($type == "business") {
$rules = $this->businessRules();
}
else{
$rules = $this->companyRules();
}
return $rules;
}
private function businessRules(){
return [
'name' => 'required',
'surname' => 'required',
'patronomic_name' => 'required',
'date_of_birth' => 'required',
'birth_place' => 'required',
'citizenship_id' => 'required',
'registration_address' => 'required'
];
}
private function companyRules(){
return [
'name' => 'required',
'short_name' => 'required',
'registration_number' => 'required',
'registration_date' => 'required',
'state_registration_agency' => 'required',
'registration_place' => 'required',
'registration_address' => 'required',
'fond_capital' => 'required',
'management_types' => 'required',
'signers' => 'required',
'share_holders' => 'required',
'organizational_form' => 'required',
'is_agent' => 'required'
];
}
}

View File

@ -14,7 +14,21 @@ class CompanyProfileResource extends JsonResource
*/
public function toArray($request)
{
return parent::toArray($request);
return [
'name' => $this->name,
'short_name' => $this->short_name,
'registration_number' => $this->registration_number,
'registration_date' => $this->registration_date,
'state_registration_agency' => $this->state_registration_agency,
'registration_place' => $this->registration_place,
'registration_address' => $this->registration_address,
'fond_capital' => $this->fond_capital,
'management_types' => $this->management_types,
'signers' => $this->signers,
'share_holders' => $this->share_holders,
'organizational_form' => $this->organizational_form,
'is_agent' => $this->is_agent
];
}
}

View File

@ -17,7 +17,7 @@ class Business extends Model
protected $table = 'businesses';
// protected $primaryKey = 'id';
// public $timestamps = false;
// public $timestamps = false;Akargider#2323!
protected $guarded = ['id'];
protected $fillable = [
'personal', 'document', 'job'

View File

@ -35,7 +35,8 @@
Route::get('/',[AccountController::class, 'account']);
Route::put('contacts',[AccountController::class,'storeContacts']);
Route::put('bank',[AccountController::class,'storeBankAccount']);
Route::put('profile',[AccountController::class,'storeProfile']);
Route::put('business-profile',[AccountController::class,'storeProfile']);
Route::put('company-profile',[AccountController::class,'storeProfile']);
});
/**

View File

@ -215,6 +215,242 @@
]
}
},
"/api/account/business-profile": {
"put": {
"tags": [
"Account"
],
"summary": " - Store account profile info (business)",
"operationId": "e809af65c12695106f3cbcf67011embgt",
"parameters": [
{
"name": "X-Localization",
"in": "header",
"description": "Localization",
"required": false,
"schema": {
"type": "string"
},
"examples": {
"ru": {
"summary": "Russian localization",
"value": "ru"
},
"en": {
"summary": "English localization",
"value": "en"
},
"tm": {
"summary": "Turkmen localization",
"value": "tm"
}
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"account_type": {
"type": "string"
},
"name": {
"type": "string"
},
"surname": {
"type": "string"
},
"patronomic_name": {
"type": "string"
},
"date_of_birth": {
"type": "string"
},
"birth_place": {
"type": "string"
},
"citizenship_id": {
"type": "string"
},
"registration_address": {
"type": "string"
}
},
"type": "object",
"example": {
"account_type": "business",
"name": "John",
"surname": "Doe",
"patronomic_name": "Muhammedovich",
"date_of_birth": "01.01.2001",
"birth_place": "Ashgabat",
"citizenship_id": "2",
"registration_address": "Ashgabat"
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
},
"security": [
{
"bearerAuth": []
}
]
}
},
"/api/account/company-profile": {
"put": {
"tags": [
"Account"
],
"summary": " - Store account profile info (company)",
"operationId": "e809af65c12695106f3cbcf67011embgt",
"parameters": [
{
"name": "X-Localization",
"in": "header",
"description": "Localization",
"required": false,
"schema": {
"type": "string"
},
"examples": {
"ru": {
"summary": "Russian localization",
"value": "ru"
},
"en": {
"summary": "English localization",
"value": "en"
},
"tm": {
"summary": "Turkmen localization",
"value": "tm"
}
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"account_type": {
"type": "string"
},
"name": {
"type": "string"
},
"short_name": {
"type": "string"
},
"registration_number": {
"type": "string"
},
"registration_date": {
"type": "string"
},
"state_registration_agency": {
"type": "string"
},
"registration_place": {
"type": "string"
},
"registration_address": {
"type": "string"
},
"fond_capital":{
"type" : "string"
},
"management_types":{
"type" : "string"
},
"signers":{
"type" : "string"
},
"share_holders":{
"type" : "string"
},
"organizational_form":{
"type" : "string"
},
"is_agent":{
"type" : "string"
}
},
"type": "object",
"example": {
"account_type": "business",
"name": "Ashgabat Dokma Toplumy",
"short_name": "ADT",
"registration_number": "453678958490",
"registration_date": "2022-01-24",
"state_registration_agency": "Ashgabat Hakimligi",
"registration_place": "Ashgabat",
"registration_address": "Ashgabat",
"fond_capital":"Birzha",
"management_types": "",
"signers": "",
"share_holders": "",
"organizational_form": "",
"is_agent": "1"
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
},
"security": [
{
"bearerAuth": []
}
]
}
},
"/api/login": {
"post": {
"tags": [