Add TimeDateController for server time and date API endpoints</message>
<message> - Introduced TimeDateController with two new endpoints: `/server-time` and `/server-date`. - Implemented methods to return the current server time and date in JSON format. - Enhanced API functionality by providing easy access to server time and date information.
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Info(title="Time and Date API", version="1.0.0")
|
||||||
|
*/
|
||||||
|
class TimeDateController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the current server time.
|
||||||
|
*
|
||||||
|
* @OA\Get(
|
||||||
|
* path="/server-time",
|
||||||
|
* summary="Get Server Time",
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Successful response",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* @OA\Property(property="server_time", type="string", example="14:30:00")
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function getServerTime(): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->json(['server_time' => date('H:i:s')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current server date.
|
||||||
|
*
|
||||||
|
* @OA\Get(
|
||||||
|
* path="/server-date",
|
||||||
|
* summary="Get Server Date",
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Successful response",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* @OA\Property(property="server_date", type="string", example="2023-10-01")
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function getServerDate(): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->json(['server_date' => date('Y-m-d')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user