Commit efc9e391 authored by Dzulfqar Ridha's avatar Dzulfqar Ridha

package $ plan

parent e3fe7711
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Classes\MResponse; use App\Classes\MResponse;
use App\Http\Request\CreateDefaultApplicationRequest; use App\Http\Request\Application\CreateDefaultApplicationRequest;
class ApplicationController extends BaseController class ApplicationController extends BaseController
{ {
......
<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController
{
//
}
<?php
namespace App\Http\Controllers;
class ExampleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
//
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:24 PM
*/
namespace App\Http\Controllers;
use App\Classes\MResponse;
use App\Http\Request\PackagePlan\PlanRequest;
class PackagePlanController extends BaseController
{
public function getPackagePlan()
{
$mResponse = new MResponse();
$statusCode = 200;
try {
$response = $this->masheryClient()->request('GET', 'https://api.mashery.com/v3/rest/packages', [
'query' => [
'fields' => 'id,name,description,plans.id,plans.name,plans.description'
]
]);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function getPackage()
{
$mResponse = new MResponse();
$statusCode = 200;
try {
$response = $this->masheryClient()->request('GET', 'https://api.mashery.com/v3/rest/packages', [
'query' => [
'fields' => 'id,name,description'
]
]);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function getPlan(PlanRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/packages/' . $request->get('pkgid') . '/plans';
try {
$response = $this->masheryClient()->request('GET', $url);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
}
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Classes\MResponse; use App\Classes\MResponse;
use App\Http\Request\UserByUsernameRequest; use App\Http\Request\User\UserByUsernameRequest;
use App\Http\Request\CreateUserRequest; use App\Http\Request\User\CreateUserRequest;
use App\Http\Request\User\UserByIdRequest;
use App\Http\Request\User\UpdateUserRequest;
class UserController extends BaseController class UserController extends BaseController
{ {
...@@ -44,6 +46,33 @@ class UserController extends BaseController ...@@ -44,6 +46,33 @@ class UserController extends BaseController
return response()->json($mResponse, $statusCode); return response()->json($mResponse, $statusCode);
} }
public function getById(UserByIdRequest $request){
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userid');
try {
$response = $this->masheryClient()->request('GET', $url);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function createUser(CreateUserRequest $request) public function createUser(CreateUserRequest $request)
{ {
$mResponse = new MResponse(); $mResponse = new MResponse();
...@@ -78,4 +107,33 @@ class UserController extends BaseController ...@@ -78,4 +107,33 @@ class UserController extends BaseController
return response()->json($mResponse, $statusCode); return response()->json($mResponse, $statusCode);
} }
public function updateUser(UpdateUserRequest $request){
$mResponse = new MResponse();
$statusCode = 200;
try {
$response = $this->masheryClient()->request('GET', 'https://api.mashery.com/v3/rest/members', [
'query' => [
'filter' => 'username:' . $request->get('username')
]
]);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
} }
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class PlanRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'pkgid' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class UpdateUserRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'username' => 'required',
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class UserByIdRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'userid' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
...@@ -15,23 +15,19 @@ $router->get('/', function () use ($router) { ...@@ -15,23 +15,19 @@ $router->get('/', function () use ($router) {
return $router->app->version(); return $router->app->version();
}); });
$router->get('/getUser', 'MasheryGetUserController@getUser');
$router->group(['prefix' => 'mashery'], function () use ($router) { $router->group(['prefix' => 'mashery'], function () use ($router) {
//mashery/token //mashery/token
$router->get('token', 'MasheryController@getToken'); $router->get('token', 'MasheryController@getToken');
//mashery/getUser?token={token}&username={mashery_username}
$router->get('getUser', 'MasheryController@getUser');
//mashery/createUser?token={}&username={}&email={}&dname={}&pass={}
$router->get('createUser', 'MasheryController@createUser');
}); });
$router->group(['middleware' => 'client.auth'], function () use ($router) { $router->group(['middleware' => 'client.auth'], function () use ($router) {
$router->group(['prefix' => 'user'], function () use ($router) { $router->group(['prefix' => 'user'], function () use ($router) {
$router->get('by-username', 'UserController@getByUsername'); $router->get('by-username', 'UserController@getByUsername');
$router->get('by-id', 'UserController@getById');
$router->get('update', 'UserController@updateUser');
$router->post('create', 'UserController@createUser'); $router->post('create', 'UserController@createUser');
}); });
...@@ -40,4 +36,12 @@ $router->group(['middleware' => 'client.auth'], function () use ($router) { ...@@ -40,4 +36,12 @@ $router->group(['middleware' => 'client.auth'], function () use ($router) {
$router->post('create', 'ApplicationController@createApp'); $router->post('create', 'ApplicationController@createApp');
}); });
$router->group(['prefix' => 'package'], function () use ($router) {
$router->get('package', 'PackagePlanController@getPackage');
$router->get('plan', 'PackagePlanController@getPlan');
$router->get('package-plan', 'PackagePlanController@getPackagePlan');
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment