Skip to content

Commit

Permalink
API: Data: Unify notify API
Browse files Browse the repository at this point in the history
Since notifyLogController and processLogController are same identical logic, and only
have different with that data that serve into the users. Then merge both of them controller
into one controller instead split it into two controllers.

Also this should patch routes to disable that old route.

Signed-off-by: Dicky Herlambang (花) <herlambangdicky5@gmail.com>
  • Loading branch information
Nicklas373 committed May 11, 2024
1 parent d59fb4c commit e436e8f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 175 deletions.
78 changes: 76 additions & 2 deletions app/Http/Controllers/Api/Data/notifyLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getLogs(Request $request)
{
$validator = Validator::make($request->all(), [
'processId' => 'required|uuid',
'logType' => ['required', 'in:access,jobs,notify'],
'logType' => ['required', 'in:access,jobs,notify,compress,convert,html,merge,split,watermark'],
'telegramLogs' => 'required|boolean'
]);
if ($validator->fails()) {
Expand Down Expand Up @@ -60,6 +60,66 @@ public function getLogs(Request $request)
$applog = null;
$datalog = null;
$telegramlog = notifyLogsModel::where('processId', $processId)->get();
} else if ($logModel == 'compress') {
if ($telegramModel) {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = compressModel::where('processId', $processId)->get();
$telegramlog = notifyLogsModel::where('processId', $processId)->get();
} else {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = compressModel::where('processId', $processId)->get();
$telegramlog = null;
}
} else if ($logModel == 'convert') {
if ($telegramModel) {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = cnvModel::where('processId', $processId) ->get();
$telegramlog = notifyLogsModel::where('processId', $processId)->get();
} else {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = cnvModel::where('processId', $processId) ->get();
$telegramlog = null;
}
} else if ($logModel == 'html') {
if ($telegramModel) {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = htmlModel::where('processId', $processId)->get();
$telegramlog = notifyLogsModel::where('processId', $processId)->get();
} else {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = htmlModel::where('processId', $processId)->get();
$telegramlog = null;
}
} else if ($logModel == 'merge') {
if ($telegramModel) {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = mergeModel::where('processId', $processId)->get();
$telegramlog = notifyLogsModel::where('processId', $processId)->get();
} else {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = mergeModel::where('processId', $processId)->get();
$telegramlog = null;
}
} else if ($logModel == 'split') {
if ($telegramModel) {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = splitModel::where('processId', $processId)->get();
$telegramlog = notifyLogsModel::where('processId', $processId)->get();
} else {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = splitModel::where('processId', $processId)->get();
$telegramlog = null;
}
} else if ($logModel == 'watermark') {
if ($telegramModel) {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = watermarkModel::where('processId', $processId)->get();
$telegramlog = notifyLogsModel::where('processId', $processId)->get();
} else {
$applog = appLogsModel::where('processId', $processId)->get();
$datalog = watermarkModel::where('processId', $processId)->get();
$telegramlog = null;
}
}
if ($telegramModel) {
return $this->returnDataMesage(
Expand Down Expand Up @@ -113,7 +173,7 @@ public function getAllLogs(Request $request)
{
$validator = Validator::make($request->all(), [
'logCount' => 'required|int',
'logType' => ['required', 'in:access,jobs,notify'],
'logType' => ['required', 'in:access,jobs,notify,compress,convert,html,merge,split,watermark'],
]);
if ($validator->fails()) {
$errors = $validator->errors()->all();
Expand All @@ -137,6 +197,20 @@ public function getAllLogs(Request $request)
$datalog = jobLogsModel::take($logCount)->get();
} else if ($logModel == 'notify') {
$datalog = notifyLogsModel::take($logCount)->get();
} else if ($logModel == 'compress') {
$datalog = compressModel::orderBy('procStartAt', $logOrder)->take($logCount)->get();
} else if ($logModel == 'convert') {
$datalog = cnvModel::orderBy('procStartAt', $logOrder)->take($logCount)->get();
} else if ($logModel == 'delete') {
$datalog = deleteModel::orderBy('procStartAt', $logOrder)->take($logCount)->get();
} else if ($logModel == 'html') {
$datalog = htmlModel::orderBy('procStartAt', $logOrder)->take($logCount)->get();
} else if ($logModel == 'merge') {
$datalog = mergeModel::orderBy('procStartAt', $logOrder)->take($logCount)->get();
} else if ($logModel == 'split') {
$datalog = splitModel::orderBy('procStartAt', $logOrder)->take($logCount)->get();
} else if ($logModel == 'watermark') {
$datalog = watermarkModel::orderBy('procStartAt', $logOrder)->take($logCount)->get();
}
$dataArrayLog = $datalog->toArray();
return $this->returnDataMesage(
Expand Down
168 changes: 0 additions & 168 deletions app/Http/Controllers/Api/Data/processLogController.php

This file was deleted.

7 changes: 2 additions & 5 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use App\Http\Controllers\Api\Auth\AuthController;
use App\Http\Controllers\Api\Data\limitLogController;
use App\Http\Controllers\Api\Data\notifyLogController;
use App\Http\Controllers\Api\Data\processLogController;
use App\Http\Controllers\Api\File\thumbnailController;
use App\Http\Controllers\Api\File\uploadController;
use App\Http\Controllers\Api\Core\compressController;
Expand Down Expand Up @@ -56,10 +55,8 @@
Route::middleware(['auth:api'],['throttle:api'])->prefix('v1/logs')->group(function() {
// API v1 Backend Logging Route
Route::get('limit', [limitLogController::class, 'getLimit']);
Route::post('proc/single', [processLogController::class, 'getLogs']);
Route::post('proc/all', [processLogController::class, 'getAllLogs']);
Route::post('notify/single', [notifyLogController::class, 'getLogs']);
Route::post('notify/all', [notifyLogController::class, 'getAllLogs']);
Route::post('proc/single', [notifyLogController::class, 'getLogs']);
Route::post('proc/all', [notifyLogController::class, 'getAllLogs']);
});

Route::fallback(function () {
Expand Down

0 comments on commit e436e8f

Please sign in to comment.