diff --git a/app/Http/Controllers/UrlShortenerController.php b/app/Http/Controllers/UrlShortenerController.php index d0480b6..181d114 100755 --- a/app/Http/Controllers/UrlShortenerController.php +++ b/app/Http/Controllers/UrlShortenerController.php @@ -19,7 +19,9 @@ class UrlShortenerController extends Controller public function viewList() { - return view('list'); + return view('list', [ + "url" => URL::to('/'), + ]); } public function createShortURL(Request $request) @@ -169,4 +171,30 @@ class UrlShortenerController extends Controller ], 400); } } + + public function urlAddressList(Request $request) + { + $user = $request->session()->get('user'); + return UrlAddress::where('user_id', $user)->paginate(); + } + + public function urlAddressDelete(Request $request, $id) + { + $urlAddress = UrlAddress::find($id); + if ($urlAddress) { + if ($urlAddress->delete()) { + return response()->json([ + "message" => "Success delete" + ], 200); + } else { + return response()->json([ + "message" => "Failed delete" + ], 500); + } + } else { + return response()->json([ + "message" => "URL Address with id $id is not exist" + ], 400); + } + } } diff --git a/app/UrlAddress.php b/app/UrlAddress.php index 683d172..27a9e8f 100755 --- a/app/UrlAddress.php +++ b/app/UrlAddress.php @@ -3,8 +3,40 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Carbon; class UrlAddress extends Model { - // + protected $appends = [ + 'is_expired', + 'full_url_destination' + ]; + + public function getFullUrlDestinationAttribute() + { + $httpPath = "http://"; + $httpsPath = "https://"; + + $hasHttpOrHttps = false; + $url = $this['url_destination']; + if ($httpPath == substr($url, 0, strlen($httpPath))) { + $hasHttpOrHttps = true; + } else if ($httpsPath == substr($url, 0, strlen($httpsPath))) { + $hasHttpOrHttps = true; + } + return ($hasHttpOrHttps ? "" : "http://") . $this['url_destination']; + } + + public function getIsExpiredAttribute() + { + $urlExpired = false; + if ($this['date_expired'] != null) { + $today = Carbon::now()->setTime(0, 0, 0); + $urlExpiredDate = Carbon::parse($this['date_expired']); + if (!$today->equalTo($urlExpiredDate)) { + $urlExpired = $urlExpiredDate->lessThanOrEqualTo($today); + } + } + return $urlExpired; + } } diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index 3380b4e..11bcb19 100755 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -11,68 +11,39 @@ @section('content')
-

- -

+

-
- -
+
- +
+ - - + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - +
# Destination Short URLClickClick Expired Date ProtectionActionAction
1.http://www.google.comhttp://shorturl.test/s/sasd5 - -
1.http://www.google.comhttp://shorturl.test/s/ssdf5 - -
1.http://www.google.comhttp://shorturl.test/s/fffs5 - + +
+
@endsection @@ -81,6 +52,10 @@ @endsection diff --git a/routes/web.php b/routes/web.php index d0d6fe6..52af011 100755 --- a/routes/web.php +++ b/routes/web.php @@ -21,6 +21,11 @@ Route::post('/s/{pathGenerated}/open/protection', "UrlShortenerController@openPr Route::middleware('auth.web')->group(function () { Route::get('/list', "UrlShortenerController@viewList"); + // URL Shortener Controller + Route::get('/web/url/address/list', "UrlShortenerController@urlAddressList"); + Route::delete('/web/url/address/delete/{id}', "UrlShortenerController@urlAddressDelete"); + + // Security Controller Route::post('/web/change/password', "SecurityController@formChangePassword"); });