From 0bd9bde7d045eac0cdd4b615f84dc1e18a1f20df Mon Sep 17 00:00:00 2001 From: ilmedova Date: Fri, 5 Aug 2022 17:02:16 +0500 Subject: [PATCH] account contacts store working + api docs --- .../Controllers/API/AccountController.php | 25 +- app/Http/Controllers/API/AuthController.php | 359 ------------------ .../Controllers/API/ResourceController.php | 21 - app/Http/Controllers/API/TicketController.php | 150 +------- .../Requests/{ => API}/ContactsRequest.php | 4 +- routes/api.php | 1 + storage/api-docs/api-docs.json | 92 ++++- 7 files changed, 101 insertions(+), 551 deletions(-) rename app/Http/Requests/{ => API}/ContactsRequest.php (91%) diff --git a/app/Http/Controllers/API/AccountController.php b/app/Http/Controllers/API/AccountController.php index 49137c23..14d9573c 100755 --- a/app/Http/Controllers/API/AccountController.php +++ b/app/Http/Controllers/API/AccountController.php @@ -4,7 +4,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\BankAccountRequest; -use App\Http\Requests\ContactsRequest; +use App\Http\Requests\API\ContactsRequest; use App\Http\Resources\AccountResource; use App\Models\Account; use Illuminate\Http\Request; @@ -12,24 +12,6 @@ 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){ $account = Account::with('profile')->find($request->user()->account_id); @@ -44,7 +26,10 @@ public function account(Request $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){ diff --git a/app/Http/Controllers/API/AuthController.php b/app/Http/Controllers/API/AuthController.php index ac121245..31a4ccf5 100755 --- a/app/Http/Controllers/API/AuthController.php +++ b/app/Http/Controllers/API/AuthController.php @@ -17,70 +17,9 @@ use Illuminate\Support\Facades\Lang; 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 { - - /** - * @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){ $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); } - /** - * @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){ $client = new Client($request->only(['email','firstname','lastname'])); $client->password = Hash::make($request->input('password')); @@ -225,55 +92,6 @@ public function register(RegisterRequest $request){ 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){ $request->validate([ '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) { if($client = $request->user()){ return ClientResource::make($client); @@ -341,34 +131,6 @@ public function client(Request $request) { ], 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) { $request->user()->currentAccessToken()->delete(); return response()->json([ @@ -376,39 +138,6 @@ public function logout(Request $request) { ], 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) { try{ $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) { try{ $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){ $client = $request->user(); diff --git a/app/Http/Controllers/API/ResourceController.php b/app/Http/Controllers/API/ResourceController.php index 52136b3a..2e4c0012 100755 --- a/app/Http/Controllers/API/ResourceController.php +++ b/app/Http/Controllers/API/ResourceController.php @@ -9,27 +9,6 @@ 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(){ return CountryResource::collection(Country::all()); } diff --git a/app/Http/Controllers/API/TicketController.php b/app/Http/Controllers/API/TicketController.php index 4febb6ec..3420a117 100755 --- a/app/Http/Controllers/API/TicketController.php +++ b/app/Http/Controllers/API/TicketController.php @@ -13,95 +13,16 @@ class TicketController extends Controller { - //admin page + public function chat(Request $request){ 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){ $messages = Message::where('ticket_id', $request->ticket_id)->orderBy('id', 'asc')->get(); 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){ try{ $data = $request->all(); @@ -113,79 +34,12 @@ public function postMessage(Request $request){ 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){ $client = $request->user(); $tickets = Ticket::with('status')->where('client_id', $client->id)->get(); 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){ $ticket = new Ticket($request->only('content', 'title')); $client = $request->user(); diff --git a/app/Http/Requests/ContactsRequest.php b/app/Http/Requests/API/ContactsRequest.php similarity index 91% rename from app/Http/Requests/ContactsRequest.php rename to app/Http/Requests/API/ContactsRequest.php index fe3679f8..94abb8bd 100755 --- a/app/Http/Requests/ContactsRequest.php +++ b/app/Http/Requests/API/ContactsRequest.php @@ -1,6 +1,6 @@