Skip to content

Commit 3535922

Browse files
committed
minor user repo changes
1 parent 163841b commit 3535922

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/Application/Repository/UserRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function __construct( Adapter $adapter, Mapper $mapper, UserFactory $fact
5151
* @throws \Exception
5252
*/
5353
public function create( User $user ): User {
54+
$user->setModified( new \DateTime() );
5455
$data = $this->mapper->toMap( $user );
5556
$this->adapter->create( 'users', $data );
5657

@@ -64,6 +65,7 @@ public function create( User $user ): User {
6465
* @throws \Exception
6566
*/
6667
public function update( User $user ): User {
68+
$user->setModified( new \DateTime() );
6769
$data = $this->mapper->toMap( $user );
6870
unset( $data->id );
6971
$id = $this->adapter->update( 'users', $user->getId(), $data, 'user_id' );

src/Application/Service/UserService.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DevPledge\Application\Repository\UserRepository;
88
use DevPledge\Domain\PreferredUserAuth\PreferredUserAuth;
99
use DevPledge\Uuid\Uuid;
10+
use Predis\Client;
1011

1112
/**
1213
* Class UserService
@@ -21,11 +22,23 @@ class UserService {
2122
* @var UserFactory $factory
2223
*/
2324
private $factory;
25+
/**
26+
* @var Client
27+
*/
28+
private $cacheClient;
2429

25-
public function __construct( UserRepository $repository, UserFactory $factory ) {
30+
/**
31+
* UserService constructor.
32+
*
33+
* @param UserRepository $repository
34+
* @param UserFactory $factory
35+
* @param Client $cacheClient
36+
*/
37+
public function __construct( UserRepository $repository, UserFactory $factory, Client $cacheClient ) {
2638

27-
$this->repo = $repository;
28-
$this->factory = $factory;
39+
$this->repo = $repository;
40+
$this->factory = $factory;
41+
$this->cacheClient = $cacheClient;
2942
}
3043

3144
/**
@@ -38,10 +51,13 @@ public function create( PreferredUserAuth $preferredUserAuth ) {
3851
$uuid = Uuid::make( 'user' )->toString();
3952
$userIdArray = [ 'user_id' => $uuid ];
4053
$data = array_merge( $userIdArray, $preferredUserAuth->getAuthDataArray()->getArray() );
41-
4254
$user = $this->factory->create( $data );
4355

44-
return $this->repo->create( $user );
56+
$createdUser = $this->repo->create( $user );
57+
if($createdUser){
58+
$this->cacheClient->set( $uuid, $createdUser->getData());
59+
}
60+
return $createdUser;
4561
}
4662

4763
/**

src/Domain/User.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,12 @@ public function setGitHubId( ?int $gitHubId ): User {
246246
* @return \stdClass
247247
*/
248248
function toMap(): \stdClass {
249-
$now = new \DateTime();
250249

251250
return (object) [
252251
'user_id' => $this->getId()->toString(),
253252
'name' => $this->getName(),
254253
'username' => $this->getUsername(),
255-
'modified' => $now->format( 'Y-m-d H:i:s' ),
254+
'modified' => $this->getModified()->format( 'Y-m-d H:i:s' ),
256255
'created' => $this->getCreated()->format( 'Y-m-d H:i:s' ),
257256
'hashed_password' => $this->getHashedPassword()
258257
];

0 commit comments

Comments
 (0)