Browse Source

add: ProjectComment (m_project_comment)

pull/3/head
ardhi 2 years ago
parent
commit
13a87932f0
  1. 57
      app/Http/Controllers/ProjectCommentController.php
  2. 24
      app/Models/ProjectComment.php
  3. 4
      routes/web.php

57
app/Http/Controllers/ProjectCommentController.php

@ -0,0 +1,57 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectComment;
class ProjectCommentController extends Controller
{
public function add(Request $request)
{
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProjectComment::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add comment successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add comment failed!','code'=>400], 400);
}
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = ProjectComment::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data project successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project failed updated!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_project_comment');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
}

24
app/Models/ProjectComment.php

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjectComment extends Model
{
protected $table = 'm_project_comment';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'sender_id',
'project_id',
'gantt_id',
'comment',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

4
routes/web.php

@ -418,6 +418,10 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/project-to-checklist-k3/search', 'ProjectToChecklistK3Controller@search'); $router->post('/project-to-checklist-k3/search', 'ProjectToChecklistK3Controller@search');
$router->delete('/project-to-checklist-k3/delete/{id}', 'ProjectToChecklistK3Controller@delete'); $router->delete('/project-to-checklist-k3/delete/{id}', 'ProjectToChecklistK3Controller@delete');
$router->get('/project-to-checklist-k3/list', 'ProjectToChecklistK3Controller@list'); $router->get('/project-to-checklist-k3/list', 'ProjectToChecklistK3Controller@list');
$router->post('/project-comment/add', 'ProjectCommentController@add');
$router->put('/project-comment/update/{id}', 'ProjectCommentController@update');
$router->post('/project-comment/search', 'ProjectCommentController@search');
}); });
}); });

Loading…
Cancel
Save