Karat service

This commit is contained in:
StudioTem committed 2023-02-23 07:39:29 +01:00
1 parent e575fabff0
commit cba2118366
6 files changed
+181

No files matched your search

@@ -0,0 +1,39 @@
<?php
namespace App\Console\Commands;
use App\Services\Karat\KaratService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
class SyncUsersFromKarat extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'karat:sync-users';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Syncs users from Karat to our DB';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$karatService = new KaratService();
dd($karatService->syncUsers());
return Command::SUCCESS;
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Services\Karat;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
class Api
{
/**
* @var array|mixed
*/
private mixed $username;
/**
* @var array|mixed
*/
private mixed $password;
/**
* @var array|mixed
*/
private mixed $endpoint;
public function __construct()
{
$this->username = Config::get('services.karat.username');
$this->password = Config::get('services.karat.password');
$this->endpoint = Config::get('services.karat.endpoint');
}
private function doRequest($command)
{
$response = Http::withOptions([
'debug' => true,
'verify' => false,
])->withBasicAuth($this->username, $this->password)
->post($this->endpoint, [
'command' => $command,
]);
return $response->json();
}
public function getUsers()
{
return $this->doRequest('TM_GET_USERS');
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Services\Karat;
class KaratService
{
private Api $api;
public function __construct()
{
$this->api = new Api();
}
public function syncUsers()
{
$users = $this->api->getUsers();
dd($users);
return $users;
}
}
+7
View File
@@ -31,4 +31,11 @@ return [
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
], ],
'karat' => [
'username' => env('KARAT_USERNAME'),
'password' => env('KARAT_PASSWORD'),
'endpoint' => 'https://86.110.228.181:39001/service',
],
]; ];
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('master_tasks', function (Blueprint $table) {
$table->foreignIdFor( \App\Models\User::class, 'created_by')->after('team_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('master_tasks', function (Blueprint $table) {
//
});
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('sub_tasks', function (Blueprint $table) {
$table->foreignIdFor( \App\Models\User::class, 'created_by')->after('master_task_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('sub_tasks', function (Blueprint $table) {
//
});
}
};