diff --git a/src/Http/Controllers/Api/v2/CorporationController.php b/src/Http/Controllers/Api/v2/CorporationController.php index c5625a2..c159976 100644 --- a/src/Http/Controllers/Api/v2/CorporationController.php +++ b/src/Http/Controllers/Api/v2/CorporationController.php @@ -26,6 +26,7 @@ use Seat\Api\Http\Resources\ContactResource; use Seat\Api\Http\Resources\ContractResource; use Seat\Api\Http\Resources\CorporationSheetResource; +use Seat\Api\Http\Resources\CorporationStructure; // getStructures use Seat\Api\Http\Resources\IndustryResource; use Seat\Api\Http\Resources\MemberTrackingResource; use Seat\Api\Http\Traits\Filterable; @@ -38,6 +39,7 @@ use Seat\Eveapi\Models\Market\CorporationOrder; use Seat\Eveapi\Models\Wallet\CorporationWalletJournal; use Seat\Eveapi\Models\Wallet\CorporationWalletTransaction; +use Seat\Web\Models\UniverseMoonReport; // getMiningExtractions /** * Class CorporationController. @@ -114,6 +116,73 @@ public function getAssets(int $corporation_id) return Resource::collection($query->paginate()); } + /** + * @OA\Get( + * path="/v2/corporation/strctures/{corporation_id}", + * tags={"Structures"}, + * summary="Get a paginated list of structures for a corporation", + * description="Returns a list of structures", + * security={ + * {"ApiKeyAuth": {}} + * }, + * @OA\Parameter( + * name="corporation_id", + * description="Corporation id", + * required=true, + * @OA\Schema( + * type="integer" + * ), + * in="path" + * ), + * @OA\Parameter( + * in="query", + * name="$filter", + * description="Query filter following OData format", + * @OA\Schema( + * type="string" + * ) + * ), + * @OA\Response(response=200, description="Successful operation", + * @OA\JsonContent( + * type="object", + * @OA\Property( + * type="array", + * property="data", + * @OA\Items(ref="#/components/schemas/CorporationStructure") + * ), + * @OA\Property( + * property="links", + * ref="#/components/schemas/ResourcePaginatedLinks" + * ), + * @OA\Property( + * property="meta", + * ref="#/components/schemas/ResourcePaginatedMetadata" + * ) + * ) + * ), + * @OA\Response(response=400, description="Bad request"), + * @OA\Response(response=401, description="Unauthorized"), + * ) + * + * @param int $corporation_id + * + * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection + */ + public function getStructures(int $corporation_id) + { + request()->validate([ + '$filter' => 'string', + ]); + + $query = CorporationStructure::with('type', 'info', 'solar_system') + ->where('corporation_id', $corporation_id) + ->where(function ($sub_query) { + $this->applyFilters(request(), $sub_query); + }); + + return Resource::collection($query->paginate()); + } + /** * @OA\Get( * path="/v2/corporation/contacts/{corporation_id}", @@ -314,6 +383,30 @@ public function getIndustry(int $corporation_id) return IndustryResource::collection($query->paginate()); } + + /** + * + */ + public function getMiningExtractions(int $corporation_id) + { + request()->validate([ + '$filter' => 'string', + ]); + + $query = UniverseMoonReport::with('content', 'moon', 'moon.solar_system', 'moon.constellation', + 'moon.region', 'moon.extraction', 'moon.extraction.structure', 'moon.extraction.structure.info') + ->whereHas('moon.extraction.structure', function ($query) use ($corporation_id) { + $query->where('corporation_id', $corporation_id); + }) + ->whereHas('moon.extraction', function ($query) { + $query->where('natural_decay_time', '>', carbon()->subSeconds(CorporationIndustryMiningExtraction::THEORETICAL_DEPLETION_COUNTDOWN)); + }) + ->where(function ($sub_query) { + $this->applyFilters(request(), $sub_query); + }); + + return CorporationMiningExtractionResource::collection($query->paginate()); + } /** * @OA\Get( diff --git a/src/Http/Resources/CorporationMiningExtractionResource.php b/src/Http/Resources/CorporationMiningExtractionResource.php new file mode 100644 index 0000000..2906203 --- /dev/null +++ b/src/Http/Resources/CorporationMiningExtractionResource.php @@ -0,0 +1,35 @@ +$this->moon->solar_system->name, + 'moon_name'=>$this->moon->name, + 'structure_name'=>$this->moon->extraction->structure->info->name, + + 'extraction_start_time'=>$this->moon->extraction->extraction_start_time, + 'chunk_arrival_time'=>$this->moon->extraction->chunk_arrival_time, + 'natural_decay_time'=>$this->moon->extraction->natural_decay_time, + + 'content'=>$this->content + ]; + } +} diff --git a/src/Http/Resources/CorporationStructureResource.php b/src/Http/Resources/CorporationStructureResource.php new file mode 100644 index 0000000..989bed4 --- /dev/null +++ b/src/Http/Resources/CorporationStructureResource.php @@ -0,0 +1,64 @@ + $this->info->name, + 'structure_id'=> $this->structure_id, + + 'type_name'=> $this->type->typeName + 'type_id'=> $this->type_id, + + 'system_name'=>$this->solar_system->name, + 'system_id'=> $this->system_id, + + //// + // + // Proposing : + // + // 'structure' => [ + // 'name' => $this->info->name, + // 'id' => $this->structure_id + // ], + // + // 'type' => [ + // 'name' => $this->type->typeName, + // 'id' => $this->type_id + // ], + // + // 'solar_system' => [ + // 'name' => $this->solar_system->name, + // 'id' => $this->system_id + // ], + // + //// + + 'fuel_expires'=>$this->fuel_expires, + 'state'=>$this->state, + 'state_timer_start'=>$this->state_timer_start, + 'state_timer_end'=>$this->state_timer_end, + 'unanchors_at'=>$this->unanchors_at, + 'reinforce_hour'=>$this->reinforce_hour, + 'next_reinforce_hour'=>$this->next_reinforce_hour, + 'next_reinforce_apply'=>$this->next_reinforce_apply, + ]; + } +} diff --git a/src/Http/routes.php b/src/Http/routes.php index 09435f9..38d7ae4 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -124,9 +124,11 @@ Route::group(['prefix' => 'corporation'], function () { Route::get('/assets/{corporation_id}')->uses('CorporationController@getAssets'); + Route::get('/structures/{corporation_id}')->uses('CorporationController@getStructures'); Route::get('/contacts/{corporation_id}')->uses('CorporationController@getContacts'); Route::get('/contracts/{corporation_id}')->uses('CorporationController@getContracts'); Route::get('/industry/{corporation_id}')->uses('CorporationController@getIndustry'); + Route::get('/extractions/{corporation_id}')->uses('CorporationController@getMiningExtractions'); Route::get('/killmails/{corporation_id}')->uses('KillmailsController@getCorporationKillmails'); Route::get('/market-orders/{corporation_id}')->uses('CorporationController@getMarketOrders'); Route::get('/member-tracking/{corporation_id}')->uses('CorporationController@getMemberTracking');