Jelajahi Sumber

эндпоинты для работы с квестами персонажа, модель CharQuest

ilg2005 4 bulan lalu
induk
melakukan
e221d15f47
3 mengubah file dengan 144 tambahan dan 0 penghapusan
  1. 115 0
      app/Http/Controllers/CharController.php
  2. 22 0
      app/Models/Char/CharQuest.php
  3. 7 0
      routes/api.php

+ 115 - 0
app/Http/Controllers/CharController.php

@@ -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],
     ];
 
 

+ 22 - 0
app/Models/Char/CharQuest.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Models\Char;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use DB;
+use App\Models\Char\CharBase;
+
+class CharQuest extends Model
+{
+    protected $connection = "Char";
+    protected $table = "Table_CharQuest";    
+    protected $dates = [];
+    protected $fillable =
+            [
+              "Owner", "Slot", "Deleted", "RecId", "State", "MCnt1", "MCnt2", "MCnt3", "MCnt4", "MCnt5", "Show", "RemLimitTime"
+            ];
+
+    public $timestamps = false;   
+
+}

+ 7 - 0
routes/api.php

@@ -38,6 +38,13 @@ Route::group(['prefix' => 'api'], function () {
     // Получение и обновление предмета по char_item_id в нужной таблице
     Route::get('GetCharItem/{table}/{char_item_id}', 'CharController@GetCharItem');
     Route::post('UpdateCharItem/{table}/{char_item_id}', 'CharController@UpdateCharItem');
+    
+    // Получение всех квестов конкретного персонажа
+    Route::get('GetCharacterQuests/{char_id}', 'CharController@GetCharacterQuests');
+    
+    // Получение и обновление конкретного квеста персонажа по ID персонажа и слоту
+    Route::get('GetCharacterQuest/{char_id}/{slot}', 'CharController@GetCharacterQuest');    
+    Route::post('UpdateCharacterQuest/{char_id}/{slot}', 'CharController@UpdateCharacterQuest');
 
     Route::group(['prefix' => 'funcs_adm'], function () {
         Route::get('UpdateCharItemAccount/{CharID?}', 'ADMIN\AdminController@UpdateCharItemAccount');