mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
no message
This commit is contained in:
1 parent
b076052f4b
commit
8affdbe955
9 files changed
+257
-12
No files matched your search
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Blocker;
|
||||||
|
use App\Models\Team;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class BlockerController extends Controller
|
||||||
|
{
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$validator = Validator::make($request->all(), [
|
||||||
|
'data.start' => 'required',
|
||||||
|
'data.end' => 'required',
|
||||||
|
'data.employee_id' => 'required',
|
||||||
|
'data.name' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()){
|
||||||
|
return response()->json($validator->errors(), 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$blocker = Blocker::create([
|
||||||
|
'start' => $request->all()['data']['start'],
|
||||||
|
'end' => $request->all()['data']['end'],
|
||||||
|
'user_id' => $request->all()['data']['employee_id'],
|
||||||
|
'name' => $request->all()['data']['name'],
|
||||||
|
'type' => 'adhoc'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response()->json($blocker, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id, Request $request)
|
||||||
|
{
|
||||||
|
$validator = Validator::make($request->all(), [
|
||||||
|
'data.start' => 'required',
|
||||||
|
'data.end' => 'required',
|
||||||
|
'data.employee_id' => 'required',
|
||||||
|
'data.name' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()){
|
||||||
|
return response()->json($validator->errors(), 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// upratanie requestu, pretoze frontend pouziva inu nomenklaturu fieldov ako appka
|
||||||
|
$data['data'] = $request->all()['data'];
|
||||||
|
$data['data']['user_id'] = $request->all()['data']['employee_id'];
|
||||||
|
|
||||||
|
$request->merge($data);
|
||||||
|
|
||||||
|
$blocker = Blocker::find($id);
|
||||||
|
|
||||||
|
$blocker->update($request->all()['data']);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Blocker updated successfully',
|
||||||
|
'blocker' => $blocker
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function delete($id)
|
||||||
|
{
|
||||||
|
$blocker = Blocker::find($id);
|
||||||
|
$blocker->delete();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Blocker deleted successfully',
|
||||||
|
'team' => $blocker
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class BlockerResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'name' => $this->name,
|
||||||
|
'employee' => UserResource::make($this->user),
|
||||||
|
'start' => $this->start,
|
||||||
|
'end' => $this->end,
|
||||||
|
'type' => $this->type,
|
||||||
|
'color' => $this->color,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Blocker extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColorAttribute()
|
||||||
|
{
|
||||||
|
// TODO - zistit ci sa maju lisit farby
|
||||||
|
return $this->type == 'adhoc' ? '#B00020' : '#B00020';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,8 @@ class Api
|
|||||||
|
|
||||||
private static function doRequest($command)
|
private static function doRequest($command)
|
||||||
{
|
{
|
||||||
$response = Http::withOptions([
|
$response = Http::timeout(60)
|
||||||
|
->withOptions([
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'verify' => false,
|
'verify' => false,
|
||||||
])->withBasicAuth(self::$username, self::$password)
|
])->withBasicAuth(self::$username, self::$password)
|
||||||
@@ -52,6 +53,6 @@ class Api
|
|||||||
|
|
||||||
public static function getProjects()
|
public static function getProjects()
|
||||||
{
|
{
|
||||||
return self::doRequest('TM_GET_CLIENTS')['projects'];
|
return self::doRequest('TM_GET_PROJECTS')['projects'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,8 +35,8 @@ class KaratService
|
|||||||
})->map(function ($item) {
|
})->map(function ($item) {
|
||||||
$arrayToInsert = $item->toArray();
|
$arrayToInsert = $item->toArray();
|
||||||
|
|
||||||
$arrayToInsert['created_at'] = Carbon::now();
|
$arrayToInsert['created_at'] = Carbon::now()->toDateTimeString();
|
||||||
$arrayToInsert['updated_at'] = Carbon::now();
|
$arrayToInsert['updated_at'] = Carbon::now()->toDateTimeString();
|
||||||
|
|
||||||
return $arrayToInsert;
|
return $arrayToInsert;
|
||||||
});
|
});
|
||||||
@@ -71,8 +71,8 @@ class KaratService
|
|||||||
})->map(function ($item) {
|
})->map(function ($item) {
|
||||||
$arrayToInsert = $item->toArray();
|
$arrayToInsert = $item->toArray();
|
||||||
|
|
||||||
$arrayToInsert['created_at'] = Carbon::now();
|
$arrayToInsert['created_at'] = Carbon::now()->toDateTimeString();
|
||||||
$arrayToInsert['updated_at'] = Carbon::now();
|
$arrayToInsert['updated_at'] = Carbon::now()->toDateTimeString();
|
||||||
|
|
||||||
return $arrayToInsert;
|
return $arrayToInsert;
|
||||||
});
|
});
|
||||||
@@ -82,19 +82,55 @@ class KaratService
|
|||||||
|
|
||||||
private function removeClientsThatAreNotInKaratAnymore( Collection $karatClients, Collection $dbClients )
|
private function removeClientsThatAreNotInKaratAnymore( Collection $karatClients, Collection $dbClients )
|
||||||
{
|
{
|
||||||
dd('finish me');
|
$codesInDbThatAreNotInKaratAnymore = $dbClients->pluck('code' )->diff( $karatClients->pluck('code'));
|
||||||
|
|
||||||
|
\App\Models\Client::whereIn('code', $codesInDbThatAreNotInKaratAnymore)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function syncProjects()
|
public function syncProjects()
|
||||||
{
|
{
|
||||||
$karatProjects = Project::all();
|
$karatProjects = Project::all();
|
||||||
|
|
||||||
|
$array = [];
|
||||||
|
foreach ( $karatProjects as $project ) {
|
||||||
|
$array[$project->code][] = $project->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $array as $key => $item ) {
|
||||||
|
if ( count($item) > 1 ) echo ($key) . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd('here');
|
||||||
|
|
||||||
$dbProjects = \App\Models\Project::all();
|
$dbProjects = \App\Models\Project::all();
|
||||||
|
|
||||||
$this->insertProjectsFromKarat($karatProjects, $dbProjects);
|
$this->insertProjectsFromKarat($karatProjects->take(200), $dbProjects);
|
||||||
|
dd('here');
|
||||||
|
|
||||||
$this->removeProjectsThatAreNotInKaratAnymore($karatProjects, $dbProjects);
|
$this->removeProjectsThatAreNotInKaratAnymore($karatProjects, $dbProjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function insertProjectsFromKarat( Collection $karatProjects, Collection $dbProjects )
|
||||||
|
{
|
||||||
|
$projectsToSkip = $dbProjects->pluck('code' )->intersect( $karatProjects->pluck('code'));
|
||||||
|
|
||||||
|
$karatProjectsToInsert = $karatProjects->reject(function ($item) use ($projectsToSkip) {
|
||||||
|
return $projectsToSkip->contains($item->code);
|
||||||
|
})->map(function ($item) {
|
||||||
|
$arrayToInsert = $item->toArray();
|
||||||
|
|
||||||
|
$dbClient = \App\Models\Client::where('code', $item->client_id)->first();
|
||||||
|
|
||||||
|
$arrayToInsert['created_at'] = Carbon::now()->toDateTimeString();
|
||||||
|
$arrayToInsert['updated_at'] = Carbon::now()->toDateTimeString();
|
||||||
|
$arrayToInsert['client_id'] = ($dbClient) ? $dbClient->id : null;
|
||||||
|
// $arrayToInsert['client_id'] = 12;
|
||||||
|
|
||||||
|
return $arrayToInsert;
|
||||||
|
});
|
||||||
|
|
||||||
|
\App\Models\Project::insert($karatProjectsToInsert->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,12 +5,12 @@ namespace App\Services\Karat;
|
|||||||
class Project extends Api {
|
class Project extends Api {
|
||||||
public $code;
|
public $code;
|
||||||
public $name;
|
public $name;
|
||||||
public $client;
|
public $client_id;
|
||||||
|
|
||||||
public function __construct($code, $name, $client) {
|
public function __construct($code, $name, $client_id) {
|
||||||
$this->code = $code;
|
$this->code = $code;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->client = $client;
|
$this->client_id = $client_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function all() {
|
public static function all() {
|
||||||
@@ -25,7 +25,7 @@ class Project extends Api {
|
|||||||
return [
|
return [
|
||||||
'code' => $this->code,
|
'code' => $this->code,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'client' => $this->client,
|
'client_id' => $this->client_id,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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('projects', function (Blueprint $table) {
|
||||||
|
$table->foreignIdFor(\App\Models\Client::class)->nullable(-1)->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('projects', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?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::create('blockers', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignIdFor(\App\Models\User::class);
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('type');
|
||||||
|
$table->timestamp( 'start');
|
||||||
|
$table->timestamp( 'end');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('blockers');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\BlockerController;
|
||||||
use App\Http\Controllers\MasterTaskController;
|
use App\Http\Controllers\MasterTaskController;
|
||||||
use App\Http\Controllers\SubTaskController;
|
use App\Http\Controllers\SubTaskController;
|
||||||
use App\Http\Controllers\TeamController;
|
use App\Http\Controllers\TeamController;
|
||||||
use App\Http\Controllers\UserController;
|
use App\Http\Controllers\UserController;
|
||||||
|
use App\Http\Resources\BlockerResource;
|
||||||
use App\Http\Resources\MasterTaskCollection;
|
use App\Http\Resources\MasterTaskCollection;
|
||||||
use App\Http\Resources\MasterTaskResource;
|
use App\Http\Resources\MasterTaskResource;
|
||||||
use App\Http\Resources\ProjectCollection;
|
use App\Http\Resources\ProjectCollection;
|
||||||
@@ -13,6 +15,7 @@ use App\Http\Resources\TeamCollection;
|
|||||||
use App\Http\Resources\TeamResource;
|
use App\Http\Resources\TeamResource;
|
||||||
use App\Http\Resources\UserCollection;
|
use App\Http\Resources\UserCollection;
|
||||||
use App\Http\Resources\UserResource;
|
use App\Http\Resources\UserResource;
|
||||||
|
use App\Models\Blocker;
|
||||||
use App\Models\MasterTask;
|
use App\Models\MasterTask;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\SubTask;
|
use App\Models\SubTask;
|
||||||
@@ -90,6 +93,13 @@ Route::middleware(['auth:sanctum'])->group(function () {
|
|||||||
Route::get('/v1/subtasks',SubTaskController::class . '@index');
|
Route::get('/v1/subtasks',SubTaskController::class . '@index');
|
||||||
|
|
||||||
Route::delete('/v1/subtasks/{id}', SubTaskController::class . '@delete');
|
Route::delete('/v1/subtasks/{id}', SubTaskController::class . '@delete');
|
||||||
|
|
||||||
|
Route::get('/v1/blockers/{id}', function ($id) {
|
||||||
|
return new BlockerResource( Blocker::find($id));
|
||||||
|
});
|
||||||
|
Route::post('/v1/blockers', BlockerController::class . '@store');
|
||||||
|
Route::put('/v1/blockers/{id}', BlockerController::class . '@update');
|
||||||
|
Route::delete('/v1/blockers/{id}', BlockerController::class . '@delete');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::post('/v1/tokens/create', function (Request $request) {
|
Route::post('/v1/tokens/create', function (Request $request) {
|
||||||
|
|||||||
Reference in new issue
Block a user