Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add registration api and unit test registration #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 122 additions & 0 deletions .idea/api-testing-automation.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 121 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions app/Domain/UserManagements/Application/UserApplication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace App\Domain\UserManagements\Application;

use App\Domain\UserManagements\Model\UserModel;
use App\Domain\UserManagements\Repositories\UserRepository;
use Illuminate\Support\Facades\Hash;

class UserApplication
{
protected $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}

public function register(UserModel $model)
{
$model->avatar = "https://ui-avatars.com/api/?name=" . urlencode($model->name);
$model->password = Hash::make($model->password);
return $this->userRepository->register($model);
}
}
16 changes: 16 additions & 0 deletions app/Domain/UserManagements/Model/UserModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace App\Domain\UserManagements\Model;

class UserModel
{
public $name;
public $email;
public $password;
public $avatar;
public $created_by;
public $updated_by;

public function toArray(){
return get_object_vars($this);
}
}
26 changes: 26 additions & 0 deletions app/Domain/UserManagements/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace App\Domain\UserManagements\Repositories;

use App\Domain\UserManagements\Model\UserModel;
use App\Models\User;

class UserRepository
{
protected $model;

public function __construct(User $model)
{
$this->model = $model;
}

public function register(UserModel $model)
{
$this->model->name = $model->name;
$this->model->email = $model->email;
$this->model->password = $model->password;
$this->model->avatar = $model->avatar;
$this->model->save();

return $this->model->only(['id', 'name', 'email', 'created_at']);
}
}
Loading