|
|
@@ -7,6 +7,7 @@ use App\Models\Char\CharBase;
|
|
|
use App\Models\Char\CharCashItem_OutputBox;
|
|
|
use App\Models\Char\CharItem;
|
|
|
use App\Models\Char\CharFellow;
|
|
|
+use App\Models\Char\CharQuest;
|
|
|
|
|
|
class CharController extends Controller
|
|
|
{
|
|
|
@@ -310,6 +311,119 @@ class CharController extends Controller
|
|
|
|
|
|
return $this->_updateAndRespond($item, $data, 'Item successfully updated.');
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Получение всех квестов конкретного персонажа.
|
|
|
+ *
|
|
|
+ * @param int $char_id
|
|
|
+ * @param \Illuminate\Http\Request $request
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ */
|
|
|
+ public function GetCharacterQuests($char_id, Request $request)
|
|
|
+ {
|
|
|
+ // 1. Проверяем существование персонажа
|
|
|
+ if (!CharBase::find($char_id)) {
|
|
|
+ return response()->json(['code' => -2, 'msg' => 'Character not found.'], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. Валидация и параметры запроса
|
|
|
+ $validated = $request->validate([
|
|
|
+ 'per_page' => 'sometimes|integer|min:1|max:100',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $perPage = $validated['per_page'] ?? 15;
|
|
|
+ $sortField = $request->input('sort_field', 'Slot');
|
|
|
+ $sortOrder = strtolower($request->input('sort_order', 'asc')) === 'desc' ? 'desc' : 'asc';
|
|
|
+
|
|
|
+ // 3. Получаем квесты персонажа
|
|
|
+ $query = CharQuest::where('Owner', $char_id);
|
|
|
+ $questsPaginator = $query->orderBy($sortField, $sortOrder)->paginate($perPage);
|
|
|
+
|
|
|
+ // 4. Формируем ответ
|
|
|
+ if ($questsPaginator->total() === 0) {
|
|
|
+ return response()->json([
|
|
|
+ 'quests' => [],
|
|
|
+ 'code' => -3,
|
|
|
+ 'msg' => 'No quests found for this character.'
|
|
|
+ ], 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ return response()->json([
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => 'Character quests successfully received.',
|
|
|
+ 'quests' => $questsPaginator,
|
|
|
+ ], 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Получение конкретного квеста персонажа по ID персонажа и слоту.
|
|
|
+ *
|
|
|
+ * @param int $char_id
|
|
|
+ * @param int $slot
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ */
|
|
|
+ public function GetCharacterQuest($char_id, $slot)
|
|
|
+ {
|
|
|
+ // 1. Проверяем существование персонажа
|
|
|
+ if (!CharBase::find($char_id)) {
|
|
|
+ return response()->json(['code' => -2, 'msg' => 'Character not found.'], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. Ищем квест по Owner и Slot
|
|
|
+ $quest = CharQuest::where('Owner', $char_id)
|
|
|
+ ->where('Slot', $slot)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if (!$quest) {
|
|
|
+ return response()->json([
|
|
|
+ 'code' => -3,
|
|
|
+ 'msg' => 'Quest not found for this character.'
|
|
|
+ ], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. Формируем ответ
|
|
|
+ return response()->json([
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => 'Character quest successfully received.',
|
|
|
+ 'quest' => $quest,
|
|
|
+ ], 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Обновление квеста персонажа по ID персонажа и слоту.
|
|
|
+ *
|
|
|
+ * @param int $char_id
|
|
|
+ * @param int $slot
|
|
|
+ * @param \Illuminate\Http\Request $request
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ */
|
|
|
+ public function UpdateCharacterQuest($char_id, $slot, Request $request)
|
|
|
+ {
|
|
|
+ // 1. Проверяем существование персонажа
|
|
|
+ if (!CharBase::find($char_id)) {
|
|
|
+ return response()->json(['code' => -2, 'msg' => 'Character not found.'], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. Ищем квест по Owner и Slot
|
|
|
+ $quest = CharQuest::where('Owner', $char_id)
|
|
|
+ ->where('Slot', $slot)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if (!$quest) {
|
|
|
+ return response()->json([
|
|
|
+ 'code' => -3,
|
|
|
+ 'msg' => 'Quest not found for this character.'
|
|
|
+ ], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. Защищенные поля, которые нельзя изменить
|
|
|
+ $protectedFields = ['Owner', 'Slot'];
|
|
|
+ $data = $request->except($protectedFields);
|
|
|
+
|
|
|
+ // 4. Обновляем запись и формируем ответ
|
|
|
+ return $this->_updateAndRespond($quest, $data, 'Quest successfully updated.');
|
|
|
+ }
|
|
|
|
|
|
//------------------------------ ПРИВАТНЫЕ МЕТОДЫ -----------------------------------------
|
|
|
/**
|
|
|
@@ -333,6 +447,7 @@ class CharController extends Controller
|
|
|
'CharItem' => ['key' => 'Owner', 'model' => CharItem::class, 'pk' => 'CharItemID'],
|
|
|
'CharFellow' => ['key' => 'Owner', 'model' => CharFellow::class, 'pk' => 'FellowID'],
|
|
|
'CharCashItem_OutputBox' => ['key' => 'Owner', 'model' => CharCashItem_OutputBox::class, 'pk' => 'ItemDBIndex'],
|
|
|
+ 'CharQuest' => ['key' => 'Owner', 'model' => CharQuest::class],
|
|
|
];
|
|
|
|
|
|
|