| @@ -19,8 +19,9 @@ | ||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function getLabelsByBoard($board_id) |
| 22 | 22 | { |
| 23 | + $board_id = absint($board_id); | |
| 23 | 24 | try { |
| 24 | 25 | $labels = $this->labelService->getLabelsByBoard($board_id); |
| 25 | 26 | |
| 26 | 27 | return $this->sendSuccess([ |
| @@ -26,14 +27,15 @@ | ||
| 26 | 27 | return $this->sendSuccess([ |
| 27 | 28 | 'labels' => $labels, |
| 28 | 29 | ], 200); |
| 29 | 30 | } catch(\Exception $e) { |
| 30 | - return $this->sendError($e->getMessage(), 404); | |
| 31 | + return $this->sendError($e->getMessage(), 400); | |
| 31 | 32 | } |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | 35 | public function getLabelsByBoardUsedInTasks($board_id) |
| 35 | 36 | { |
| 37 | + $board_id = absint($board_id); | |
| 36 | 38 | try { |
| 37 | 39 | $labels = $this->labelService->getLabelsByBoardUsedInTasks($board_id); |
| 38 | 40 | |
| 39 | 41 | return $this->sendSuccess([ |
| @@ -39,15 +41,16 @@ | ||
| 39 | 41 | return $this->sendSuccess([ |
| 40 | 42 | 'labels' => $labels, |
| 41 | 43 | ], 200); |
| 42 | 44 | } catch(\Exception $e) { |
| 43 | - return $this->sendError($e->getMessage(), 404); | |
| 45 | + return $this->sendError($e->getMessage(), 400); | |
| 44 | 46 | } |
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | public function createLabel(Request $request, $board_id) |
| 48 | 50 | { |
| 49 | - $labelData = $this->labelSanitizeAndValidate($request->all(), [ | |
| 51 | + $board_id = absint($board_id); | |
| 52 | + $labelData = $this->labelSanitizeAndValidate($request->only(['bg_color', 'color', 'label']), [ | |
| 50 | 53 | 'bg_color' => 'required|string', |
| 51 | 54 | 'color' => 'required|string', |
| 52 | 55 | 'label' => 'nullable|string', |
| 53 | 56 | ]); |
| @@ -53,9 +56,9 @@ | ||
| 53 | 56 | ]); |
| 54 | 57 | |
| 55 | 58 | try { |
| 56 | 59 | $label = $this->labelService->createLabel($labelData, $board_id); |
| 57 | - do_action('fluent_boards/board_label', $label, Constant::ACTIVITY_ACTION_CREATED); | |
| 60 | + do_action('fluent_boards/board_label_created', $label); | |
| 58 | 61 | |
| 59 | 62 | return $this->sendSuccess([ |
| 60 | 63 | 'message' => __('Label has been created', 'fluent-boards'), |
| 61 | 64 | 'label' => $label, |
| @@ -66,20 +69,20 @@ | ||
| 66 | 69 | } |
| 67 | 70 | |
| 68 | 71 | public function createLabelForTask(Request $request, $board_id) |
| 69 | 72 | { |
| 73 | + $board_id = absint($board_id); | |
| 70 | 74 | $requestData = [ |
| 71 | - 'task_id' => $request->taskId, | |
| 72 | - 'boardTerm_id' => (int) $request->labelId, | |
| 75 | + 'task_id' => $request->getSafe('taskId', 'intval'), | |
| 76 | + 'board_term_id' => $request->getSafe('labelId', 'intval'), | |
| 73 | 77 | ]; |
| 74 | 78 | |
| 75 | 79 | $labelData = $this->labelSanitizeAndValidate($requestData, [ |
| 76 | 80 | 'task_id' => 'required|integer', |
| 77 | - 'boardTerm_id' => 'required|integer', | |
| 81 | + 'board_term_id' => 'required|integer', | |
| 78 | 82 | ]); |
| 79 | 83 | try { |
| 80 | - $label = $this->labelService->createLabelForTask($labelData); | |
| 81 | -// do_action('fluent_boards/label_manage_for_task_activity', $label->task_id, 'added'); | |
| 84 | + $label = $this->labelService->createLabelForTask($labelData, $board_id); | |
| 82 | 85 | |
| 83 | 86 | return $this->sendSuccess([ |
| 84 | 87 | 'message' => __('Label has been added', 'fluent-boards'), |
| 85 | 88 | 'label' => $label, |
| @@ -90,27 +93,32 @@ | ||
| 90 | 93 | } |
| 91 | 94 | |
| 92 | 95 | public function getLabelsByTask($board_id, $task_id) |
| 93 | 96 | { |
| 97 | + $board_id = absint($board_id); | |
| 98 | + $task_id = absint($task_id); | |
| 94 | 99 | try { |
| 95 | - $labels = $this->labelService->getLabelsByTask($task_id); | |
| 100 | + $labels = $this->labelService->getLabelsByTask($task_id, $board_id); | |
| 96 | 101 | |
| 97 | 102 | return $this->sendSuccess([ |
| 98 | 103 | 'labels' => $labels, |
| 99 | 104 | ], 200); |
| 100 | 105 | } catch(\Exception $e) { |
| 101 | - return $this->sendError($e->getMessage(), 404); | |
| 106 | + return $this->sendError($e->getMessage(), 400); | |
| 102 | 107 | } |
| 103 | 108 | } |
| 104 | 109 | |
| 105 | 110 | public function deleteLabelOfTask($board_id, $task_id, $label_id) |
| 106 | 111 | { |
| 112 | + $board_id = absint($board_id); | |
| 113 | + $task_id = absint($task_id); | |
| 114 | + $label_id = absint($label_id); | |
| 107 | 115 | try { |
| 108 | - $this->labelService->deleteLabelOfTask($task_id, $label_id); | |
| 116 | + $this->labelService->deleteLabelOfTask($task_id, $label_id, $board_id); | |
| 109 | 117 | |
| 110 | 118 | return $this->sendSuccess([ |
| 111 | 119 | 'message' => __('Label has been deleted', 'fluent-boards'), |
| 112 | - ], 201); | |
| 120 | + ], 200); | |
| 113 | 121 | } catch (\Exception $e) { |
| 114 | 122 | return $this->sendError($e->getMessage(), 400); |
| 115 | 123 | } |
| 116 | 124 | } |
| @@ -116,25 +124,17 @@ | ||
| 116 | 124 | } |
| 117 | 125 | |
| 118 | 126 | public function deleteLabelOfBoard($board_id, $label_id) |
| 119 | 127 | { |
| 128 | + $board_id = absint($board_id); | |
| 129 | + $label_id = absint($label_id); | |
| 120 | 130 | try { |
| 131 | + $this->labelService->deleteLabelOfBoard($label_id, $board_id); | |
| 121 | 132 | |
| 122 | - $label = Label::findOrFail($label_id); | |
| 123 | - | |
| 124 | - if (count($label->tasks) > 0) { | |
| 125 | - return $this->sendError([ | |
| 126 | - 'message' => __("You can't delete. This label used in task.", 'fluent-boards'), | |
| 127 | - 'type' => 'warning', | |
| 128 | - ]); | |
| 129 | - } | |
| 130 | - | |
| 131 | - $this->labelService->deleteLabelOfBoard($label_id); | |
| 132 | - | |
| 133 | 133 | return $this->sendSuccess([ |
| 134 | 134 | 'message' => __('Label has been deleted', 'fluent-boards'), |
| 135 | 135 | 'type' => 'success', |
| 136 | - ], 201); | |
| 136 | + ], 200); | |
| 137 | 137 | } catch (\Exception $e) { |
| 138 | 138 | return $this->sendError($e->getMessage(), 400); |
| 139 | 139 | } |
| 140 | 140 | } |
| @@ -140,16 +140,18 @@ | ||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | public function editLabelofBoard(Request $request, $board_id, $label_id) |
| 143 | 143 | { |
| 144 | - $labelData = $this->labelSanitizeAndValidate($request->all(), [ | |
| 144 | + $board_id = absint($board_id); | |
| 145 | + $label_id = absint($label_id); | |
| 146 | + $labelData = $this->labelSanitizeAndValidate($request->only(['bg_color', 'color', 'label']), [ | |
| 145 | 147 | 'bg_color' => 'required|string', |
| 146 | - 'color' => 'required|string', | |
| 148 | + 'color' => 'nullable|string', | |
| 147 | 149 | 'label' => 'nullable|string', |
| 148 | 150 | ]); |
| 149 | 151 | try { |
| 150 | - $label = $this->labelService->editLabelofBoard($labelData, $label_id); | |
| 151 | - do_action('fluent_boards/board_label', $label, Constant::ACTIVITY_ACTION_UPDATED); | |
| 152 | + $label = $this->labelService->editLabelofBoard($labelData, $label_id, $board_id); | |
| 153 | + do_action('fluent_boards/board_label_updated', $label); | |
| 152 | 154 | |
| 153 | 155 | return $this->sendSuccess([ |
| 154 | 156 | 'message' => __('Label has been updated', 'fluent-boards'), |
| 155 | 157 | 'label' => $label, |