account contacts store working + api docs

This commit is contained in:
Mahri Ilmedova 2022-08-05 17:02:16 +05:00
parent d3e513b9bf
commit 0bd9bde7d0
7 changed files with 101 additions and 551 deletions

View File

@ -4,7 +4,7 @@
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\BankAccountRequest; use App\Http\Requests\BankAccountRequest;
use App\Http\Requests\ContactsRequest; use App\Http\Requests\API\ContactsRequest;
use App\Http\Resources\AccountResource; use App\Http\Resources\AccountResource;
use App\Models\Account; use App\Models\Account;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -12,24 +12,6 @@
class AccountController extends Controller class AccountController extends Controller
{ {
/**
* @OA\GET(
* path="/api/account",
* summary=" - Get client account",
* tags = {"Account"},
* security={
* {"bearerAuth": {}}
* },
* @OA\Response(
* response="200",
* description="OK"
* ),
* @OA\Response(
* response="401",
* description="Unauthorized"
* )
* )
*/
public function account(Request $request){ public function account(Request $request){
$account = Account::with('profile')->find($request->user()->account_id); $account = Account::with('profile')->find($request->user()->account_id);
@ -44,7 +26,10 @@ public function account(Request $request){
} }
public function storeContacts(ContactsRequest $request){ public function storeContacts(ContactsRequest $request){
$account = Account::with('profile')->find($request->user()->account_id);
$data['contacts'] = json_encode($request->all());
$account->fill($data)->save();
return AccountResource::make($account);
} }
public function storeBankAccount(BankAccountRequest $request){ public function storeBankAccount(BankAccountRequest $request){

View File

@ -17,70 +17,9 @@
use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Lang;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
/**
* @OA\Info(
* title="Legalization API",
* version="1.0.0"
* )
* @OA\SecurityScheme(
* securityScheme="bearerAuth",
* in="header",
* name="bearerAuth",
* type="http",
* scheme="bearer",
* bearerFormat="JWT",
* ),
*/
//controller where all auth process for clie-nt happens
class AuthController extends Controller class AuthController extends Controller
{ {
/**
* @OA\POST(
* path="/api/login",
* summary=" - Login user",
* tags = {"Authorization"},
*
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="email",
* type="string",
* ),
* @OA\Property(
* property="password",
* type="string",
* ),
* example={"email": "ilmedovamahri@gmail.com", "password": 12345678}
* )
* )
* ),
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="200",
* description="OK",
* @OA\JsonContent(type="object")
* ),
* @OA\Response(
* response="401",
* description="Unauthorized",
* @OA\JsonContent(type="object")
* )
* )
*/
public function login(LoginRequest $request){ public function login(LoginRequest $request){
$client = Client::where('email', $request->input('email'))->first(); $client = Client::where('email', $request->input('email'))->first();
@ -117,78 +56,6 @@ public function login(LoginRequest $request){
return response()->json(['message' => Lang::get('auth.email_not_found')], 404); return response()->json(['message' => Lang::get('auth.email_not_found')], 404);
} }
/**
* @OA\POST(
* path="/api/register",
* summary=" - Register user",
* tags = {"Authorization"},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="firstname",
* type="string",
* ),
* @OA\Property(
* property="lastname",
* type="string",
* ),
* @OA\Property(
* property="email",
* type="string",
* ),
* @OA\Property(
* property="password",
* type="string",
* ),
* @OA\Property(
* property="account_type",
* type="string",
* ),
* @OA\Property(
* property="country",
* type="integer",
* ),
* example={"firstname":"Mahri", "lastname":"Ilmedova" ,"email": "ilmedovamahri@gmail.com", "password": 12345678, "country": 1,"account_type":"business"}
* )
* )
* ),
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="201",
* description="OK",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="token", type="string"),
* @OA\Property(property="client", type="object",
* @OA\Property(property="id", type="integer"),
* @OA\Property(property="firstname", type="string"),
* @OA\Property(property="lastname", type="string"),
* @OA\Property(property="email", type="string"),
* @OA\Property(property="is_verified", type="boolean"),
* )
* )
* ),
* @OA\Response(
* response="422",
* description="Validation Error",
* @OA\JsonContent(type="object",
* @OA\Property(property="message", type="string"),
* @OA\Property(property="errors", type="object"),
* )
* )
* )
*/
public function register(RegisterRequest $request){ public function register(RegisterRequest $request){
$client = new Client($request->only(['email','firstname','lastname'])); $client = new Client($request->only(['email','firstname','lastname']));
$client->password = Hash::make($request->input('password')); $client->password = Hash::make($request->input('password'));
@ -225,55 +92,6 @@ public function register(RegisterRequest $request){
return ClientResource::make($client); return ClientResource::make($client);
} }
/**
* @OA\POST(
* path="/api/verify-email",
* summary=" - Verify email of client",
* tags = {"Authorization"},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="email",
* type="string",
* ),
* @OA\Property(
* property="token",
* type="string",
* ),
* example={"email": "ilmedovamahri@gmail.com", "token": "4515"}
* )
* )
* ),
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="200",
* description="OK"
* ),
* @OA\Response(
* response="400",
* description="Missing fields (email or token)"
* ),
* @OA\Response(
* response="404",
* description="Client not found"
* ),
* @OA\Response(
* response="401",
* description="Unauthorised. Tokens do not match"
* )
* )
*/
public function verifyEmail(Request $request){ public function verifyEmail(Request $request){
$request->validate([ $request->validate([
'email' => 'required|email', 'email' => 'required|email',
@ -304,34 +122,6 @@ public function verifyEmail(Request $request){
} }
} }
/**
* @OA\GET(
* path="/api/client",
* summary=" - Get user",
* tags = {"Authorization"},
* security={
* {"bearerAuth": {}}
* },
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="200",
* description="OK"
* ),
* @OA\Response(
* response="401",
* description="Unauthorized"
* )
* )
*/
public function client(Request $request) { public function client(Request $request) {
if($client = $request->user()){ if($client = $request->user()){
return ClientResource::make($client); return ClientResource::make($client);
@ -341,34 +131,6 @@ public function client(Request $request) {
], 401); ], 401);
} }
/**
* @OA\POST(
* path="/api/logout",
* summary=" - Logout user",
* tags = {"Authorization"},
* security={
* {"bearerAuth": {}}
* },
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="200",
* description="OK"
* ),
* @OA\Response(
* response="401",
* description="Unauthorized"
* )
* )
*/
public function logout(Request $request) { public function logout(Request $request) {
$request->user()->currentAccessToken()->delete(); $request->user()->currentAccessToken()->delete();
return response()->json([ return response()->json([
@ -376,39 +138,6 @@ public function logout(Request $request) {
], 200); ], 200);
} }
/**
* @OA\POST(
* path="/api/forgot-password",
* summary=" - Send a user password reset link",
* tags = {"Authorization"},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="email",
* type="string",
* ),
* example={"email": "ilmedovamahri@gmail.com"}
* )
* )
* ),
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="200",
* description="OK"
* )
* )
*/
public function sendPasswordResetLinkEmail(Request $request) { public function sendPasswordResetLinkEmail(Request $request) {
try{ try{
$request->validate(['email' => 'required|email']); $request->validate(['email' => 'required|email']);
@ -437,51 +166,6 @@ public function sendPasswordResetLinkEmail(Request $request) {
} }
} }
/**
* @OA\POST(
* path="/api/reset-password",
* summary=" - Reset client password and enter new",
* tags = {"Authorization"},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="email",
* type="string",
* ),
* @OA\Property(
* property="token",
* type="string",
* ),
* @OA\Property(
* property="password",
* type="string",
* ),
* @OA\Property(
* property="confirm_password",
* type="string",
* ),
* example={"email": "ilmedovamahri@gmail.com", "token":"2546", "password":"Hello001!", "confirm_password":"Hello001!"}
* )
* )
* ),
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="200",
* description="OK"
* )
* )
*/
public function updatePassword(Request $request) { public function updatePassword(Request $request) {
try{ try{
$this->validate($request, [ $this->validate($request, [
@ -511,49 +195,6 @@ public function updatePassword(Request $request) {
} }
} }
/**
* @OA\POST(
* path="/api/update-client",
* summary=" - Update client account",
* tags = {"Authorization"},
* description = "Every field is required, except password. Password field is optional",
* security={
* {"bearerAuth": {}}
* },
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="firstname",
* type="string",
* ),
* @OA\Property(
* property="lastname",
* type="string",
* ),
* @OA\Property(
* property="password",
* type="string",
* ),
* example={"firstname":"Mahri","lastname":"Ilmedova","password":"Hello001!"}
* )
* )
* ),
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(response=201, description="Successful created", @OA\JsonContent()),
* @OA\Response(response=404, description="Not found", @OA\JsonContent()),
* )
*/
public function updateClient(ClientRequest $request){ public function updateClient(ClientRequest $request){
$client = $request->user(); $client = $request->user();

View File

@ -9,27 +9,6 @@
class ResourceController extends Controller class ResourceController extends Controller
{ {
/**
* @OA\GET(
* path="/api/countries",
* summary=" - Get countries list",
* tags = {"Resources"},
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="200",
* description="OK"
* )
* )
*/
public function countries(){ public function countries(){
return CountryResource::collection(Country::all()); return CountryResource::collection(Country::all());
} }

View File

@ -13,95 +13,16 @@
class TicketController extends Controller class TicketController extends Controller
{ {
//admin page
public function chat(Request $request){ public function chat(Request $request){
return view('admin.messages'); return view('admin.messages');
} }
/**
* @OA\GET(
* path="/api/ticket/ticket-messages",
* summary=" - Get ticket messages",
* tags = {"Tickets"},
* security={
* {"bearerAuth": {}}
* },
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Parameter(
* name="ticket_id",
* in="query",
* required=true,
* @OA\Schema(
* type="string"
* ),
*
* ),
* @OA\Response(
* response="200",
* description="OK"
* ),
* @OA\Response(
* response="401",
* description="Unauthorized"
* )
* )
*/
public function getTicketMessages(Request $request){ public function getTicketMessages(Request $request){
$messages = Message::where('ticket_id', $request->ticket_id)->orderBy('id', 'asc')->get(); $messages = Message::where('ticket_id', $request->ticket_id)->orderBy('id', 'asc')->get();
return MessageResource::collection($messages); return MessageResource::collection($messages);
} }
/**
* @OA\POST(
* path="/api/ticket/post-message",
* summary=" - Post ticket message",
* tags = {"Tickets"},
* security={
* {"bearerAuth": {}}
* },
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="content",
* type="string",
* ),
* @OA\Property(
* property="is_client",
* type="boolean",
* ),
* @OA\Property(
* property="ticket_id",
* type="integer",
* ),
* example={"content": "ilmedovamahri@gmail.com", "is_client":1, "ticket_id":2}
* )
* )
* ),
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(response=201, description="Successful created", @OA\JsonContent()),
* @OA\Response(response=404, description="Not found", @OA\JsonContent()),
* )
*/
public function postMessage(Request $request){ public function postMessage(Request $request){
try{ try{
$data = $request->all(); $data = $request->all();
@ -113,79 +34,12 @@ public function postMessage(Request $request){
return $e->getMessage(); return $e->getMessage();
} }
} }
/**
* @OA\GET(
* path="/api/ticket/my-tickets",
* summary=" - Get client tickets",
* tags = {"Tickets"},
* security={
* {"bearerAuth": {}}
* },
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(
* response="200",
* description="OK"
* ),
* @OA\Response(
* response="401",
* description="Unauthorized"
* )
* )
*/
public function getTickets(Request $request){ public function getTickets(Request $request){
$client = $request->user(); $client = $request->user();
$tickets = Ticket::with('status')->where('client_id', $client->id)->get(); $tickets = Ticket::with('status')->where('client_id', $client->id)->get();
return TicketResource::collection($tickets); return TicketResource::collection($tickets);
} }
/**
* @OA\POST(
* path="/api/ticket/post-ticket",
* summary=" - Create new ticket",
* tags = {"Tickets"},
* security={
* {"bearerAuth": {}}
* },
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="title",
* type="string",
* ),
* @OA\Property(
* property="content",
* type="string",
* ),
* example={"content": "ilmedovamahri@gmail.com", "title":"hello"}
* )
* )
* ),
* @OA\Parameter(
* description="Localization",
* in="header",
* name="X-Localization",
* required=false,
* @OA\Schema(type="string"),
* @OA\Examples(example="ru", value="ru", summary="Russian localization"),
* @OA\Examples(example="en", value="en", summary="English localization"),
* @OA\Examples(example="tm", value="tm", summary="Turkmen localization"),
* ),
* @OA\Response(response=201, description="Successful created", @OA\JsonContent()),
* @OA\Response(response=404, description="Not found", @OA\JsonContent()),
* )
*/
public function postTicket(TicketRequest $request){ public function postTicket(TicketRequest $request){
$ticket = new Ticket($request->only('content', 'title')); $ticket = new Ticket($request->only('content', 'title'));
$client = $request->user(); $client = $request->user();

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Http\Requests; namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
@ -13,7 +13,7 @@ class ContactsRequest extends FormRequest
*/ */
public function authorize() public function authorize()
{ {
return false; return true;
} }
/** /**

View File

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

View File

@ -27,6 +27,96 @@
] ]
} }
}, },
"/api/account/contacts": {
"put": {
"tags": [
"Account"
],
"summary": " - Store account contacts",
"operationId": "e809af65c12695106f3cbcf67011e145",
"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": {
"address": {
"type": "string"
},
"phone": {
"type": "string"
},
"email": {
"type": "string"
},
"fax": {
"type": "string"
}
},
"type": "object",
"example": {
"address": "Gami city",
"phone": "+99365555555",
"email": "johndoe@gmail.com",
"fax": "+99312454545"
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
},
"security": [
{
"bearerAuth": []
}
]
}
},
"/api/login": { "/api/login": {
"post": { "post": {
"tags": [ "tags": [
@ -913,4 +1003,4 @@
} }
} }
} }
} }