Browse Source

update post to get method

pull/3/head
wahyuun 1 year ago
parent
commit
ab5fd49d37
  1. 67
      app/Http/Controllers/Controller.php
  2. 23
      app/Http/Controllers/ProjectController.php
  3. 2
      routes/web.php

67
app/Http/Controllers/Controller.php

@ -37,73 +37,6 @@ class Controller extends BaseController
$this->pathActivityDocument = config('assets.activity'); $this->pathActivityDocument = config('assets.activity');
} }
protected function setUpPayloadByUser($condition)
{
$alias = "utp";
$userProyek = UserToProyek::from('assign_hr_to_proyek AS ' . $alias);
$userProyek = $userProyek->where([
['is_customer', true],
['user_id', $condition['user_id']['user_id']]
])->select('m_proyek.*', 'm_type_proyek.name AS join_second_name');
if (isset($condition['joins'])) {
$no = 0;
foreach ($condition['joins'] as $join) {
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias;
$tableName = $join['name'];
$columnJoin = $join['column_join']; // foreign key table sini
$columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan
$columnResult = $join['column_results'];
foreach ($columnResult as $sColumn) {
$userProyek = $userProyek->addSelect($tableName . "." . $sColumn . " as join_" . $this->listJoinAll[$no] . "_" . $sColumn);
}
$userProyek = $userProyek->leftJoin($tableName, $tableJoin . "." . $columnJoin, '=', $tableName . '.' . $columnSelf);
$no++;
}
$userProyek->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id');
}
if (isset($condition['columns'])) {
$listWhere = $condition['columns'];
$userProyek = $userProyek->where(function ($query) use ($listWhere, $alias) {
foreach ($listWhere as $where) {
$value = $where['value'];
if ($value && $value != "" && $value != " ") {
$column = $where['name'];
$operator = strtolower($where['logic_operator']); // like, =, <>, range
$value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
});
}
if (isset($condition['group_column'])) {
$userProyek = $this->groupWhere($userProyek, $condition['group_column'], $alias);
}
$data['count'] = clone $userProyek;
if (isset($condition['paging'])) {
$userProyek = $userProyek->offset($condition['paging']['start'])->limit($condition['paging']['length']);
}
if (isset($condition['orders'])) {
$orders = $condition['orders'];
$sortBy = $orders['ascending'] ? "ASC" : "DESC";
$columnOrder = $orders['columns'];
foreach ($columnOrder as $column) {
$userProyek = $userProyek->orderBy($alias . "." . $column, $sortBy);
}
}
$data['userProyek'] = $userProyek;
return $data;
}
protected function setUpPayload($condition, $tableSelf) protected function setUpPayload($condition, $tableSelf)
{ {
$alias = "selfTable"; $alias = "selfTable";

23
app/Http/Controllers/ProjectController.php

@ -204,16 +204,23 @@ class ProjectController extends Controller
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
} }
public function getByUser(Request $request) public function getByUser($id)
{ {
$payload = $request->all(); $alias = "utp";
$dataBuilder = $this->setUpPayloadByUser($payload); $userProyek = UserToProyek::query()
$builder = $dataBuilder['userProyek']; ->from('assign_hr_to_proyek AS ' . $alias)
$countBuilder = $dataBuilder['count']; ->where([
$dataGet = $builder->get(); ['is_customer', true],
$totalRecord = $countBuilder->count(); ['user_id', $id]
])
->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias.'.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name','m_users.name AS join_first_name')
->get();
$totalRecord = $userProyek->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
} }
public function search(Request $request) public function search(Request $request)

2
routes/web.php

@ -53,7 +53,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->post('/project-by-customer', 'ProjectController@getByUser'); $router->get('/project-by-customer/{id}','ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search'); $router->post('/project/search', 'ProjectController@search');
$router->post('/project/add', 'ProjectController@add'); $router->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update'); $router->put('/project/update/{id}', 'ProjectController@update');

Loading…
Cancel
Save