From b5aaf3376121b95943396b92210d1de77e04ec3d Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Fri, 13 Jun 2025 05:26:00 +0300 Subject: [PATCH 01/12] Remove gRPC-related classes and proto-generated files no longer in use to streamline the codebase. --- app/Grpc/BaseResponse.php | 29 -- app/Grpc/GPBMetadata/User/UserService.php | 24 -- app/Grpc/HealthCheckRequest.php | 58 ---- app/Grpc/HealthCheckResponse.php | 58 ---- .../HealthCheckResponse/ServingStatus.php | 56 ---- .../HealthCheckResponse_ServingStatus.php | 16 -- app/Grpc/HealthServiceClient.php | 34 --- app/Grpc/Services/BaseServer.php | 18 +- app/Grpc/User/AuthenticateRequest.php | 85 ------ app/Grpc/User/AuthenticateResponse.php | 193 -------------- app/Grpc/User/CartItem.php | 139 ---------- app/Grpc/User/ChangePasswordRequest.php | 85 ------ app/Grpc/User/ChangePasswordResponse.php | 85 ------ app/Grpc/User/CreateUserRequest.php | 139 ---------- app/Grpc/User/DeleteUserRequest.php | 58 ---- app/Grpc/User/DeleteUserResponse.php | 85 ------ app/Grpc/User/GetUserRequest.php | 60 ----- app/Grpc/User/ListUsersRequest.php | 112 -------- app/Grpc/User/ListUsersResponse.php | 193 -------------- app/Grpc/User/LogoutRequest.php | 31 --- app/Grpc/User/LogoutResponse.php | 85 ------ app/Grpc/User/RefreshTokenRequest.php | 31 --- app/Grpc/User/RefreshTokenResponse.php | 166 ------------ app/Grpc/User/UpdateUserRequest.php | 139 ---------- app/Grpc/User/User.php | 249 ------------------ app/Grpc/User/UserProfileRequest.php | 58 ---- app/Grpc/User/UserProfileResponse.php | 247 ----------------- app/Grpc/User/UserResponse.php | 114 -------- app/Grpc/User/UserServiceClient.php | 175 ------------ app/Grpc/User/ValidateTokenRequest.php | 58 ---- app/Grpc/User/ValidateTokenResponse.php | 139 ---------- app/Http/Resources/UserResource.php | 2 +- 32 files changed, 10 insertions(+), 3011 deletions(-) delete mode 100644 app/Grpc/BaseResponse.php delete mode 100644 app/Grpc/GPBMetadata/User/UserService.php delete mode 100644 app/Grpc/HealthCheckRequest.php delete mode 100644 app/Grpc/HealthCheckResponse.php delete mode 100644 app/Grpc/HealthCheckResponse/ServingStatus.php delete mode 100644 app/Grpc/HealthCheckResponse_ServingStatus.php delete mode 100644 app/Grpc/HealthServiceClient.php delete mode 100644 app/Grpc/User/AuthenticateRequest.php delete mode 100644 app/Grpc/User/AuthenticateResponse.php delete mode 100644 app/Grpc/User/CartItem.php delete mode 100644 app/Grpc/User/ChangePasswordRequest.php delete mode 100644 app/Grpc/User/ChangePasswordResponse.php delete mode 100644 app/Grpc/User/CreateUserRequest.php delete mode 100644 app/Grpc/User/DeleteUserRequest.php delete mode 100644 app/Grpc/User/DeleteUserResponse.php delete mode 100644 app/Grpc/User/GetUserRequest.php delete mode 100644 app/Grpc/User/ListUsersRequest.php delete mode 100644 app/Grpc/User/ListUsersResponse.php delete mode 100644 app/Grpc/User/LogoutRequest.php delete mode 100644 app/Grpc/User/LogoutResponse.php delete mode 100644 app/Grpc/User/RefreshTokenRequest.php delete mode 100644 app/Grpc/User/RefreshTokenResponse.php delete mode 100644 app/Grpc/User/UpdateUserRequest.php delete mode 100644 app/Grpc/User/User.php delete mode 100644 app/Grpc/User/UserProfileRequest.php delete mode 100644 app/Grpc/User/UserProfileResponse.php delete mode 100644 app/Grpc/User/UserResponse.php delete mode 100644 app/Grpc/User/UserServiceClient.php delete mode 100644 app/Grpc/User/ValidateTokenRequest.php delete mode 100644 app/Grpc/User/ValidateTokenResponse.php diff --git a/app/Grpc/BaseResponse.php b/app/Grpc/BaseResponse.php deleted file mode 100644 index 668c300..0000000 --- a/app/Grpc/BaseResponse.php +++ /dev/null @@ -1,29 +0,0 @@ - $this->code, - 'message' => $this->message, - 'data' => $this->data, - ]; - } - - protected function buildUserResponse($response, bool $success = true, string $message = '') - { - $response->setSuccess($success); - $response->setMessage($message); - return $response; - } -} diff --git a/app/Grpc/GPBMetadata/User/UserService.php b/app/Grpc/GPBMetadata/User/UserService.php deleted file mode 100644 index b54220e..0000000 --- a/app/Grpc/GPBMetadata/User/UserService.php +++ /dev/null @@ -1,24 +0,0 @@ -internalAddGeneratedFile(hex2bin( - "0ab0130a12757365725f736572766963652e70726f746f120475736572221c0a0e4765745573657252657175657374120a0a02696418012001280322500a114372656174655573657252657175657374120c0a046e616d65180120012809120d0a05656d61696c18022001280912100a0870617373776f7264180320012809120c0a04726f6c65180420012809224e0a115570646174655573657252657175657374120a0a026964180120012803120c0a046e616d65180220012809120d0a05656d61696c18032001280912100a0870617373776f7264180420012809221f0a1144656c6574655573657252657175657374120a0a02696418012001280322420a104c697374557365727352657175657374120c0a047061676518012001280512100a087065725f70616765180220012805120e0a0673656172636818032001280922360a1341757468656e74696361746552657175657374120d0a05656d61696c18012001280912100a0870617373776f726418022001280922240a125573657250726f66696c6552657175657374120e0a066669656c6473180220032809220f0a0d4c6f676f75745265717565737422250a1456616c6964617465546f6b656e52657175657374120d0a05746f6b656e18012001280922150a1352656672657368546f6b656e5265717565737422470a154368616e676550617373776f72645265717565737412180a1063757272656e745f70617373776f726418012001280912140a0c6e65775f70617373776f7264180220012809228f010a0455736572120a0a026964180120012803120c0a046e616d65180220012809120d0a05656d61696c180320012809120c0a04726f6c6518042001280912120a0a70686f746f5f7061746818052001280912140a0c6163636573735f746f6b656e18062001280912120a0a637265617465645f617418072001280912120a0a757064617465645f617418082001280922450a08436172744974656d120a0a026964180120012803120c0a047479706518022001280912100a087175616e74697479180320012805120d0a057072696365180420012801224a0a0c55736572526573706f6e736512180a047573657218012001280b320a2e757365722e55736572120f0a0773756363657373180220012808120f0a076d65737361676518032001280922360a1244656c65746555736572526573706f6e7365120f0a0773756363657373180120012808120f0a076d6573736167651802200128092288010a114c6973745573657273526573706f6e736512190a05757365727318012003280b320a2e757365722e55736572120d0a05746f74616c18022001280512140a0c63757272656e745f7061676518032001280512110a096c6173745f70616765180420012805120f0a0773756363657373180520012808120f0a076d6573736167651806200128092289010a1441757468656e746963617465526573706f6e736512180a047573657218012001280b320a2e757365722e55736572120d0a05746f6b656e18022001280912120a0a746f6b656e5f7479706518032001280912120a0a657870697265735f6174180420012809120f0a0773756363657373180520012808120f0a076d65737361676518062001280922a6010a135573657250726f66696c65526573706f6e7365120a0a026964180120012803120c0a046e616d65180220012809120d0a05656d61696c18032001280912120a0a70686f746f5f70617468180420012809120c0a04726f6c6518052001280912220a0a636172745f6974656d7318062003280b320e2e757365722e436172744974656d120f0a0773756363657373180720012808120f0a076d65737361676518082001280922320a0e4c6f676f7574526573706f6e7365120f0a0773756363657373180120012808120f0a076d65737361676518022001280922620a1556616c6964617465546f6b656e526573706f6e736512180a047573657218012001280b320a2e757365722e55736572120d0a0576616c6964180220012808120f0a0773756363657373180320012808120f0a076d657373616765180420012809226f0a1452656672657368546f6b656e526573706f6e7365120d0a05746f6b656e18012001280912120a0a746f6b656e5f7479706518022001280912120a0a657870697265735f6174180320012809120f0a0773756363657373180420012808120f0a076d657373616765180520012809223a0a164368616e676550617373776f7264526573706f6e7365120f0a0773756363657373180120012808120f0a076d65737361676518022001280932e0050a0b557365725365727669636512330a074765745573657212142e757365722e47657455736572526571756573741a122e757365722e55736572526573706f6e736512390a0a4372656174655573657212172e757365722e43726561746555736572526571756573741a122e757365722e55736572526573706f6e736512390a0a5570646174655573657212172e757365722e55706461746555736572526571756573741a122e757365722e55736572526573706f6e7365123f0a0a44656c6574655573657212172e757365722e44656c65746555736572526571756573741a182e757365722e44656c65746555736572526573706f6e7365123c0a094c697374557365727312162e757365722e4c6973745573657273526571756573741a172e757365722e4c6973745573657273526573706f6e736512490a1041757468656e7469636174655573657212192e757365722e41757468656e746963617465526571756573741a1a2e757365722e41757468656e746963617465526573706f6e736512450a0e4765745573657250726f66696c6512182e757365722e5573657250726f66696c65526571756573741a192e757365722e5573657250726f66696c65526573706f6e736512370a0a4c6f676f75745573657212132e757365722e4c6f676f7574526571756573741a142e757365722e4c6f676f7574526573706f6e736512480a0d56616c6964617465546f6b656e121a2e757365722e56616c6964617465546f6b656e526571756573741a1b2e757365722e56616c6964617465546f6b656e526573706f6e736512450a0c52656672657368546f6b656e12192e757365722e52656672657368546f6b656e526571756573741a1a2e757365722e52656672657368546f6b656e526573706f6e7365124b0a0e4368616e676550617373776f7264121b2e757365722e4368616e676550617373776f7264526571756573741a1c2e757365722e4368616e676550617373776f7264526573706f6e7365422cca020d4170705c477270635c55736572e202194170705c477270635c4750424d657461646174615c55736572620670726f746f33" - ), true); - - static::$is_initialized = true; - } -} - diff --git a/app/Grpc/HealthCheckRequest.php b/app/Grpc/HealthCheckRequest.php deleted file mode 100644 index 262db2c..0000000 --- a/app/Grpc/HealthCheckRequest.php +++ /dev/null @@ -1,58 +0,0 @@ -gateway.HealthCheckRequest - */ -class HealthCheckRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field string service = 1; - */ - protected $service = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $service - * } - */ - public function __construct($data = NULL) { - \App\Grpc\Gateway\Apigw::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field string service = 1; - * @return string - */ - public function getService() - { - return $this->service; - } - - /** - * Generated from protobuf field string service = 1; - * @param string $var - * @return $this - */ - public function setService($var) - { - GPBUtil::checkString($var, True); - $this->service = $var; - - return $this; - } - -} - diff --git a/app/Grpc/HealthCheckResponse.php b/app/Grpc/HealthCheckResponse.php deleted file mode 100644 index 74d33a8..0000000 --- a/app/Grpc/HealthCheckResponse.php +++ /dev/null @@ -1,58 +0,0 @@ -gateway.HealthCheckResponse - */ -class HealthCheckResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field .gateway.HealthCheckResponse.ServingStatus status = 1; - */ - protected $status = 0; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int $status - * } - */ - public function __construct($data = NULL) { - \App\Grpc\Gateway\Apigw::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field .gateway.HealthCheckResponse.ServingStatus status = 1; - * @return int - */ - public function getStatus() - { - return $this->status; - } - - /** - * Generated from protobuf field .gateway.HealthCheckResponse.ServingStatus status = 1; - * @param int $var - * @return $this - */ - public function setStatus($var) - { - GPBUtil::checkEnum($var, \App\Grpc\HealthCheckResponse_ServingStatus::class); - $this->status = $var; - - return $this; - } - -} - diff --git a/app/Grpc/HealthCheckResponse/ServingStatus.php b/app/Grpc/HealthCheckResponse/ServingStatus.php deleted file mode 100644 index 1e1c32d..0000000 --- a/app/Grpc/HealthCheckResponse/ServingStatus.php +++ /dev/null @@ -1,56 +0,0 @@ -gateway.HealthCheckResponse.ServingStatus - */ -class ServingStatus -{ - /** - * Generated from protobuf enum UNKNOWN = 0; - */ - const UNKNOWN = 0; - /** - * Generated from protobuf enum SERVING = 1; - */ - const SERVING = 1; - /** - * Generated from protobuf enum NOT_SERVING = 2; - */ - const NOT_SERVING = 2; - - private static $valueToName = [ - self::UNKNOWN => 'UNKNOWN', - self::SERVING => 'SERVING', - self::NOT_SERVING => 'NOT_SERVING', - ]; - - public static function name($value) - { - if (!isset(self::$valueToName[$value])) { - throw new UnexpectedValueException(sprintf( - 'Enum %s has no name defined for value %s', __CLASS__, $value)); - } - return self::$valueToName[$value]; - } - - - public static function value($name) - { - $const = __CLASS__ . '::' . strtoupper($name); - if (!defined($const)) { - throw new UnexpectedValueException(sprintf( - 'Enum %s has no value defined for name %s', __CLASS__, $name)); - } - return constant($const); - } -} - -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ServingStatus::class, \App\Grpc\HealthCheckResponse_ServingStatus::class); - diff --git a/app/Grpc/HealthCheckResponse_ServingStatus.php b/app/Grpc/HealthCheckResponse_ServingStatus.php deleted file mode 100644 index 4e1274a..0000000 --- a/app/Grpc/HealthCheckResponse_ServingStatus.php +++ /dev/null @@ -1,16 +0,0 @@ -_simpleRequest('/gateway.HealthService/Check', - $argument, - ['\App\Grpc\HealthCheckResponse', 'decode'], - $metadata, $options); - } - -} diff --git a/app/Grpc/Services/BaseServer.php b/app/Grpc/Services/BaseServer.php index ad7ea4d..6959aca 100644 --- a/app/Grpc/Services/BaseServer.php +++ b/app/Grpc/Services/BaseServer.php @@ -79,15 +79,15 @@ public function HandleBytesRequest(BytesRequest $in): BytesResponse return $response; } - /** - * Handle streaming (not implemented for this example) - */ - public function HandleStreamRequest(Iterator $in, ServerContext $context): Iterator - { - foreach ($in as $request) { - yield $this->HandleRequest($request, $context); - } - } +// /** +// * Handle streaming (not implemented for this example) +// */ +// public function HandleStreamRequest(Iterator $in, ServerContext $context): Iterator +// { +// foreach ($in as $request) { +// yield $this->HandleRequest($request, $context); +// } +// } /** * Create error response diff --git a/app/Grpc/User/AuthenticateRequest.php b/app/Grpc/User/AuthenticateRequest.php deleted file mode 100644 index 4b88e4d..0000000 --- a/app/Grpc/User/AuthenticateRequest.php +++ /dev/null @@ -1,85 +0,0 @@ -user.AuthenticateRequest - */ -class AuthenticateRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field string email = 1; - */ - protected $email = ''; - /** - * Generated from protobuf field string password = 2; - */ - protected $password = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $email - * @type string $password - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field string email = 1; - * @return string - */ - public function getEmail() - { - return $this->email; - } - - /** - * Generated from protobuf field string email = 1; - * @param string $var - * @return $this - */ - public function setEmail($var) - { - GPBUtil::checkString($var, True); - $this->email = $var; - - return $this; - } - - /** - * Generated from protobuf field string password = 2; - * @return string - */ - public function getPassword() - { - return $this->password; - } - - /** - * Generated from protobuf field string password = 2; - * @param string $var - * @return $this - */ - public function setPassword($var) - { - GPBUtil::checkString($var, True); - $this->password = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/AuthenticateResponse.php b/app/Grpc/User/AuthenticateResponse.php deleted file mode 100644 index ce25214..0000000 --- a/app/Grpc/User/AuthenticateResponse.php +++ /dev/null @@ -1,193 +0,0 @@ -user.AuthenticateResponse - */ -class AuthenticateResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field .user.User user = 1; - */ - protected $user = null; - /** - * Generated from protobuf field string token = 2; - */ - protected $token = ''; - /** - * Generated from protobuf field string token_type = 3; - */ - protected $token_type = ''; - /** - * Generated from protobuf field string expires_at = 4; - */ - protected $expires_at = ''; - /** - * Generated from protobuf field bool success = 5; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 6; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \App\Grpc\User\User $user - * @type string $token - * @type string $token_type - * @type string $expires_at - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field .user.User user = 1; - * @return \App\Grpc\User\User - */ - public function getUser() - { - return $this->user; - } - - /** - * Generated from protobuf field .user.User user = 1; - * @param \App\Grpc\User\User $var - * @return $this - */ - public function setUser($var) - { - GPBUtil::checkMessage($var, \App\Grpc\User\User::class); - $this->user = $var; - - return $this; - } - - /** - * Generated from protobuf field string token = 2; - * @return string - */ - public function getToken() - { - return $this->token; - } - - /** - * Generated from protobuf field string token = 2; - * @param string $var - * @return $this - */ - public function setToken($var) - { - GPBUtil::checkString($var, True); - $this->token = $var; - - return $this; - } - - /** - * Generated from protobuf field string token_type = 3; - * @return string - */ - public function getTokenType() - { - return $this->token_type; - } - - /** - * Generated from protobuf field string token_type = 3; - * @param string $var - * @return $this - */ - public function setTokenType($var) - { - GPBUtil::checkString($var, True); - $this->token_type = $var; - - return $this; - } - - /** - * Generated from protobuf field string expires_at = 4; - * @return string - */ - public function getExpiresAt() - { - return $this->expires_at; - } - - /** - * Generated from protobuf field string expires_at = 4; - * @param string $var - * @return $this - */ - public function setExpiresAt($var) - { - GPBUtil::checkString($var, True); - $this->expires_at = $var; - - return $this; - } - - /** - * Generated from protobuf field bool success = 5; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 5; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 6; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 6; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/CartItem.php b/app/Grpc/User/CartItem.php deleted file mode 100644 index b954222..0000000 --- a/app/Grpc/User/CartItem.php +++ /dev/null @@ -1,139 +0,0 @@ -user.CartItem - */ -class CartItem extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field int64 id = 1; - */ - protected $id = 0; - /** - * Generated from protobuf field string type = 2; - */ - protected $type = ''; - /** - * Generated from protobuf field int32 quantity = 3; - */ - protected $quantity = 0; - /** - * Generated from protobuf field double price = 4; - */ - protected $price = 0.0; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $id - * @type string $type - * @type int $quantity - * @type float $price - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field int64 id = 1; - * @return int|string - */ - public function getId() - { - return $this->id; - } - - /** - * Generated from protobuf field int64 id = 1; - * @param int|string $var - * @return $this - */ - public function setId($var) - { - GPBUtil::checkInt64($var); - $this->id = $var; - - return $this; - } - - /** - * Generated from protobuf field string type = 2; - * @return string - */ - public function getType() - { - return $this->type; - } - - /** - * Generated from protobuf field string type = 2; - * @param string $var - * @return $this - */ - public function setType($var) - { - GPBUtil::checkString($var, True); - $this->type = $var; - - return $this; - } - - /** - * Generated from protobuf field int32 quantity = 3; - * @return int - */ - public function getQuantity() - { - return $this->quantity; - } - - /** - * Generated from protobuf field int32 quantity = 3; - * @param int $var - * @return $this - */ - public function setQuantity($var) - { - GPBUtil::checkInt32($var); - $this->quantity = $var; - - return $this; - } - - /** - * Generated from protobuf field double price = 4; - * @return float - */ - public function getPrice() - { - return $this->price; - } - - /** - * Generated from protobuf field double price = 4; - * @param float $var - * @return $this - */ - public function setPrice($var) - { - GPBUtil::checkDouble($var); - $this->price = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/ChangePasswordRequest.php b/app/Grpc/User/ChangePasswordRequest.php deleted file mode 100644 index 9768234..0000000 --- a/app/Grpc/User/ChangePasswordRequest.php +++ /dev/null @@ -1,85 +0,0 @@ -user.ChangePasswordRequest - */ -class ChangePasswordRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field string current_password = 1; - */ - protected $current_password = ''; - /** - * Generated from protobuf field string new_password = 2; - */ - protected $new_password = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $current_password - * @type string $new_password - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field string current_password = 1; - * @return string - */ - public function getCurrentPassword() - { - return $this->current_password; - } - - /** - * Generated from protobuf field string current_password = 1; - * @param string $var - * @return $this - */ - public function setCurrentPassword($var) - { - GPBUtil::checkString($var, True); - $this->current_password = $var; - - return $this; - } - - /** - * Generated from protobuf field string new_password = 2; - * @return string - */ - public function getNewPassword() - { - return $this->new_password; - } - - /** - * Generated from protobuf field string new_password = 2; - * @param string $var - * @return $this - */ - public function setNewPassword($var) - { - GPBUtil::checkString($var, True); - $this->new_password = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/ChangePasswordResponse.php b/app/Grpc/User/ChangePasswordResponse.php deleted file mode 100644 index ce1ec24..0000000 --- a/app/Grpc/User/ChangePasswordResponse.php +++ /dev/null @@ -1,85 +0,0 @@ -user.ChangePasswordResponse - */ -class ChangePasswordResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field bool success = 1; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 2; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field bool success = 1; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 1; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 2; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 2; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/CreateUserRequest.php b/app/Grpc/User/CreateUserRequest.php deleted file mode 100644 index d229886..0000000 --- a/app/Grpc/User/CreateUserRequest.php +++ /dev/null @@ -1,139 +0,0 @@ -user.CreateUserRequest - */ -class CreateUserRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field string name = 1; - */ - protected $name = ''; - /** - * Generated from protobuf field string email = 2; - */ - protected $email = ''; - /** - * Generated from protobuf field string password = 3; - */ - protected $password = ''; - /** - * Generated from protobuf field string role = 4; - */ - protected $role = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $name - * @type string $email - * @type string $password - * @type string $role - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field string name = 1; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Generated from protobuf field string name = 1; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - - /** - * Generated from protobuf field string email = 2; - * @return string - */ - public function getEmail() - { - return $this->email; - } - - /** - * Generated from protobuf field string email = 2; - * @param string $var - * @return $this - */ - public function setEmail($var) - { - GPBUtil::checkString($var, True); - $this->email = $var; - - return $this; - } - - /** - * Generated from protobuf field string password = 3; - * @return string - */ - public function getPassword() - { - return $this->password; - } - - /** - * Generated from protobuf field string password = 3; - * @param string $var - * @return $this - */ - public function setPassword($var) - { - GPBUtil::checkString($var, True); - $this->password = $var; - - return $this; - } - - /** - * Generated from protobuf field string role = 4; - * @return string - */ - public function getRole() - { - return $this->role; - } - - /** - * Generated from protobuf field string role = 4; - * @param string $var - * @return $this - */ - public function setRole($var) - { - GPBUtil::checkString($var, True); - $this->role = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/DeleteUserRequest.php b/app/Grpc/User/DeleteUserRequest.php deleted file mode 100644 index c48203b..0000000 --- a/app/Grpc/User/DeleteUserRequest.php +++ /dev/null @@ -1,58 +0,0 @@ -user.DeleteUserRequest - */ -class DeleteUserRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field int64 id = 1; - */ - protected $id = 0; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $id - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field int64 id = 1; - * @return int|string - */ - public function getId() - { - return $this->id; - } - - /** - * Generated from protobuf field int64 id = 1; - * @param int|string $var - * @return $this - */ - public function setId($var) - { - GPBUtil::checkInt64($var); - $this->id = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/DeleteUserResponse.php b/app/Grpc/User/DeleteUserResponse.php deleted file mode 100644 index 600e394..0000000 --- a/app/Grpc/User/DeleteUserResponse.php +++ /dev/null @@ -1,85 +0,0 @@ -user.DeleteUserResponse - */ -class DeleteUserResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field bool success = 1; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 2; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field bool success = 1; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 1; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 2; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 2; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/GetUserRequest.php b/app/Grpc/User/GetUserRequest.php deleted file mode 100644 index eae8edb..0000000 --- a/app/Grpc/User/GetUserRequest.php +++ /dev/null @@ -1,60 +0,0 @@ -user.GetUserRequest - */ -class GetUserRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field int64 id = 1; - */ - protected $id = 0; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $id - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field int64 id = 1; - * @return int|string - */ - public function getId() - { - return $this->id; - } - - /** - * Generated from protobuf field int64 id = 1; - * @param int|string $var - * @return $this - */ - public function setId($var) - { - GPBUtil::checkInt64($var); - $this->id = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/ListUsersRequest.php b/app/Grpc/User/ListUsersRequest.php deleted file mode 100644 index 97d3d50..0000000 --- a/app/Grpc/User/ListUsersRequest.php +++ /dev/null @@ -1,112 +0,0 @@ -user.ListUsersRequest - */ -class ListUsersRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field int32 page = 1; - */ - protected $page = 0; - /** - * Generated from protobuf field int32 per_page = 2; - */ - protected $per_page = 0; - /** - * Generated from protobuf field string search = 3; - */ - protected $search = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int $page - * @type int $per_page - * @type string $search - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field int32 page = 1; - * @return int - */ - public function getPage() - { - return $this->page; - } - - /** - * Generated from protobuf field int32 page = 1; - * @param int $var - * @return $this - */ - public function setPage($var) - { - GPBUtil::checkInt32($var); - $this->page = $var; - - return $this; - } - - /** - * Generated from protobuf field int32 per_page = 2; - * @return int - */ - public function getPerPage() - { - return $this->per_page; - } - - /** - * Generated from protobuf field int32 per_page = 2; - * @param int $var - * @return $this - */ - public function setPerPage($var) - { - GPBUtil::checkInt32($var); - $this->per_page = $var; - - return $this; - } - - /** - * Generated from protobuf field string search = 3; - * @return string - */ - public function getSearch() - { - return $this->search; - } - - /** - * Generated from protobuf field string search = 3; - * @param string $var - * @return $this - */ - public function setSearch($var) - { - GPBUtil::checkString($var, True); - $this->search = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/ListUsersResponse.php b/app/Grpc/User/ListUsersResponse.php deleted file mode 100644 index ac84a51..0000000 --- a/app/Grpc/User/ListUsersResponse.php +++ /dev/null @@ -1,193 +0,0 @@ -user.ListUsersResponse - */ -class ListUsersResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field repeated .user.User users = 1; - */ - private $users; - /** - * Generated from protobuf field int32 total = 2; - */ - protected $total = 0; - /** - * Generated from protobuf field int32 current_page = 3; - */ - protected $current_page = 0; - /** - * Generated from protobuf field int32 last_page = 4; - */ - protected $last_page = 0; - /** - * Generated from protobuf field bool success = 5; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 6; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \App\Grpc\User\User[]|\Google\Protobuf\Internal\RepeatedField $users - * @type int $total - * @type int $current_page - * @type int $last_page - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field repeated .user.User users = 1; - * @return \Google\Protobuf\Internal\RepeatedField - */ - public function getUsers() - { - return $this->users; - } - - /** - * Generated from protobuf field repeated .user.User users = 1; - * @param \App\Grpc\User\User[]|\Google\Protobuf\Internal\RepeatedField $var - * @return $this - */ - public function setUsers($var) - { - $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \App\Grpc\User\User::class); - $this->users = $arr; - - return $this; - } - - /** - * Generated from protobuf field int32 total = 2; - * @return int - */ - public function getTotal() - { - return $this->total; - } - - /** - * Generated from protobuf field int32 total = 2; - * @param int $var - * @return $this - */ - public function setTotal($var) - { - GPBUtil::checkInt32($var); - $this->total = $var; - - return $this; - } - - /** - * Generated from protobuf field int32 current_page = 3; - * @return int - */ - public function getCurrentPage() - { - return $this->current_page; - } - - /** - * Generated from protobuf field int32 current_page = 3; - * @param int $var - * @return $this - */ - public function setCurrentPage($var) - { - GPBUtil::checkInt32($var); - $this->current_page = $var; - - return $this; - } - - /** - * Generated from protobuf field int32 last_page = 4; - * @return int - */ - public function getLastPage() - { - return $this->last_page; - } - - /** - * Generated from protobuf field int32 last_page = 4; - * @param int $var - * @return $this - */ - public function setLastPage($var) - { - GPBUtil::checkInt32($var); - $this->last_page = $var; - - return $this; - } - - /** - * Generated from protobuf field bool success = 5; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 5; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 6; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 6; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/LogoutRequest.php b/app/Grpc/User/LogoutRequest.php deleted file mode 100644 index 9f612e2..0000000 --- a/app/Grpc/User/LogoutRequest.php +++ /dev/null @@ -1,31 +0,0 @@ -user.LogoutRequest - */ -class LogoutRequest extends \Google\Protobuf\Internal\Message -{ - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - -} - diff --git a/app/Grpc/User/LogoutResponse.php b/app/Grpc/User/LogoutResponse.php deleted file mode 100644 index 83b04b7..0000000 --- a/app/Grpc/User/LogoutResponse.php +++ /dev/null @@ -1,85 +0,0 @@ -user.LogoutResponse - */ -class LogoutResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field bool success = 1; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 2; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field bool success = 1; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 1; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 2; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 2; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/RefreshTokenRequest.php b/app/Grpc/User/RefreshTokenRequest.php deleted file mode 100644 index 1a470f9..0000000 --- a/app/Grpc/User/RefreshTokenRequest.php +++ /dev/null @@ -1,31 +0,0 @@ -user.RefreshTokenRequest - */ -class RefreshTokenRequest extends \Google\Protobuf\Internal\Message -{ - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - -} - diff --git a/app/Grpc/User/RefreshTokenResponse.php b/app/Grpc/User/RefreshTokenResponse.php deleted file mode 100644 index 8999b2b..0000000 --- a/app/Grpc/User/RefreshTokenResponse.php +++ /dev/null @@ -1,166 +0,0 @@ -user.RefreshTokenResponse - */ -class RefreshTokenResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field string token = 1; - */ - protected $token = ''; - /** - * Generated from protobuf field string token_type = 2; - */ - protected $token_type = ''; - /** - * Generated from protobuf field string expires_at = 3; - */ - protected $expires_at = ''; - /** - * Generated from protobuf field bool success = 4; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 5; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $token - * @type string $token_type - * @type string $expires_at - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field string token = 1; - * @return string - */ - public function getToken() - { - return $this->token; - } - - /** - * Generated from protobuf field string token = 1; - * @param string $var - * @return $this - */ - public function setToken($var) - { - GPBUtil::checkString($var, True); - $this->token = $var; - - return $this; - } - - /** - * Generated from protobuf field string token_type = 2; - * @return string - */ - public function getTokenType() - { - return $this->token_type; - } - - /** - * Generated from protobuf field string token_type = 2; - * @param string $var - * @return $this - */ - public function setTokenType($var) - { - GPBUtil::checkString($var, True); - $this->token_type = $var; - - return $this; - } - - /** - * Generated from protobuf field string expires_at = 3; - * @return string - */ - public function getExpiresAt() - { - return $this->expires_at; - } - - /** - * Generated from protobuf field string expires_at = 3; - * @param string $var - * @return $this - */ - public function setExpiresAt($var) - { - GPBUtil::checkString($var, True); - $this->expires_at = $var; - - return $this; - } - - /** - * Generated from protobuf field bool success = 4; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 4; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 5; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 5; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/UpdateUserRequest.php b/app/Grpc/User/UpdateUserRequest.php deleted file mode 100644 index 8363942..0000000 --- a/app/Grpc/User/UpdateUserRequest.php +++ /dev/null @@ -1,139 +0,0 @@ -user.UpdateUserRequest - */ -class UpdateUserRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field int64 id = 1; - */ - protected $id = 0; - /** - * Generated from protobuf field string name = 2; - */ - protected $name = ''; - /** - * Generated from protobuf field string email = 3; - */ - protected $email = ''; - /** - * Generated from protobuf field string password = 4; - */ - protected $password = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $id - * @type string $name - * @type string $email - * @type string $password - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field int64 id = 1; - * @return int|string - */ - public function getId() - { - return $this->id; - } - - /** - * Generated from protobuf field int64 id = 1; - * @param int|string $var - * @return $this - */ - public function setId($var) - { - GPBUtil::checkInt64($var); - $this->id = $var; - - return $this; - } - - /** - * Generated from protobuf field string name = 2; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Generated from protobuf field string name = 2; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - - /** - * Generated from protobuf field string email = 3; - * @return string - */ - public function getEmail() - { - return $this->email; - } - - /** - * Generated from protobuf field string email = 3; - * @param string $var - * @return $this - */ - public function setEmail($var) - { - GPBUtil::checkString($var, True); - $this->email = $var; - - return $this; - } - - /** - * Generated from protobuf field string password = 4; - * @return string - */ - public function getPassword() - { - return $this->password; - } - - /** - * Generated from protobuf field string password = 4; - * @param string $var - * @return $this - */ - public function setPassword($var) - { - GPBUtil::checkString($var, True); - $this->password = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/User.php b/app/Grpc/User/User.php deleted file mode 100644 index e66ff64..0000000 --- a/app/Grpc/User/User.php +++ /dev/null @@ -1,249 +0,0 @@ -user.User - */ -class User extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field int64 id = 1; - */ - protected $id = 0; - /** - * Generated from protobuf field string name = 2; - */ - protected $name = ''; - /** - * Generated from protobuf field string email = 3; - */ - protected $email = ''; - /** - * Generated from protobuf field string role = 4; - */ - protected $role = ''; - /** - * Generated from protobuf field string photo_path = 5; - */ - protected $photo_path = ''; - /** - * Generated from protobuf field string access_token = 6; - */ - protected $access_token = ''; - /** - * Generated from protobuf field string created_at = 7; - */ - protected $created_at = ''; - /** - * Generated from protobuf field string updated_at = 8; - */ - protected $updated_at = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $id - * @type string $name - * @type string $email - * @type string $role - * @type string $photo_path - * @type string $access_token - * @type string $created_at - * @type string $updated_at - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field int64 id = 1; - * @return int|string - */ - public function getId() - { - return $this->id; - } - - /** - * Generated from protobuf field int64 id = 1; - * @param int|string $var - * @return $this - */ - public function setId($var) - { - GPBUtil::checkInt64($var); - $this->id = $var; - - return $this; - } - - /** - * Generated from protobuf field string name = 2; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Generated from protobuf field string name = 2; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - - /** - * Generated from protobuf field string email = 3; - * @return string - */ - public function getEmail() - { - return $this->email; - } - - /** - * Generated from protobuf field string email = 3; - * @param string $var - * @return $this - */ - public function setEmail($var) - { - GPBUtil::checkString($var, True); - $this->email = $var; - - return $this; - } - - /** - * Generated from protobuf field string role = 4; - * @return string - */ - public function getRole() - { - return $this->role; - } - - /** - * Generated from protobuf field string role = 4; - * @param string $var - * @return $this - */ - public function setRole($var) - { - GPBUtil::checkString($var, True); - $this->role = $var; - - return $this; - } - - /** - * Generated from protobuf field string photo_path = 5; - * @return string - */ - public function getPhotoPath() - { - return $this->photo_path; - } - - /** - * Generated from protobuf field string photo_path = 5; - * @param string $var - * @return $this - */ - public function setPhotoPath($var) - { - GPBUtil::checkString($var, True); - $this->photo_path = $var; - - return $this; - } - - /** - * Generated from protobuf field string access_token = 6; - * @return string - */ - public function getAccessToken() - { - return $this->access_token; - } - - /** - * Generated from protobuf field string access_token = 6; - * @param string $var - * @return $this - */ - public function setAccessToken($var) - { - GPBUtil::checkString($var, True); - $this->access_token = $var; - - return $this; - } - - /** - * Generated from protobuf field string created_at = 7; - * @return string - */ - public function getCreatedAt() - { - return $this->created_at; - } - - /** - * Generated from protobuf field string created_at = 7; - * @param string $var - * @return $this - */ - public function setCreatedAt($var) - { - GPBUtil::checkString($var, True); - $this->created_at = $var; - - return $this; - } - - /** - * Generated from protobuf field string updated_at = 8; - * @return string - */ - public function getUpdatedAt() - { - return $this->updated_at; - } - - /** - * Generated from protobuf field string updated_at = 8; - * @param string $var - * @return $this - */ - public function setUpdatedAt($var) - { - GPBUtil::checkString($var, True); - $this->updated_at = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/UserProfileRequest.php b/app/Grpc/User/UserProfileRequest.php deleted file mode 100644 index 8677915..0000000 --- a/app/Grpc/User/UserProfileRequest.php +++ /dev/null @@ -1,58 +0,0 @@ -user.UserProfileRequest - */ -class UserProfileRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field repeated string fields = 2; - */ - private $fields; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string[]|\Google\Protobuf\Internal\RepeatedField $fields - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field repeated string fields = 2; - * @return \Google\Protobuf\Internal\RepeatedField - */ - public function getFields() - { - return $this->fields; - } - - /** - * Generated from protobuf field repeated string fields = 2; - * @param string[]|\Google\Protobuf\Internal\RepeatedField $var - * @return $this - */ - public function setFields($var) - { - $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); - $this->fields = $arr; - - return $this; - } - -} - diff --git a/app/Grpc/User/UserProfileResponse.php b/app/Grpc/User/UserProfileResponse.php deleted file mode 100644 index d574745..0000000 --- a/app/Grpc/User/UserProfileResponse.php +++ /dev/null @@ -1,247 +0,0 @@ -user.UserProfileResponse - */ -class UserProfileResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field int64 id = 1; - */ - protected $id = 0; - /** - * Generated from protobuf field string name = 2; - */ - protected $name = ''; - /** - * Generated from protobuf field string email = 3; - */ - protected $email = ''; - /** - * Generated from protobuf field string photo_path = 4; - */ - protected $photo_path = ''; - /** - * Generated from protobuf field string role = 5; - */ - protected $role = ''; - /** - * Generated from protobuf field repeated .user.CartItem cart_items = 6; - */ - private $cart_items; - /** - * Generated from protobuf field bool success = 7; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 8; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $id - * @type string $name - * @type string $email - * @type string $photo_path - * @type string $role - * @type \App\Grpc\User\CartItem[]|\Google\Protobuf\Internal\RepeatedField $cart_items - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field int64 id = 1; - * @return int|string - */ - public function getId() - { - return $this->id; - } - - /** - * Generated from protobuf field int64 id = 1; - * @param int|string $var - * @return $this - */ - public function setId($var) - { - GPBUtil::checkInt64($var); - $this->id = $var; - - return $this; - } - - /** - * Generated from protobuf field string name = 2; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Generated from protobuf field string name = 2; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - - /** - * Generated from protobuf field string email = 3; - * @return string - */ - public function getEmail() - { - return $this->email; - } - - /** - * Generated from protobuf field string email = 3; - * @param string $var - * @return $this - */ - public function setEmail($var) - { - GPBUtil::checkString($var, True); - $this->email = $var; - - return $this; - } - - /** - * Generated from protobuf field string photo_path = 4; - * @return string - */ - public function getPhotoPath() - { - return $this->photo_path; - } - - /** - * Generated from protobuf field string photo_path = 4; - * @param string $var - * @return $this - */ - public function setPhotoPath($var) - { - GPBUtil::checkString($var, True); - $this->photo_path = $var; - - return $this; - } - - /** - * Generated from protobuf field string role = 5; - * @return string - */ - public function getRole() - { - return $this->role; - } - - /** - * Generated from protobuf field string role = 5; - * @param string $var - * @return $this - */ - public function setRole($var) - { - GPBUtil::checkString($var, True); - $this->role = $var; - - return $this; - } - - /** - * Generated from protobuf field repeated .user.CartItem cart_items = 6; - * @return \Google\Protobuf\Internal\RepeatedField - */ - public function getCartItems() - { - return $this->cart_items; - } - - /** - * Generated from protobuf field repeated .user.CartItem cart_items = 6; - * @param \App\Grpc\User\CartItem[]|\Google\Protobuf\Internal\RepeatedField $var - * @return $this - */ - public function setCartItems($var) - { - $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \App\Grpc\User\CartItem::class); - $this->cart_items = $arr; - - return $this; - } - - /** - * Generated from protobuf field bool success = 7; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 7; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 8; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 8; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/UserResponse.php b/app/Grpc/User/UserResponse.php deleted file mode 100644 index b7ad7d2..0000000 --- a/app/Grpc/User/UserResponse.php +++ /dev/null @@ -1,114 +0,0 @@ -user.UserResponse - */ -class UserResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field .user.User user = 1; - */ - protected $user = null; - /** - * Generated from protobuf field bool success = 2; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 3; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \App\Grpc\User\User $user - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field .user.User user = 1; - * @return \App\Grpc\User\User - */ - public function getUser() - { - return $this->user; - } - - /** - * Generated from protobuf field .user.User user = 1; - * @param \App\Grpc\User\User $var - * @return $this - */ - public function setUser($var) - { - GPBUtil::checkMessage($var, \App\Grpc\User\User::class); - $this->user = $var; - - return $this; - } - - /** - * Generated from protobuf field bool success = 2; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 2; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 3; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 3; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/UserServiceClient.php b/app/Grpc/User/UserServiceClient.php deleted file mode 100644 index cca9b6c..0000000 --- a/app/Grpc/User/UserServiceClient.php +++ /dev/null @@ -1,175 +0,0 @@ -_simpleRequest('/user.UserService/GetUser', - $argument, - ['\App\Grpc\User\UserResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\CreateUserRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\UserResponse - */ - public function CreateUser(\App\Grpc\User\CreateUserRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/CreateUser', - $argument, - ['\App\Grpc\User\UserResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\UpdateUserRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\UserResponse - */ - public function UpdateUser(\App\Grpc\User\UpdateUserRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/UpdateUser', - $argument, - ['\App\Grpc\User\UserResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\DeleteUserRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\DeleteUserResponse - */ - public function DeleteUser(\App\Grpc\User\DeleteUserRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/DeleteUser', - $argument, - ['\App\Grpc\User\DeleteUserResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\ListUsersRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\ListUsersResponse - */ - public function ListUsers(\App\Grpc\User\ListUsersRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/ListUsers', - $argument, - ['\App\Grpc\User\ListUsersResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\AuthenticateRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\AuthenticateResponse - */ - public function AuthenticateUser(\App\Grpc\User\AuthenticateRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/AuthenticateUser', - $argument, - ['\App\Grpc\User\AuthenticateResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\UserProfileRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\UserProfileResponse - */ - public function GetUserProfile(\App\Grpc\User\UserProfileRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/GetUserProfile', - $argument, - ['\App\Grpc\User\UserProfileResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\LogoutRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\LogoutResponse - */ - public function LogoutUser(\App\Grpc\User\LogoutRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/LogoutUser', - $argument, - ['\App\Grpc\User\LogoutResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\ValidateTokenRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\ValidateTokenResponse - */ - public function ValidateToken(\App\Grpc\User\ValidateTokenRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/ValidateToken', - $argument, - ['\App\Grpc\User\ValidateTokenResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\RefreshTokenRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\RefreshTokenResponse - */ - public function RefreshToken(\App\Grpc\User\RefreshTokenRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/RefreshToken', - $argument, - ['\App\Grpc\User\RefreshTokenResponse', 'decode'], - $metadata, $options); - } - - /** - * @param \App\Grpc\User\ChangePasswordRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \App\Grpc\User\ChangePasswordResponse - */ - public function ChangePassword(\App\Grpc\User\ChangePasswordRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/user.UserService/ChangePassword', - $argument, - ['\App\Grpc\User\ChangePasswordResponse', 'decode'], - $metadata, $options); - } - -} diff --git a/app/Grpc/User/ValidateTokenRequest.php b/app/Grpc/User/ValidateTokenRequest.php deleted file mode 100644 index cc819bf..0000000 --- a/app/Grpc/User/ValidateTokenRequest.php +++ /dev/null @@ -1,58 +0,0 @@ -user.ValidateTokenRequest - */ -class ValidateTokenRequest extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field string token = 1; - */ - protected $token = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $token - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field string token = 1; - * @return string - */ - public function getToken() - { - return $this->token; - } - - /** - * Generated from protobuf field string token = 1; - * @param string $var - * @return $this - */ - public function setToken($var) - { - GPBUtil::checkString($var, True); - $this->token = $var; - - return $this; - } - -} - diff --git a/app/Grpc/User/ValidateTokenResponse.php b/app/Grpc/User/ValidateTokenResponse.php deleted file mode 100644 index cf2bddd..0000000 --- a/app/Grpc/User/ValidateTokenResponse.php +++ /dev/null @@ -1,139 +0,0 @@ -user.ValidateTokenResponse - */ -class ValidateTokenResponse extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field .user.User user = 1; - */ - protected $user = null; - /** - * Generated from protobuf field bool valid = 2; - */ - protected $valid = false; - /** - * Generated from protobuf field bool success = 3; - */ - protected $success = false; - /** - * Generated from protobuf field string message = 4; - */ - protected $message = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \App\Grpc\User\User $user - * @type bool $valid - * @type bool $success - * @type string $message - * } - */ - public function __construct($data = NULL) { - \App\Grpc\GPBMetadata\User\UserService::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field .user.User user = 1; - * @return \App\Grpc\User\User - */ - public function getUser() - { - return $this->user; - } - - /** - * Generated from protobuf field .user.User user = 1; - * @param \App\Grpc\User\User $var - * @return $this - */ - public function setUser($var) - { - GPBUtil::checkMessage($var, \App\Grpc\User\User::class); - $this->user = $var; - - return $this; - } - - /** - * Generated from protobuf field bool valid = 2; - * @return bool - */ - public function getValid() - { - return $this->valid; - } - - /** - * Generated from protobuf field bool valid = 2; - * @param bool $var - * @return $this - */ - public function setValid($var) - { - GPBUtil::checkBool($var); - $this->valid = $var; - - return $this; - } - - /** - * Generated from protobuf field bool success = 3; - * @return bool - */ - public function getSuccess() - { - return $this->success; - } - - /** - * Generated from protobuf field bool success = 3; - * @param bool $var - * @return $this - */ - public function setSuccess($var) - { - GPBUtil::checkBool($var); - $this->success = $var; - - return $this; - } - - /** - * Generated from protobuf field string message = 4; - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * Generated from protobuf field string message = 4; - * @param string $var - * @return $this - */ - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - - return $this; - } - -} - diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index d06ae49..89cef64 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -21,7 +21,7 @@ public function toArray(Request $request): array 'email' => data_get($this, 'email'), 'photo_url' => $this->when(data_get($this, 'photo_path'), ApiGateway::storageUri() . data_get($this, 'photo_path')), 'token' => $this->whenNotNull(data_get($this, 'accessToken')), - 'token_expires_at' => $this->whenNotNull(data_get($this, 'accessToken')), + 'token_expires_at' => $this->whenNotNull(data_get($this, 'tokenExpiresAt')), 'role_name' => data_get($this, 'role'), ]); } From 0c35df4532dce225d62c2a73ab3a7fdd9f59a1fa Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Sat, 14 Jun 2025 00:45:12 +0300 Subject: [PATCH 02/12] Introduce gRPC implementation, including route registry, base service, controllers, and request/response handling. Integrate `GrpcServiceProvider` and update configuration and bootstrap files. --- app/Console/Commands/GrpcServeCommand.php | 2 +- app/Grpc/Controllers/AuthController.php | 68 +++++++ app/Grpc/Controllers/BaseGrpcService.php | 68 +++++++ app/Grpc/Controllers/CartController.php | 0 app/Grpc/Controllers/UserController.php | 76 ++++++++ app/Grpc/GrpcRoute.php | 11 ++ app/Grpc/GrpcRouteRegistry.php | 31 +++ app/Grpc/GrpcServiceRouter.php | 19 ++ app/Grpc/Services/BaseServer.php | 38 +--- app/Grpc/Services/CartServer.php | 3 +- app/Grpc/Services/GrpcService.php | 55 ++++++ app/Grpc/Services/UserGrpcService.php | 220 ++++++++++++++++++++++ app/Grpc/Services/UserServer.php | 4 +- app/Providers/GrpcServiceProvider.php | 20 ++ bootstrap/providers.php | 3 +- config/services.php | 1 + routes/grpc.php | 21 +++ 17 files changed, 598 insertions(+), 42 deletions(-) create mode 100644 app/Grpc/Controllers/AuthController.php create mode 100644 app/Grpc/Controllers/BaseGrpcService.php create mode 100644 app/Grpc/Controllers/CartController.php create mode 100644 app/Grpc/Controllers/UserController.php create mode 100644 app/Grpc/GrpcRoute.php create mode 100644 app/Grpc/GrpcRouteRegistry.php create mode 100644 app/Grpc/GrpcServiceRouter.php create mode 100644 app/Grpc/Services/GrpcService.php create mode 100644 app/Grpc/Services/UserGrpcService.php create mode 100644 app/Providers/GrpcServiceProvider.php create mode 100644 routes/grpc.php diff --git a/app/Console/Commands/GrpcServeCommand.php b/app/Console/Commands/GrpcServeCommand.php index 31c1b04..dcf4076 100644 --- a/app/Console/Commands/GrpcServeCommand.php +++ b/app/Console/Commands/GrpcServeCommand.php @@ -23,7 +23,7 @@ public function handle(): int $server->addHttp2Port("{$host}:{$port}"); // Register the User service - $server->handle(app(\App\Grpc\Services\UserServer::class)); + $server->handle(app(\App\Grpc\Services\UserGrpcService::class)); $this->info('gRPC User Service started successfully'); $this->info('Listening for requests...'); diff --git a/app/Grpc/Controllers/AuthController.php b/app/Grpc/Controllers/AuthController.php new file mode 100644 index 0000000..d8cfb66 --- /dev/null +++ b/app/Grpc/Controllers/AuthController.php @@ -0,0 +1,68 @@ +getPayload()->getValue(); + $userData = json_decode($jsonData, true); + $rules = new UserCreateRequest()->rules(); + $validator = Validator::make($userData, $rules); + if ($validator->fails()) { + return $this->createErrorResponse( + $response, + Response::HTTP_UNPROCESSABLE_ENTITY, + STATUS_INVALID_ARGUMENT, + $validator->errors(), + errorMsg: ['message' => 'Validation errors'] + ); + } + + // Pack response + $responseData = new Any(); + try { + $user = $this->userService->create($userData); + $userResource = new UserResource($user); + $responseData->setValue(json_encode([ + 'data' => $userResource + ])); + $response->setSuccess(true); + $response->setStatusCode(201); + $response->setData($responseData); + } catch (Exception $e) { + Log::error('User creation error', [ + 'error' => $e->getMessage(), + 'trace' => $e->getTrace() + ]); + throw $e; // Re-throw to be caught by the outer try-catch + } + + + return $response; + } + +} diff --git a/app/Grpc/Controllers/BaseGrpcService.php b/app/Grpc/Controllers/BaseGrpcService.php new file mode 100644 index 0000000..7377274 --- /dev/null +++ b/app/Grpc/Controllers/BaseGrpcService.php @@ -0,0 +1,68 @@ +setValue(json_encode($data)); + $response->setData($responseData); + $response->setSuccess(true); + $response->setStatusCode($code); + return $response; + } + + /** + * Create error response + */ + public function createErrorResponse(FlexibleResponse $response, int $statusCode, $code, string $message, ?array $errorMsg = null): FlexibleResponse + { + BaseGrpcService::getContext()->setStatus([ + 'code' => $code, + 'details' => $message + ]); + $error = new ErrorInfo(); + $error->setCode($code); + $error->setMessage($message); + + if (!is_null($errorMsg)) { + $any = new Any(); + $any->setValue(json_encode($errorMsg)); + $response->setData($any); + } + + $response->setSuccess(false); + $response->setStatusCode($statusCode); + $response->setError($error); + + return $response; + } +} diff --git a/app/Grpc/Controllers/CartController.php b/app/Grpc/Controllers/CartController.php new file mode 100644 index 0000000..e69de29 diff --git a/app/Grpc/Controllers/UserController.php b/app/Grpc/Controllers/UserController.php new file mode 100644 index 0000000..bce9ac9 --- /dev/null +++ b/app/Grpc/Controllers/UserController.php @@ -0,0 +1,76 @@ +getPayload()->getValue(); + $data = json_decode($jsonData, true); + + $validator = Validator::make($data, [ + 'id' => 'required|integer|min:1' + ]); + $validator->validate(); + if ($validator->fails()) { + $this->createErrorResponse( + $response, + Response::HTTP_BAD_REQUEST, + STATUS_INVALID_ARGUMENT, + $validator->errors() + ); + return $response; +// throw new Exception($validator->errors(), STATUS_INVALID_ARGUMENT); + } + $user = $this->userService->show($data['id']); + $user = $user['data']; + if (!$user) { + $this->createErrorResponse( + $response, + Response::HTTP_NOT_FOUND, + STATUS_NOT_FOUND, + 'User not found: ' . ($data['id'] ?? 'unknown') + ); + return $response; +// throw new Exception($message, STATUS_NOT_FOUND); + } + + $responseData = new Any(); + $resource = new UserResource($user); + $responseData->setValue(json_encode([ + 'data' => $resource + ])); + + $response->setSuccess(true); + $response->setStatusCode(200); + $response->setData($responseData); + + + return $response; + } + +} diff --git a/app/Grpc/GrpcRoute.php b/app/Grpc/GrpcRoute.php new file mode 100644 index 0000000..55d6f70 --- /dev/null +++ b/app/Grpc/GrpcRoute.php @@ -0,0 +1,11 @@ + $controller, + 'action' => $action + ]; + } + + public static function resolve(string $service, string $method): ?array + { + return self::$routes[$service][$method] ?? null; + } + + public static function getAllRoutes(): array + { + return self::$routes; + } + + public static function getAllServices(): array + { + return array_keys(self::$routes); + } +} diff --git a/app/Grpc/GrpcServiceRouter.php b/app/Grpc/GrpcServiceRouter.php new file mode 100644 index 0000000..3de8200 --- /dev/null +++ b/app/Grpc/GrpcServiceRouter.php @@ -0,0 +1,19 @@ +serviceName = $serviceName; + } + + public function method(string $methodName, string $controller, string $action): self + { + GrpcRouteRegistry::register($this->serviceName, $methodName, $controller, $action); + return $this; + } +} diff --git a/app/Grpc/Services/BaseServer.php b/app/Grpc/Services/BaseServer.php index 6959aca..1332c2c 100644 --- a/app/Grpc/Services/BaseServer.php +++ b/app/Grpc/Services/BaseServer.php @@ -89,31 +89,7 @@ public function HandleBytesRequest(BytesRequest $in): BytesResponse // } // } - /** - * Create error response - */ - public function createErrorResponse(FlexibleResponse $response, int $statusCode, $code, string $message, ?array $errorMsg = null): FlexibleResponse - { - UserServer::getContext()->setStatus([ - 'code' => $code, - 'details' => $message - ]); - $error = new ErrorInfo(); - $error->setCode($code); - $error->setMessage($message); - if (!is_null($errorMsg)) { - $any = new Any(); - $any->setValue(json_encode($errorMsg)); - $response->setData($any); - } - - $response->setSuccess(false); - $response->setStatusCode($statusCode); - $response->setError($error); - - return $response; - } /** * Create bytes error response @@ -162,19 +138,7 @@ private function processUserRequest(string $method, array $data): array } } - /** - * @param array $data - * @param FlexibleResponse $response - */ - protected function createResponse(array $data, FlexibleResponse $response, $code = 200): FlexibleResponse - { - $responseData = new Any(); - $responseData->setValue(json_encode($data)); - $response->setData($responseData); - $response->setSuccess(true); - $response->setStatusCode($code); - return $response; - } + /** * @param FlexibleRequest $in diff --git a/app/Grpc/Services/CartServer.php b/app/Grpc/Services/CartServer.php index 7ad1bd6..ec54c7c 100644 --- a/app/Grpc/Services/CartServer.php +++ b/app/Grpc/Services/CartServer.php @@ -2,6 +2,7 @@ namespace App\Grpc\Services; +use App\Grpc\Controllers\BaseGrpcService; use App\Grpc\FlexibleRequest; use App\Grpc\FlexibleResponse; use App\Services\CartCacheService; @@ -62,7 +63,7 @@ private function addToCart(FlexibleRequest $in, FlexibleResponse $response): Fle ); return $response; } - request()->headers->set('Authorization', data_get(UserServer::getContext()->clientMetadata(), 'authorization') ?? ''); + request()->headers->set('Authorization', data_get(BaseGrpcService::getContext()->clientMetadata(), 'authorization') ?? ''); $res = $this->shoppingCartGatewayService->add( auth()->id(), data_get($data, 'item_id'), diff --git a/app/Grpc/Services/GrpcService.php b/app/Grpc/Services/GrpcService.php new file mode 100644 index 0000000..58c47f9 --- /dev/null +++ b/app/Grpc/Services/GrpcService.php @@ -0,0 +1,55 @@ +setService($service); + $grpcRequest->setMethod($method); + $grpcRequest->setRequestId(uniqid()); + + // Pack request data as Any + $payload = new Any(); + $payload->setValue(json_encode($request->all())); + $grpcRequest->setPayload($payload); + + + // Call gRPC service + $grpcResponse = $this->gatewayService->HandleClientRequest($grpcRequest); + + // Convert back to HTTP response + if ($grpcResponse->getSuccess()) { + $data = json_decode($grpcResponse->getData()->getValue()) ?? $grpcResponse->getData()->getValue(); + return response()->json($data, $grpcResponse->getStatusCode()); + } else { + $error = $grpcResponse->getError()->getMessage(); + $data = $grpcResponse->getData() ? json_decode($grpcResponse->getData()->getValue()) : null; + if (data_get($data, 'message')) + $res['message'] = data_get($data, 'message'); + + $res['error'] = json_decode($error) ?? $error; + return response()->json($res, $grpcResponse->getStatusCode()); + } + } + + public function dispatchGrpcRequest(FlexibleRequest $request): FlexibleResponse + { + return $this->gatewayService->HandleClientRequest($request); + } +} diff --git a/app/Grpc/Services/UserGrpcService.php b/app/Grpc/Services/UserGrpcService.php new file mode 100644 index 0000000..9de9ef7 --- /dev/null +++ b/app/Grpc/Services/UserGrpcService.php @@ -0,0 +1,220 @@ +gw_service = config('services.microservices.gw_service_grpc'); + } + + /** + * Handle flexible protobuf requests + */ + public function HandleClientRequest(FlexibleRequest $in): FlexibleResponse + { + $response = new FlexibleResponse(); + $response->setRequestId($in->getRequestId()); + $response->setTimestamp($this->getCurrentTimestamp()); + + // try { + // to Get a gRPC client for the target service + $grpcClient = $this->getGrpcClient($in->getService()); + if (!$grpcClient) { + return $this->createErrorResponse($response, 404, 'SERVICE_NOT_FOUND', 'Service not found: ' . $in->getService()); + } + + // Forward the exact same FlexibleRequest to downstream service + // The downstream service implements the same flexible proto + $metadata = []; + if ($bearerToken = request()->bearerToken()) + $metadata['authorization'] = ['Bearer ' . $bearerToken]; + list($downstreamResponse, $status) = $grpcClient->HandleRequest($in, $metadata)->wait(); + if ($status->code === STATUS_OK) { + // Forward the response as-is + $response->setSuccess($downstreamResponse->getSuccess()); + $response->setStatusCode($downstreamResponse->getStatusCode()); + $response->setData($downstreamResponse->getData()); + + // Forward headers + foreach ($downstreamResponse->getHeaders() as $key => $value) { + $response->getHeaders()[$key] = $value; + } + + } else { + // dd($downstreamResponse->getError()); + if (is_null($downstreamResponse)) + return $this->createErrorResponse( + $response, + 500, + 'GRPC_ERROR', + 'Downstream service returned null response' + ); + return $this->createErrorResponse( + $response, + $downstreamResponse->getStatusCode(), + 'GRPC_ERROR', + $downstreamResponse->getError() ? $downstreamResponse->getError()->getMessage() : 'Unknown error', + data: $downstreamResponse->getData() + ); + } + + // } catch (Exception $e) { + + // Log::error('Gateway gRPC request failed', [ + // 'service' => $in->getService(), + // 'method' => $in->getMethod(), + // 'error' => $e->getMessage() + // ]); + + // return $this->createErrorResponse($response, 500, 'INTERNAL_ERROR', $e->getMessage()); + // } + + return $response; + } + + public function HandleRequest(FlexibleRequest $request, ServerContext $context): FlexibleResponse + { + try { + $this->authMiddleware->authenticateGrpcRequest($context->clientMetadata()); + BaseGrpcService::setContext($context); + // Extract service and method from the request + $serviceName = $request->getService(); + $methodName = $request->getMethod(); + + // Resolve the route + $route = GrpcRouteRegistry::resolve($serviceName, $methodName); + + if (!$route) { + throw new Exception("Route not found: {$serviceName}::{$methodName}"); + } + $response = new FlexibleResponse(); + $response->setRequestId($request->getRequestId()); + $response->setTimestamp($this->getCurrentTimestamp()); + + // Instantiate controller + $controllerClass = "App\\Grpc\\Controllers\\{$route['controller']}"; + $controller = app($controllerClass); + + // Call the action + return $controller->{$route['action']}($request, $response); + + } catch (Exception $e) { + Log::error("Failed to handle gRPC request", [$e->getMessage()]); + return new FlexibleResponse([ + 'status' => 'error', + 'code' => 500, + 'data' => json_encode(['message' => $e->getMessage()]) + ]); + } + } + + /** + * Get gRPC client for service + */ + private function getGrpcClient(string $service): ?GatewayServiceClient + { + try { + // Simplified options to avoid compatibility issues + $options = [ + 'credentials' => ChannelCredentials::createInsecure(), + 'timeout' => 30000000, // 30 seconds in microseconds + ]; + + $res = new GatewayServiceClient( + $this->gw_service, + $options + ); + + Log::info("Created gRPC client for service: {$service} at {$this->gw_service}"); + return $res; + } catch (Exception $e) { + Log::error("Failed to create gRPC client for service: {$service}", [ + 'address' => $this->gw_service, + 'error' => $e->getMessage() + ]); + return null; + } + } + + /** + * Create error response for FlexibleResponse + */ + private function createErrorResponse(FlexibleResponse $response, int $statusCode, string $code, string $message, ?Any $data = null): FlexibleResponse + { + $error = new ErrorInfo(); + $error->setCode($code); + $error->setMessage($message); + + $response->setData($data); + $response->setSuccess(false); + $response->setStatusCode($statusCode); + $response->setError($error); + + return $response; + } + + /** + * Create error response for BytesResponse + */ + private function createBytesErrorResponse(BytesResponse $response, int $statusCode, string $code, string $message): BytesResponse + { + $error = new ErrorInfo(); + $error->setCode($code); + $error->setMessage($message); + + $response->setSuccess(false); + $response->setStatusCode($statusCode); + $response->setError($error); + $response->setContentType('application/json'); + $response->setData(json_encode(['error' => $code, 'message' => $message])); + + return $response; + } + + /** + * Get current timestamp + */ + private function getCurrentTimestamp(): Timestamp + { + $timestamp = new Timestamp(); + $timestamp->fromDateTime(new DateTime()); + return $timestamp; + } + + public function getMethodDescriptors(): array + { + return [ + '/gateway.GatewayService/HandleRequest' => new MethodDescriptor( + $this, + 'HandleRequest', + FlexibleRequest::class, + MethodDescriptor::UNARY_CALL, + ), + ]; + } + +} diff --git a/app/Grpc/Services/UserServer.php b/app/Grpc/Services/UserServer.php index dd3d930..8e4c1f1 100644 --- a/app/Grpc/Services/UserServer.php +++ b/app/Grpc/Services/UserServer.php @@ -76,8 +76,8 @@ function manageOperation(FlexibleRequest $in, FlexibleResponse $response): Flexi public function HandleRequest(FlexibleRequest $in, ServerContext $context): FlexibleResponse { - self::setContext($context); - $this->authMiddleware->authenticateGrpcRequest($context->clientMetadata()); +// self::setContext($context); +// $this->authMiddleware->authenticateGrpcRequest($context->clientMetadata()); $response = new FlexibleResponse(); $response->setRequestId($in->getRequestId()); $response->setTimestamp($this->getCurrentTimestamp()); diff --git a/app/Providers/GrpcServiceProvider.php b/app/Providers/GrpcServiceProvider.php new file mode 100644 index 0000000..521b147 --- /dev/null +++ b/app/Providers/GrpcServiceProvider.php @@ -0,0 +1,20 @@ +loadGrpcRoutes(); + } + + protected function loadGrpcRoutes(): void + { + if (file_exists(base_path('routes/grpc.php'))) { + require base_path('routes/grpc.php'); + } + } +} diff --git a/bootstrap/providers.php b/bootstrap/providers.php index cdebb55..98aace7 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -2,5 +2,6 @@ return [ App\Providers\AppServiceProvider::class, - Bschmitt\Amqp\AmqpServiceProvider::class + App\Providers\GrpcServiceProvider::class, + Bschmitt\Amqp\AmqpServiceProvider::class, ]; diff --git a/config/services.php b/config/services.php index d46b321..0e86987 100644 --- a/config/services.php +++ b/config/services.php @@ -42,6 +42,7 @@ ], 'microservices' => [ + 'gw_service_grpc' => env('GW_SERVICE_GRPC', 'api-gw:50051'), 'gw_url' => env('GW_URL'), 'product_uri' => env('PRODUCT_URI'), 'offer_uri' => env('OFFER_URI'), diff --git a/routes/grpc.php b/routes/grpc.php new file mode 100644 index 0000000..f567186 --- /dev/null +++ b/routes/grpc.php @@ -0,0 +1,21 @@ +method('GetUser', 'UserController', 'show') + ->method('UpdateUser', 'UserController', 'update') + ->method('DeleteUser', 'UserController', 'destroy') + ->method('ListUsers', 'UserController', 'index'); + +GrpcRoute::service('Auth') + ->method('Login', 'AuthController', 'login') + ->method('SignUp', 'AuthController', 'signup') + ->method('logout', 'AuthController', 'logout') + ->method('validateToken', 'AuthController', 'validateToken'); + +// Product Service Routes +GrpcRoute::service('Cart') + ->method('getCart', 'CartController', 'index') + ->method('addToCart', 'CartController', 'store'); From 6782d43bbe401e0facd44fa242f42333f488e10f Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Sat, 14 Jun 2025 03:33:24 +0300 Subject: [PATCH 03/12] Refactor gRPC implementation: restructure routes for consistency, streamline request handling, and introduce `CartController`. Update Docker environment variables and image version for compatibility. Remove unused gRPC config. --- app/Grpc/Controllers/AuthController.php | 99 ++++++- app/Grpc/Controllers/BaseGrpcService.php | 15 +- app/Grpc/Controllers/CartController.php | 169 ++++++++++++ app/Grpc/Middleware/GrpcAuthMiddleware.php | 37 ++- app/Grpc/Services/CartServer.php | 296 ++++++++++----------- config/grpc.php | 16 -- docker-compose.yml | 6 +- routes/grpc.php | 4 +- 8 files changed, 456 insertions(+), 186 deletions(-) delete mode 100644 config/grpc.php diff --git a/app/Grpc/Controllers/AuthController.php b/app/Grpc/Controllers/AuthController.php index d8cfb66..d1078f1 100644 --- a/app/Grpc/Controllers/AuthController.php +++ b/app/Grpc/Controllers/AuthController.php @@ -2,9 +2,12 @@ namespace App\Grpc\Controllers; +use App\Grpc\ErrorInfo; use App\Grpc\FlexibleRequest; use App\Grpc\FlexibleResponse; +use App\Grpc\Middleware\GrpcAuthMiddleware; use App\Http\Requests\Users\UserCreateRequest; +use App\Http\Requests\Users\UserReadRequest; use App\Http\Resources\UserResource; use App\Services\UserService; use Exception; @@ -13,6 +16,7 @@ use Illuminate\Support\Facades\Validator; use Symfony\Component\HttpFoundation\Response; use const Grpc\STATUS_INVALID_ARGUMENT; +use const Grpc\STATUS_UNAUTHENTICATED; class AuthController extends BaseGrpcService { @@ -25,11 +29,10 @@ public function __construct( /** * @throws Exception */ - private function createUser(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse + public function createUser(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse { // Extract data from Any payload - $jsonData = $request->getPayload()->getValue(); - $userData = json_decode($jsonData, true); + $userData = $this->getRequestData($request); $rules = new UserCreateRequest()->rules(); $validator = Validator::make($userData, $rules); if ($validator->fails()) { @@ -65,4 +68,94 @@ private function createUser(FlexibleRequest $request, FlexibleResponse $response return $response; } + public function login(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + { + $data = $this->getRequestData($in); + $rules = new UserReadRequest()->rules(); + $validator = Validator::make($data, $rules); + if ($validator->fails()) { + Log::error('User login validation error', [ + 'errors' => $validator->errors() + ]); + self::getContext()->setStatus([ + 'code' => STATUS_INVALID_ARGUMENT, + 'details' => $validator->errors() + ]); + $response->setStatusCode(Response::HTTP_BAD_REQUEST); + $response->setError(new ErrorInfo([ + 'message' => $validator->errors() + ])); + $response->setSuccess(false); + return $response; +// throw new Exception($validator->errors(), STATUS_INVALID_ARGUMENT); + } + + $user = $this->userService->login($data); + + if (!$user) { + self::getContext()->setStatus([ + 'code' => STATUS_UNAUTHENTICATED, + 'details' => 'Invalid credentials' + ]); + $response->setError(new ErrorInfo([ + 'message' => 'Invalid credentials' + ])); + $response->setStatusCode(Response::HTTP_UNAUTHORIZED); + $response->setSuccess(false); + return $response; +// throw new Exception ('Invalid credentials', STATUS_UNAUTHENTICATED); + } + + // Pack user data into Any + $userResource = new UserResource($user); + $anyData = new Any(); + $anyData->setValue(json_encode([ + 'message' => 'Login successful', + 'data' => $userResource + ])); + + $response->setSuccess(true); + $response->setStatusCode(200); + $response->setData($anyData); + + return $response; + } + + + public function validateToken(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse + { + try { + $user = auth()->user(); + $user->withAccessToken(app(GrpcAuthMiddleware::class)->getToken(BaseGrpcService::getContext()->clientMetadata())); + + $user = $this->userService->validateToken($user); + if (is_null($user['data'])) { + return $this->createErrorResponse( + $response, + Response::HTTP_UNAUTHORIZED, + STATUS_INVALID_ARGUMENT, + $user['message'], + ); + } + return $this->createResponse([ + 'message' => $user['message'], + 'data' => $user['data'] + ], + $response + ); + } catch (Exception $e) { + Log::error('Token validation error', [ + 'error' => $e->getMessage(), + 'trace' => $e->getTrace() + ]); + + return $this->createErrorResponse( + $response, + Response::HTTP_UNAUTHORIZED, + STATUS_INVALID_ARGUMENT, + 'Token validation failed: ' . $e->getMessage() + ); + } + } + } diff --git a/app/Grpc/Controllers/BaseGrpcService.php b/app/Grpc/Controllers/BaseGrpcService.php index 7377274..79661fe 100644 --- a/app/Grpc/Controllers/BaseGrpcService.php +++ b/app/Grpc/Controllers/BaseGrpcService.php @@ -3,11 +3,8 @@ namespace App\Grpc\Controllers; use App\Grpc\ErrorInfo; +use App\Grpc\FlexibleRequest; use App\Grpc\FlexibleResponse; -use App\Grpc\Middleware\GrpcAuthMiddleware; -use App\Grpc\Services\BaseServer; -use App\Grpc\Services\UserServer; -use App\Services\UserService; use Google\Protobuf\Any; use Grpc\ServerContext; @@ -25,6 +22,16 @@ public static function setContext(ServerContext $context): void self::$context = $context; } + /** + * @param FlexibleRequest $request + * @return mixed + */ + protected function getRequestData(FlexibleRequest $request): mixed + { + $jsonData = $request->getPayload()->getValue(); + return json_decode($jsonData, true); + } + /** * @param array $data diff --git a/app/Grpc/Controllers/CartController.php b/app/Grpc/Controllers/CartController.php index e69de29..137f5a0 100644 --- a/app/Grpc/Controllers/CartController.php +++ b/app/Grpc/Controllers/CartController.php @@ -0,0 +1,169 @@ +getRequestData($in); + $rules = [ + 'item_id' => 'required|integer', + 'item_type' => 'required|string|in:products,offers', + 'quantity' => 'nullable|integer|min:1', + ]; + $validator = Validator::make($data, $rules); + if ($validator->fails()) { + Log::error('Add to cart validation error', [ + 'errors' => $validator->errors() + ]); + $this->createErrorResponse( + $response, + Response::HTTP_BAD_REQUEST, + STATUS_INVALID_ARGUMENT, + $validator->errors()->first() + ); + return $response; + } + request()->headers->set('Authorization', data_get(BaseGrpcService::getContext()->clientMetadata(), 'authorization') ?? ''); + $res = $this->shoppingCartGatewayService->add( + auth()->id(), + data_get($data, 'item_id'), + data_get($data, 'item_type'), + (int)data_get($data, 'quantity', 1) + ); + if (!$res) { + Log::error('Add to cart failed', [ + 'user_id' => auth()->id(), + 'item_id' => data_get($data, 'item_id'), + 'item_type' => data_get($data, 'item_type'), + ]); + $this->createErrorResponse( + $response, + Response::HTTP_NOT_FOUND, + STATUS_INVALID_ARGUMENT, + 'Item not found or could not be added to cart' + ); + return $response; + } + \Log::info('Item added to cart', [ + 'user_id' => auth()->id(), + 'item_id' => data_get($data, 'item_id'), + 'item_type' => data_get($data, 'item_type'), + 'quantity' => data_get($data, 'quantity', 1), + ]); + $message = ['message' => 'Item added to cart successfully']; + return $this->createResponse($message, $response); + } + + /** + * @throws BindingResolutionException + * @throws ConnectionException + */ + private function getCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + { + $cart = $this->shoppingCartGatewayService->getCart(auth()->id()); + if (!$cart) { + Log::error('Get cart failed', [ + 'user_id' => auth()->id(), + ]); + return $this->createErrorResponse( + $response, + Response::HTTP_NOT_FOUND, + STATUS_INVALID_ARGUMENT, + 'Cart not found' + ); + } + + return $this->createResponse([ + 'message' => 'Cart retrieved successfully', + 'data' => $cart + ], + $response + ); + } + + private function removeFromCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + { + $data = $this->getRequestData($in); + $rules = [ + 'item_id' => 'required|integer', + 'item_type' => 'required|string|in:products,offers', + ]; + $validator = Validator::make($data, $rules); + if ($validator->fails()) { + Log::error('Remove from cart validation error', [ + 'errors' => $validator->errors() + ]); + return $this->createErrorResponse( + $response, + Response::HTTP_BAD_REQUEST, + STATUS_INVALID_ARGUMENT, + $validator->errors()->first() + ); + } + try { + $this->cartCacheService->remove( + auth()->id(), + data_get($data, 'item_type'), + data_get($data, 'item_id'), + ); + return $this->createResponse(['message' => 'Item removed from cart successfully'], $response); + } catch (\Exception $e) { + Log::error('Remove from cart cache error', [ + 'user_id' => auth()->id(), + 'item_id' => data_get($data, 'item_id'), + 'item_type' => data_get($data, 'item_type'), + 'error' => $e->getMessage() + ]); + return $this->createErrorResponse( + $response, + Response::HTTP_NOT_FOUND, + STATUS_INVALID_ARGUMENT, + 'Item not found in cart' + ); + } + } + + private function clearCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + { + try { + $this->cartCacheService->clear(auth()->id()); + return $this->createResponse(['message' => 'Cart cleared successfully'], $response); + } catch (\Exception $e) { + Log::error('Clear cart cache error', [ + 'user_id' => auth()->id(), + 'error' => $e->getMessage() + ]); + return $this->createErrorResponse( + $response, + Response::HTTP_INTERNAL_SERVER_ERROR, + STATUS_INVALID_ARGUMENT, + 'Failed to clear cart' + ); + } + } +} diff --git a/app/Grpc/Middleware/GrpcAuthMiddleware.php b/app/Grpc/Middleware/GrpcAuthMiddleware.php index 036d756..8c6b120 100644 --- a/app/Grpc/Middleware/GrpcAuthMiddleware.php +++ b/app/Grpc/Middleware/GrpcAuthMiddleware.php @@ -4,19 +4,22 @@ use App\Models\User; use Auth; +use Exception; use Laravel\Passport\Token; +use LaravelIdea\Helper\Laravel\Passport\_IH_Token_C; +use Log; class GrpcAuthMiddleware { /** - * @throws \Exception + * @throws Exception */ private function getTokenIdFromJWT($jwt) { $parts = explode('.', $jwt); if (count($parts) !== 3) { - throw new \Exception('Invalid JWT format'); + throw new Exception('Invalid JWT format'); } $payload = json_decode(base64_decode($parts[1]), true); @@ -43,7 +46,7 @@ public function getUserByAccessToken($tokenString) return $token->user; - } catch (\Exception $e) { + } catch (Exception $e) { return null; } } @@ -68,8 +71,8 @@ public function authenticateGrpcRequest($metadata): ?User return $user; - } catch (\Exception $e) { - \Log::error('gRPC Authentication error: ' . $e->getMessage()); + } catch (Exception $e) { + Log::error('gRPC Authentication error: ' . $e->getMessage()); return null; } } @@ -89,8 +92,8 @@ public function validateToken(string $token): array 'message' => 'Token is valid', 'data' => $user, ]; - } catch (\Exception $e) { - \Log::error('Token validation error: ' . $e->getMessage()); + } catch (Exception $e) { + Log::error('Token validation error: ' . $e->getMessage()); return [ 'message' => 'Token validation failed', 'data' => null, @@ -116,15 +119,25 @@ public function extractBearerToken($metadata): ?string } /** - * @throws \Exception + * @throws Exception */ public function revokeGrpcToken($clientMetadata): void { - $tokenString = $this->extractBearerToken($clientMetadata); - $tokenId = $this->getTokenIdFromJWT($tokenString); - $token = Token::find($tokenId); + $token = $this->getToken($clientMetadata); if ($token->revoked) - throw new \Exception('Token not found'); + throw new Exception('Token not found'); $token->revoke(); } + + /** + * @param $clientMetadata + * @return Token|Token[]|_IH_Token_C|null + * @throws Exception + */ + public function getToken($clientMetadata): _IH_Token_C|Token|array|null + { + $tokenString = $this->extractBearerToken($clientMetadata); + $tokenId = $this->getTokenIdFromJWT($tokenString); + return Token::find($tokenId); + } } diff --git a/app/Grpc/Services/CartServer.php b/app/Grpc/Services/CartServer.php index ec54c7c..f104ecd 100644 --- a/app/Grpc/Services/CartServer.php +++ b/app/Grpc/Services/CartServer.php @@ -37,153 +37,153 @@ function manageOperation(FlexibleRequest $in, FlexibleResponse $response): Flexi 'clearCart' => $this->clearCart($in, $response), }; } - - /** - * @throws \Exception - */ - private function addToCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse - { - $jsonData = $in->getPayload()->getValue(); - $data = json_decode($jsonData, true); - $rules = [ - 'item_id' => 'required|integer', - 'item_type' => 'required|string|in:products,offers', - 'quantity' => 'nullable|integer|min:1', - ]; - $validator = Validator::make($data, $rules); - if ($validator->fails()) { - Log::error('Add to cart validation error', [ - 'errors' => $validator->errors() - ]); - $this->createErrorResponse( - $response, - Response::HTTP_BAD_REQUEST, - STATUS_INVALID_ARGUMENT, - $validator->errors()->first() - ); - return $response; - } - request()->headers->set('Authorization', data_get(BaseGrpcService::getContext()->clientMetadata(), 'authorization') ?? ''); - $res = $this->shoppingCartGatewayService->add( - auth()->id(), - data_get($data, 'item_id'), - data_get($data, 'item_type'), - (int)data_get($data, 'quantity', 1) - ); - if (!$res) { - Log::error('Add to cart failed', [ - 'user_id' => auth()->id(), - 'item_id' => data_get($data, 'item_id'), - 'item_type' => data_get($data, 'item_type'), - ]); - $this->createErrorResponse( - $response, - Response::HTTP_NOT_FOUND, - STATUS_INVALID_ARGUMENT, - 'Item not found or could not be added to cart' - ); - return $response; - } - \Log::info('Item added to cart', [ - 'user_id' => auth()->id(), - 'item_id' => data_get($data, 'item_id'), - 'item_type' => data_get($data, 'item_type'), - 'quantity' => data_get($data, 'quantity', 1), - ]); - $message = ['message' => 'Item added to cart successfully']; - return $this->createResponse($message, $response); - } - - /** - * @throws BindingResolutionException - * @throws ConnectionException - */ - private function getCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse - { - $jsonData = $in->getPayload()->getValue(); - $data = json_decode($jsonData, true); - - $cart = $this->shoppingCartGatewayService->getCart(auth()->id()); - if (!$cart) { - Log::error('Get cart failed', [ - 'user_id' => auth()->id(), - ]); - return $this->createErrorResponse( - $response, - Response::HTTP_NOT_FOUND, - STATUS_INVALID_ARGUMENT, - 'Cart not found' - ); - } - - return $this->createResponse([ - 'message' => 'Cart retrieved successfully', - 'data' => $cart - ], - $response - ); - } - - private function removeFromCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse - { - $jsonData = $in->getPayload()->getValue(); - $data = json_decode($jsonData, true); - $rules = [ - 'item_id' => 'required|integer', - 'item_type' => 'required|string|in:products,offers', - ]; - $validator = Validator::make($data, $rules); - if ($validator->fails()) { - Log::error('Remove from cart validation error', [ - 'errors' => $validator->errors() - ]); - return $this->createErrorResponse( - $response, - Response::HTTP_BAD_REQUEST, - STATUS_INVALID_ARGUMENT, - $validator->errors()->first() - ); - } - try { - $this->cartCacheService->remove( - auth()->id(), - data_get($data, 'item_type'), - data_get($data, 'item_id'), - ); - return $this->createResponse(['message' => 'Item removed from cart successfully'], $response); - } catch (\Exception $e) { - Log::error('Remove from cart cache error', [ - 'user_id' => auth()->id(), - 'item_id' => data_get($data, 'item_id'), - 'item_type' => data_get($data, 'item_type'), - 'error' => $e->getMessage() - ]); - return $this->createErrorResponse( - $response, - Response::HTTP_NOT_FOUND, - STATUS_INVALID_ARGUMENT, - 'Item not found in cart' - ); - } - } - - private function clearCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse - { - try { - $this->cartCacheService->clear(auth()->id()); - return $this->createResponse(['message' => 'Cart cleared successfully'], $response); - } catch (\Exception $e) { - Log::error('Clear cart cache error', [ - 'user_id' => auth()->id(), - 'error' => $e->getMessage() - ]); - return $this->createErrorResponse( - $response, - Response::HTTP_INTERNAL_SERVER_ERROR, - STATUS_INVALID_ARGUMENT, - 'Failed to clear cart' - ); - } - } +// +// /** +// * @throws \Exception +// */ +// private function addToCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse +// { +// $jsonData = $in->getPayload()->getValue(); +// $data = json_decode($jsonData, true); +// $rules = [ +// 'item_id' => 'required|integer', +// 'item_type' => 'required|string|in:products,offers', +// 'quantity' => 'nullable|integer|min:1', +// ]; +// $validator = Validator::make($data, $rules); +// if ($validator->fails()) { +// Log::error('Add to cart validation error', [ +// 'errors' => $validator->errors() +// ]); +// $this->createErrorResponse( +// $response, +// Response::HTTP_BAD_REQUEST, +// STATUS_INVALID_ARGUMENT, +// $validator->errors()->first() +// ); +// return $response; +// } +// request()->headers->set('Authorization', data_get(BaseGrpcService::getContext()->clientMetadata(), 'authorization') ?? ''); +// $res = $this->shoppingCartGatewayService->add( +// auth()->id(), +// data_get($data, 'item_id'), +// data_get($data, 'item_type'), +// (int)data_get($data, 'quantity', 1) +// ); +// if (!$res) { +// Log::error('Add to cart failed', [ +// 'user_id' => auth()->id(), +// 'item_id' => data_get($data, 'item_id'), +// 'item_type' => data_get($data, 'item_type'), +// ]); +// $this->createErrorResponse( +// $response, +// Response::HTTP_NOT_FOUND, +// STATUS_INVALID_ARGUMENT, +// 'Item not found or could not be added to cart' +// ); +// return $response; +// } +// \Log::info('Item added to cart', [ +// 'user_id' => auth()->id(), +// 'item_id' => data_get($data, 'item_id'), +// 'item_type' => data_get($data, 'item_type'), +// 'quantity' => data_get($data, 'quantity', 1), +// ]); +// $message = ['message' => 'Item added to cart successfully']; +// return $this->createResponse($message, $response); +// } +// +// /** +// * @throws BindingResolutionException +// * @throws ConnectionException +// */ +// private function getCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse +// { +// $jsonData = $in->getPayload()->getValue(); +// $data = json_decode($jsonData, true); +// +// $cart = $this->shoppingCartGatewayService->getCart(auth()->id()); +// if (!$cart) { +// Log::error('Get cart failed', [ +// 'user_id' => auth()->id(), +// ]); +// return $this->createErrorResponse( +// $response, +// Response::HTTP_NOT_FOUND, +// STATUS_INVALID_ARGUMENT, +// 'Cart not found' +// ); +// } +// +// return $this->createResponse([ +// 'message' => 'Cart retrieved successfully', +// 'data' => $cart +// ], +// $response +// ); +// } +// +// private function removeFromCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse +// { +// $jsonData = $in->getPayload()->getValue(); +// $data = json_decode($jsonData, true); +// $rules = [ +// 'item_id' => 'required|integer', +// 'item_type' => 'required|string|in:products,offers', +// ]; +// $validator = Validator::make($data, $rules); +// if ($validator->fails()) { +// Log::error('Remove from cart validation error', [ +// 'errors' => $validator->errors() +// ]); +// return $this->createErrorResponse( +// $response, +// Response::HTTP_BAD_REQUEST, +// STATUS_INVALID_ARGUMENT, +// $validator->errors()->first() +// ); +// } +// try { +// $this->cartCacheService->remove( +// auth()->id(), +// data_get($data, 'item_type'), +// data_get($data, 'item_id'), +// ); +// return $this->createResponse(['message' => 'Item removed from cart successfully'], $response); +// } catch (\Exception $e) { +// Log::error('Remove from cart cache error', [ +// 'user_id' => auth()->id(), +// 'item_id' => data_get($data, 'item_id'), +// 'item_type' => data_get($data, 'item_type'), +// 'error' => $e->getMessage() +// ]); +// return $this->createErrorResponse( +// $response, +// Response::HTTP_NOT_FOUND, +// STATUS_INVALID_ARGUMENT, +// 'Item not found in cart' +// ); +// } +// } +// +// private function clearCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse +// { +// try { +// $this->cartCacheService->clear(auth()->id()); +// return $this->createResponse(['message' => 'Cart cleared successfully'], $response); +// } catch (\Exception $e) { +// Log::error('Clear cart cache error', [ +// 'user_id' => auth()->id(), +// 'error' => $e->getMessage() +// ]); +// return $this->createErrorResponse( +// $response, +// Response::HTTP_INTERNAL_SERVER_ERROR, +// STATUS_INVALID_ARGUMENT, +// 'Failed to clear cart' +// ); +// } +// } } diff --git a/config/grpc.php b/config/grpc.php deleted file mode 100644 index 409c1d8..0000000 --- a/config/grpc.php +++ /dev/null @@ -1,16 +0,0 @@ - [ - 'user' => [ - 'host' => env('USER_SERVICE_GRPC_HOST', 'localhost:50051'), - ], - // Add other services here as you create them - ], - - 'server' => [ - 'port' => env('GRPC_SERVER_PORT', 50051), - 'host' => env('GRPC_SERVER_HOST', '0.0.0.0'), - ], -]; diff --git a/docker-compose.yml b/docker-compose.yml index 7e2fd18..1102ec2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ services: user: build: context: . - image: ommrgazar315/user-service:2.0_grpc + image: ommrgazar315/user-service:2.5_grpc restart: unless-stopped working_dir: /var/www volumes: @@ -30,6 +30,10 @@ services: - AMQP_VHOST=/ - GRPC_SERVER_PORT=9501 - GRPC_SERVER_HOST=0.0.0.0 + - GW_SERVICE_GRPC=api-gw:50051 + - GW_URL=http://api-gw/ + - PRODUCT_URI=api/products/ + - OFFER_URI=api/offers/ # command: > # sh -c "php-fpm" user_db: diff --git a/routes/grpc.php b/routes/grpc.php index f567186..dc42c7a 100644 --- a/routes/grpc.php +++ b/routes/grpc.php @@ -12,8 +12,8 @@ GrpcRoute::service('Auth') ->method('Login', 'AuthController', 'login') ->method('SignUp', 'AuthController', 'signup') - ->method('logout', 'AuthController', 'logout') - ->method('validateToken', 'AuthController', 'validateToken'); + ->method('Logout', 'AuthController', 'logout') + ->method('ValidateToken', 'AuthController', 'validateToken'); // Product Service Routes GrpcRoute::service('Cart') From cf74f6fec3c7be16fa7889d8cc779bb9338ab543 Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Sat, 14 Jun 2025 03:46:08 +0300 Subject: [PATCH 04/12] Update gRPC routes and `CartController`: add new cart operations, adjust method visibility, and refine service definitions. --- app/Grpc/Controllers/CartController.php | 8 ++++---- routes/grpc.php | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Grpc/Controllers/CartController.php b/app/Grpc/Controllers/CartController.php index 137f5a0..fbb745f 100644 --- a/app/Grpc/Controllers/CartController.php +++ b/app/Grpc/Controllers/CartController.php @@ -27,7 +27,7 @@ public function __construct( /** * @throws \Exception */ - private function addToCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + public function addToCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse { $data = $this->getRequestData($in); $rules = [ @@ -83,7 +83,7 @@ private function addToCart(FlexibleRequest $in, FlexibleResponse $response): Fle * @throws BindingResolutionException * @throws ConnectionException */ - private function getCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + public function getCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse { $cart = $this->shoppingCartGatewayService->getCart(auth()->id()); if (!$cart) { @@ -106,7 +106,7 @@ private function getCart(FlexibleRequest $in, FlexibleResponse $response): Flexi ); } - private function removeFromCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + public function removeFromCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse { $data = $this->getRequestData($in); $rules = [ @@ -148,7 +148,7 @@ private function removeFromCart(FlexibleRequest $in, FlexibleResponse $response) } } - private function clearCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + public function clearCart(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse { try { $this->cartCacheService->clear(auth()->id()); diff --git a/routes/grpc.php b/routes/grpc.php index dc42c7a..4201577 100644 --- a/routes/grpc.php +++ b/routes/grpc.php @@ -15,7 +15,9 @@ ->method('Logout', 'AuthController', 'logout') ->method('ValidateToken', 'AuthController', 'validateToken'); -// Product Service Routes +// Cart Service Routes GrpcRoute::service('Cart') - ->method('getCart', 'CartController', 'index') - ->method('addToCart', 'CartController', 'store'); + ->method('GetCart', 'CartController', 'getCart') + ->method('AddToCart', 'CartController', 'addToCart') + ->method('RemoveFromCart', 'CartController', 'removeFromCart') + ->method('ClearCart', 'CartController', 'clearCart'); From 0b22a1f2e783ac0c34cd5c0a904a36a6d3c0a39f Mon Sep 17 00:00:00 2001 From: Omar Ahmed El-Gazzar <92094226+OmmrGAZAR315@users.noreply.github.com> Date: Sat, 14 Jun 2025 03:49:24 +0300 Subject: [PATCH 05/12] Update app/Grpc/Services/BaseServer.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- app/Grpc/Services/BaseServer.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Grpc/Services/BaseServer.php b/app/Grpc/Services/BaseServer.php index 1332c2c..10c3ec0 100644 --- a/app/Grpc/Services/BaseServer.php +++ b/app/Grpc/Services/BaseServer.php @@ -79,15 +79,15 @@ public function HandleBytesRequest(BytesRequest $in): BytesResponse return $response; } -// /** -// * Handle streaming (not implemented for this example) -// */ -// public function HandleStreamRequest(Iterator $in, ServerContext $context): Iterator -// { -// foreach ($in as $request) { -// yield $this->HandleRequest($request, $context); -// } -// } + /** + * Handle streaming (not implemented for this example) + * + * @todo Implement HandleStreamRequest functionality for bidirectional streaming. + */ + public function HandleStreamRequest(Iterator $in, ServerContext $context): Iterator + { + throw new Exception('HandleStreamRequest is not implemented yet.'); + } From f64ea578b6dabc36f4fe09dc92f29f2f1b9b2228 Mon Sep 17 00:00:00 2001 From: Omar Ahmed El-Gazzar <92094226+OmmrGAZAR315@users.noreply.github.com> Date: Sat, 14 Jun 2025 03:49:41 +0300 Subject: [PATCH 06/12] Update app/Grpc/Middleware/GrpcAuthMiddleware.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- app/Grpc/Middleware/GrpcAuthMiddleware.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Grpc/Middleware/GrpcAuthMiddleware.php b/app/Grpc/Middleware/GrpcAuthMiddleware.php index 8c6b120..ba43126 100644 --- a/app/Grpc/Middleware/GrpcAuthMiddleware.php +++ b/app/Grpc/Middleware/GrpcAuthMiddleware.php @@ -6,7 +6,6 @@ use Auth; use Exception; use Laravel\Passport\Token; -use LaravelIdea\Helper\Laravel\Passport\_IH_Token_C; use Log; class GrpcAuthMiddleware From f7bfc4ca1f65cf50633c024adac1d9e8925f0642 Mon Sep 17 00:00:00 2001 From: Omar Ahmed El-Gazzar <92094226+OmmrGAZAR315@users.noreply.github.com> Date: Sat, 14 Jun 2025 03:50:27 +0300 Subject: [PATCH 07/12] Update app/Grpc/Controllers/CartController.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- app/Grpc/Controllers/CartController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Grpc/Controllers/CartController.php b/app/Grpc/Controllers/CartController.php index fbb745f..5534e9a 100644 --- a/app/Grpc/Controllers/CartController.php +++ b/app/Grpc/Controllers/CartController.php @@ -18,7 +18,7 @@ class CartController extends BaseGrpcService { public function __construct( protected readonly UserService $userService, - private readonly shoppingCartGatewayService $shoppingCartGatewayService, + private readonly ShoppingCartGatewayService $shoppingCartGatewayService, protected CartCacheService $cartCacheService ) { From f27ffb5ee06034354a0ef0f1f2cae215766c641e Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Sat, 14 Jun 2025 04:02:06 +0300 Subject: [PATCH 08/12] Refactor gRPC `UserService` routes and implementation: remove unused methods, simplify request handling, and adjust service definitions for improved consistency and maintainability. --- app/Grpc/Controllers/UserController.php | 87 ++++++++++- app/Grpc/Services/UserServer.php | 189 ------------------------ routes/grpc.php | 7 +- 3 files changed, 87 insertions(+), 196 deletions(-) diff --git a/app/Grpc/Controllers/UserController.php b/app/Grpc/Controllers/UserController.php index bce9ac9..2f06186 100644 --- a/app/Grpc/Controllers/UserController.php +++ b/app/Grpc/Controllers/UserController.php @@ -9,10 +9,14 @@ use App\Services\UserService; use Exception; use Google\Protobuf\Any; +use Illuminate\Contracts\Container\BindingResolutionException; +use Illuminate\Http\Client\ConnectionException; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; use Symfony\Component\HttpFoundation\Response; use const Grpc\STATUS_INVALID_ARGUMENT; use const Grpc\STATUS_NOT_FOUND; +use const Grpc\STATUS_UNAUTHENTICATED; class UserController extends BaseGrpcService { @@ -29,9 +33,7 @@ public function __construct( */ public function getUser(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse { - $jsonData = $request->getPayload()->getValue(); - $data = json_decode($jsonData, true); - + $data = $this->getRequestData($request); $validator = Validator::make($data, [ 'id' => 'required|integer|min:1' ]); @@ -73,4 +75,83 @@ public function getUser(FlexibleRequest $request, FlexibleResponse $response): F return $response; } + /** + * List users with pagination + * @throws Exception + */ + public function listUsers(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse + { + try { + $users = $this->userService->index(); + $users = data_get($users, 'data'); + $responseData = new Any(); + $resourceCollection = UserResource::collection($users); + $responseData->setValue(json_encode([ + 'data' => $resourceCollection, +// 'pagination' => [ +// 'current_page' => $users->currentPage(), +// 'total_pages' => $users->lastPage(), +// 'total_items' => $users->total(), +// 'per_page' => $users->perPage() +// ] + ])); + + $response->setSuccess(true); + $response->setStatusCode(200); + \Log::info('User listing successful', [ + 'total_users' => count($users), + 'users' => $users + ]); + $response->setData($responseData); + } catch (Exception $e) { + Log::error('User listing error', [ + 'error' => $e->getMessage(), + 'trace' => $e->getTrace() + ]); + return $this->createErrorResponse($response, Response::HTTP_UNAUTHORIZED, STATUS_UNAUTHENTICATED, 'Failed to list users: ' . $e->getMessage()); +// throw new Exception('Failed to user-service: ' . $e->getMessage(), STATUS_INTERNAL); + } + return $response; + } + + /** + * @throws BindingResolutionException + * @throws ConnectionException + */ + public function getUserProfile(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + { + $jsonData = $in->getPayload()->getValue(); + $data = json_decode($jsonData, true); + $this->authMiddleware->authenticateGrpcRequest(BaseGrpcService::getContext()->clientMetadata()); + $user = $this->userService->userProfile($data); + \Log::info('GetUserProfile called', [ + 'data' => $data, + 'user_id' => $data['id'] ?? null, + 'user' => $user + ]); + + if (!$user) { + $this->createErrorResponse( + $response, + Response::HTTP_NOT_FOUND, + STATUS_NOT_FOUND, + 'User not found' + ); + return $response; + } + + // Pack user data into Any + $anyData = new Any(); + $anyData->setValue(json_encode([ + 'data' => $user + ])); + + $response->setSuccess(true); + $response->setStatusCode(200); + $response->setData($anyData); + + return $response; + } + + } diff --git a/app/Grpc/Services/UserServer.php b/app/Grpc/Services/UserServer.php index 8e4c1f1..aef4db3 100644 --- a/app/Grpc/Services/UserServer.php +++ b/app/Grpc/Services/UserServer.php @@ -144,157 +144,6 @@ private function createUser(FlexibleRequest $request, FlexibleResponse $response return $response; } - /** - * Get user by ID - * @throws Exception - */ - private function getUser(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse - { - $jsonData = $request->getPayload()->getValue(); - $data = json_decode($jsonData, true); - - $validator = Validator::make($data, [ - 'id' => 'required|integer|min:1' - ]); - $validator->validate(); - if ($validator->fails()) { - $this->createErrorResponse( - $response, - Response::HTTP_BAD_REQUEST, - STATUS_INVALID_ARGUMENT, - $validator->errors() - ); - return $response; -// throw new Exception($validator->errors(), STATUS_INVALID_ARGUMENT); - } - $user = $this->userService->show($data['id']); - $user = $user['data']; - if (!$user) { - $this->createErrorResponse( - $response, - Response::HTTP_NOT_FOUND, - STATUS_NOT_FOUND, - 'User not found: ' . ($data['id'] ?? 'unknown') - ); - return $response; -// throw new Exception($message, STATUS_NOT_FOUND); - } - - $responseData = new Any(); - $resource = new UserResource($user); - $responseData->setValue(json_encode([ - 'data' => $resource - ])); - - $response->setSuccess(true); - $response->setStatusCode(200); - $response->setData($responseData); - - - return $response; - } - - /** - * Update user - */ - private function updateUser(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse - { - $jsonData = $request->getPayload()->getValue(); - $data = json_decode($jsonData, true); - - $user = User::find($data['id'] ?? null); - - if (!$user) { - return $this->createErrorResponse($response, 404, 'USER_NOT_FOUND', 'User not found'); - } - - // Validate update data - $validator = Validator::make($data, [ - 'name' => 'sometimes|string|max:255', - 'email' => 'sometimes|email|unique:users,email,' . $user->id, - ]); - - if ($validator->fails()) { - return $this->createErrorResponse($response, 400, 'VALIDATION_ERROR', $validator->errors()->first()); - } - - $user->update(array_intersect_key($data, array_flip(['name', 'email']))); - - $responseData = new Any(); - $responseData->setValue(json_encode([ - 'data' => new UserResource($user) - ])); - - $response->setSuccess(true); - $response->setStatusCode(200); - $response->setData($responseData); - - return $response; - } - - /** - * Delete user - */ - private function deleteUser(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse - { - $jsonData = $request->getPayload()->getValue(); - $data = json_decode($jsonData, true); - - $user = User::find($data['id'] ?? null); - - if (!$user) { - return $this->createErrorResponse($response, 404, 'USER_NOT_FOUND', 'User not found'); - } - - $user->delete(); - - $response->setSuccess(true); - $response->setStatusCode(204); - - - return $response; - } - - /** - * List users with pagination - * @throws Exception - */ - private function listUsers(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse - { - $jsonData = $request->getPayload()->getValue(); - $filters = json_decode($jsonData, true) ?? []; - try { - $users = $this->userService->index(); - $users = data_get($users, 'data'); - $responseData = new Any(); - $resourceCollection = UserResource::collection($users); - $responseData->setValue(json_encode([ - 'data' => $resourceCollection, -// 'pagination' => [ -// 'current_page' => $users->currentPage(), -// 'total_pages' => $users->lastPage(), -// 'total_items' => $users->total(), -// 'per_page' => $users->perPage() -// ] - ])); - - $response->setSuccess(true); - $response->setStatusCode(200); - \Log::info('User listing successful', [ - 'total_users' => count($users), - 'users' => $users - ]); - $response->setData($responseData); - } catch (Exception $e) { - Log::error('User listing error', [ - 'error' => $e->getMessage(), - 'trace' => $e->getTrace() - ]); - return $this->createErrorResponse($response, Response::HTTP_UNAUTHORIZED, STATUS_UNAUTHENTICATED, 'Failed to list users: ' . $e->getMessage()); -// throw new Exception('Failed to user-service: ' . $e->getMessage(), STATUS_INTERNAL); - } - return $response; - } /** * @throws Exception @@ -353,44 +202,6 @@ private function login(FlexibleRequest $in, FlexibleResponse $response): Flexibl return $response; } - /** - * @throws BindingResolutionException - * @throws ConnectionException - */ - private function GetUserProfile(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse - { - $jsonData = $in->getPayload()->getValue(); - $data = json_decode($jsonData, true); - $this->authMiddleware->authenticateGrpcRequest(self::$context->clientMetadata()); - $user = $this->userService->userProfile($data); - \Log::info('GetUserProfile called', [ - 'data' => $data, - 'user_id' => $data['id'] ?? null, - 'user' => $user - ]); - - if (!$user) { - $this->createErrorResponse( - $response, - Response::HTTP_NOT_FOUND, - STATUS_NOT_FOUND, - 'User not found' - ); - return $response; - } - - // Pack user data into Any - $anyData = new Any(); - $anyData->setValue(json_encode([ - 'data' => $user - ])); - - $response->setSuccess(true); - $response->setStatusCode(200); - $response->setData($anyData); - - return $response; - } private function logout(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse diff --git a/routes/grpc.php b/routes/grpc.php index 4201577..2c5b2c7 100644 --- a/routes/grpc.php +++ b/routes/grpc.php @@ -4,10 +4,9 @@ // User Service Routes GrpcRoute::service('UserService') - ->method('GetUser', 'UserController', 'show') - ->method('UpdateUser', 'UserController', 'update') - ->method('DeleteUser', 'UserController', 'destroy') - ->method('ListUsers', 'UserController', 'index'); + ->method('GetUser', 'UserController', 'getUser') + ->method('ListUsers', 'UserController', 'listUsers') + ->method('GetUserProfile', 'UserController', 'getUserProfile'); GrpcRoute::service('Auth') ->method('Login', 'AuthController', 'login') From bc2836b42a299a511a87a5a89f399cfc3bb35737 Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Sat, 14 Jun 2025 04:53:03 +0300 Subject: [PATCH 09/12] Add validation for empty login request data in AuthController --- app/Grpc/Controllers/AuthController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Grpc/Controllers/AuthController.php b/app/Grpc/Controllers/AuthController.php index d1078f1..c6a6ee5 100644 --- a/app/Grpc/Controllers/AuthController.php +++ b/app/Grpc/Controllers/AuthController.php @@ -71,6 +71,15 @@ public function createUser(FlexibleRequest $request, FlexibleResponse $response) public function login(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse { $data = $this->getRequestData($in); + if (empty($data)) { + Log::error('Login request data is empty'); + return $this->createErrorResponse( + $response, + Response::HTTP_BAD_REQUEST, + STATUS_INVALID_ARGUMENT, + 'Request data is empty' + ); + } $rules = new UserReadRequest()->rules(); $validator = Validator::make($data, $rules); if ($validator->fails()) { From 414ef30e2c2ea61b9a9d4a0e06ee832ccf228b70 Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Sat, 14 Jun 2025 06:53:54 +0300 Subject: [PATCH 10/12] Refactor ApiGatewayRepository to use gRPC for product retrieval and update ProductHandler for dependency injection --- app/Handler/ProductHandler.php | 2 +- app/Repositories/ApiGatewayRepository.php | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Handler/ProductHandler.php b/app/Handler/ProductHandler.php index 8f576ff..208e1e2 100644 --- a/app/Handler/ProductHandler.php +++ b/app/Handler/ProductHandler.php @@ -12,6 +12,6 @@ class ProductHandler implements ItemHandlerInterface */ public function getItem($itemId) { - return new ApiGatewayRepository()->getProduct($itemId); + return app(ApiGatewayRepository::class)->getProduct($itemId); } } diff --git a/app/Repositories/ApiGatewayRepository.php b/app/Repositories/ApiGatewayRepository.php index daf18de..917b302 100644 --- a/app/Repositories/ApiGatewayRepository.php +++ b/app/Repositories/ApiGatewayRepository.php @@ -3,6 +3,7 @@ namespace App\Repositories; use App\External_Apis\Apis\ApiGateway; +use App\Grpc\Services\GrpcService; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\Client\ConnectionException; use Illuminate\Support\Facades\Http; @@ -13,7 +14,9 @@ class ApiGatewayRepository private string $productApi; private string $offerApi; - public function __construct() + public function __construct( + private GrpcService $grpcService, + ) { $this->productApi = ApiGateway::getService('product_uri'); $this->offerApi = ApiGateway::getService('offer_uri'); @@ -25,9 +28,15 @@ public function __construct() */ public function getProduct(int $productId) { - $response = http::withToken(request()->bearerToken())->get($this->productApi . $productId); - if ($response->successful()) - return $response->json('data'); +// $response = http::withToken(request()->bearerToken())->get($this->productApi . $productId); + request()->merge(['id' => $productId]); + $response = $this->grpcService->proxyRequest( + request(), + 'ProductService', + 'getProduct', + ); + if ($response->getStatusCode() === 200) + return data_get($response->getData(true), 'data'); return null; } From 7c9dfb2b8af9601129a72016a885ef9589ff8535 Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Sat, 14 Jun 2025 12:52:11 +0300 Subject: [PATCH 11/12] Refactor OfferHandler to use dependency injection for ApiGatewayRepository. --- app/Handler/OfferHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Handler/OfferHandler.php b/app/Handler/OfferHandler.php index 1062717..b6aa8c2 100644 --- a/app/Handler/OfferHandler.php +++ b/app/Handler/OfferHandler.php @@ -12,6 +12,6 @@ class OfferHandler implements ItemHandlerInterface */ public function getItem($itemId) { - return new ApiGatewayRepository()->getOffer($itemId); + return app(ApiGatewayRepository::class)->getOffer($itemId); } } From ed16929727149bfa33ba3a3c5f18859b61e35998 Mon Sep 17 00:00:00 2001 From: OmmrGAZAR315 Date: Sat, 14 Jun 2025 21:26:20 +0300 Subject: [PATCH 12/12] Refactor AuthController: rename `createUser` to `signup`, inject `GrpcAuthMiddleware`, and migrate `logout` method from UserServer. --- app/Grpc/Controllers/AuthController.php | 23 +++++++++++++++++++++-- app/Grpc/Services/UserServer.php | 17 ----------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/Grpc/Controllers/AuthController.php b/app/Grpc/Controllers/AuthController.php index c6a6ee5..9455781 100644 --- a/app/Grpc/Controllers/AuthController.php +++ b/app/Grpc/Controllers/AuthController.php @@ -21,7 +21,8 @@ class AuthController extends BaseGrpcService { public function __construct( - protected readonly UserService $userService + protected readonly UserService $userService, + protected readonly GrpcAuthMiddleware $authMiddleware ) { } @@ -29,7 +30,7 @@ public function __construct( /** * @throws Exception */ - public function createUser(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse + public function signup(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse { // Extract data from Any payload $userData = $this->getRequestData($request); @@ -130,6 +131,24 @@ public function login(FlexibleRequest $in, FlexibleResponse $response): Flexible return $response; } + public function logout(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse + { + try { + $this->authMiddleware->revokeGrpcToken(BaseGrpcService::getContext()->clientMetadata()); + return $this->createResponse( + [], + $response, + Response::HTTP_NO_CONTENT, + ); + } catch (Exception $e) { + Log::error('Logout error', [ + 'error' => $e->getMessage(), + 'trace' => $e->getTrace() + ]); + return $this->createErrorResponse($response, Response::HTTP_UNAUTHORIZED, STATUS_UNAUTHENTICATED, $isLoggedOut['error'] ?? 'Unauthenticated'); + } + } + public function validateToken(FlexibleRequest $request, FlexibleResponse $response): FlexibleResponse { diff --git a/app/Grpc/Services/UserServer.php b/app/Grpc/Services/UserServer.php index aef4db3..c8c44f7 100644 --- a/app/Grpc/Services/UserServer.php +++ b/app/Grpc/Services/UserServer.php @@ -204,22 +204,5 @@ private function login(FlexibleRequest $in, FlexibleResponse $response): Flexibl - private function logout(FlexibleRequest $in, FlexibleResponse $response): FlexibleResponse - { - try { - $this->authMiddleware->revokeGrpcToken(self::$context->clientMetadata()); - return $this->createResponse( - [], - $response, - Response::HTTP_NO_CONTENT, - ); - } catch (Exception $e) { - Log::error('Logout error', [ - 'error' => $e->getMessage(), - 'trace' => $e->getTrace() - ]); - return $this->createErrorResponse($response, Response::HTTP_UNAUTHORIZED, STATUS_UNAUTHENTICATED, $isLoggedOut['error'] ?? 'Unauthenticated'); - } - } }