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(); $message = new Message($data); $message->save(); return MessageResource::make($message); } catch(\Exception $e){ 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(); $ticket['client_id'] = $client->id; $status = Status::where('name', 'LIKE', '%' . 'open' . '%')->firstOrFail(); $ticket['status_id'] = $status->id; $ticket->save(); return TicketResource::make($ticket); } }