Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
POST_CODE_VALID_URL=https://api.postcodes.io/postcodes
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ Start the development server using `php artisan serve` and go to http://127.0.0.

1. Make the address lookup component accessible
2. Style it using bootstrap

## I worked On Backend
## Backend steps
1. Copy .env.example to .env to be sure `POST_CODE_VALID_URL` is exist
2. To register user go to `http://127.0.0.1:8000/users`
3. To list all registered users run command `php artisan users:list`
47 changes: 47 additions & 0 deletions app/Console/Commands/UsersList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\User;

class UsersList extends Command {

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'users:list';

/**
* The console command description.
*
* @var string
*/
protected $description = 'list recently registered users';

/**
* Create a new command instance.
* UsersList constructor.
*/
public function __construct() {
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle() {
$data = User::get(['name', 'email', 'postcode'])->toArray();
if (count($data)) {
$headers = ['Name', 'Email', 'Postcode'];
$this->table($headers, $data);
} else {
$this->info("No users Exist");
}
return 0;
}
}
3 changes: 2 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console;

use App\Console\Commands\UsersList;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand All @@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
//
'App\Console\Commands\UsersList',
];

/**
Expand Down
32 changes: 9 additions & 23 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
* @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
//
Expand All @@ -21,35 +19,23 @@ class Handler extends ExceptionHandler
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Report or log an exception.
* Register the exception handling callbacks for the application.
*
* @param \Throwable $exception
* @return void
* @throws Throwable
*/
public function report(Throwable $exception)
public function register()
{
parent::report($exception);
$this->reportable(function (Throwable $e) {
//
});
}

/**
* Render an exception into an HTTP response.
*
* @param Request $request
* @param \Throwable $exception
* @return Response
* @throws Throwable
*/
public function render($request, Throwable $exception): Response
{
return parent::render($request, $exception);
}
}
}
38 changes: 38 additions & 0 deletions app/Http/Controllers/Backend/User/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* User: kholoudElkholy
* Email: kholoudelkholy91@gmail.com
*/

namespace App\Http\Controllers\Backend\User;

use App\Http\Controllers\Controller;
use App\Http\Requests\User\StoreUserRequest;
use App\Services\CreatingUserService;

class UserController extends Controller
{
/**
* Return Register view
* @return mixed
*/
public function create(){
return view('register');
}

/**
* @param StoreUserRequest $request
* @param CreatingUserService $service
* @return mixed
*/
public function store( StoreUserRequest $request,
CreatingUserService $service){

$user_saved = $service->execute($request->all());

if ($user_saved) {
return redirect()->back()->with('success', __('messages.user.stored'));
}
return redirect()->back()->with('error', __('messages.user.notStored'));
}
}
156 changes: 156 additions & 0 deletions app/Http/Repositories/BaseRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

/**
* User: kholoudElkholy
* Email: kholoudelkholy91@gmail.com
*/
namespace App\Http\Repositories;

use Illuminate\Database\Eloquent\Model;

class BaseRepository
{
/**
*
* @var Model
*/
protected $model = null;
protected $resource = null;

/**
*
* @param Model $model
*/
protected function __construct(Model $model)
{
$this->model = $model;
}

/**
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function all()
{
return $this->model->all();
}

/**
* @param array $data
* @return mixed
*/
public function create(array $data)
{
return $this->model->create($data);
}

/**
* @param Model $item
* @param array $data
* @return Model
*/
public function update(Model $item, array $data)
{
$item->update($data);
return $item;
}

/**
* @param Model $item
* @return Model
*/
public function show(Model $item)
{
$item->get();
return $item;
}

/**
* @param Model $item
* @return Model
* @throws \Exception
*/
public function destroy(Model $item)
{
$item->delete();
return $item;
}


//===================================
//
// public function get(): EloquentCollection
// {
// return Medal::query()->with('event')->get();
// }
//
// public function getById(Medal $medal): Medal
// {
// $medal->get();
// return $medal;
// }
//
// public function create(Medal $medal, array $data): Medal
// {
// return $medal->create($data);
//
// }
//
// public function update(Medal $medal, array $data): Medal
// {
// $medal->update($data);
// return $medal;
// }
//
// public function delete(Medal $medal): Medal
// {
// $medal->delete();
// return $medal;
// }

/**
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/




/**
* @param $id
* @return \Illuminate\Http\JsonResponse|mixed
*/
// public function show($id)
// {
// if ($item = $this->model->find($id)) {
//// return $item;
// return [
// 'error' => true,
// 'msg' => trans('messages.' . $this->model . '.notFound', ['model' => class_basename(get_class(new $this->model))]),
// 'data' => $item
// ];
// }
// return [
// 'error' => true,
// 'msg' => trans('messages.' . $this->model . '.notFound', ['model' => class_basename(get_class(new $this->model))]),
// 'data' => null
// ];
// }
/**
* @param Model $item
* @return Model
*/

// public function destroy($id)
// {
// if ($item = $this->model->find($id)) {
// {
// $item->delete();
// }
// }
// return [
// 'error' => true,
// 'msg' => trans('messages.' . $this->model . '.notFound', ['model' => class_basename(get_class(new $this->model))])
// ];
//
// }

}
20 changes: 20 additions & 0 deletions app/Http/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* User: kholoudElkholy
* Email: kholoudelkholy91@gmail.com
*/
namespace App\Http\Repositories;

use App\Models\User;

class UserRepository extends BaseRepository
{
/**
* UserRepository constructor.
* @param User $user
*/
public function __construct(User $user) {
parent::__construct($user);
}
}
Loading