-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from mchekin/buying-from-character-store
Buying from character store (Basic)
- Loading branch information
Showing
52 changed files
with
11,865 additions
and
2,292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ Homestead.yaml | |
npm-debug.log | ||
yarn-error.log | ||
/.vagrant | ||
/public/mix-manifest.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Modules\Trade\Application\Services\TradeService; | ||
use App\Modules\Trade\UI\Http\CommandMappers\BuyItemCommandMapper; | ||
use App\Modules\Trade\UI\Http\CommandMappers\SellItemCommandMapper; | ||
use Exception; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class TradeController extends Controller | ||
{ | ||
/** | ||
* @var TradeService | ||
*/ | ||
private $service; | ||
|
||
public function __construct(TradeService $service) | ||
{ | ||
$this->service = $service; | ||
} | ||
|
||
public function buyItem(Request $request, BuyItemCommandMapper $commandMapper): JsonResponse | ||
{ | ||
$command = $commandMapper->map($request); | ||
|
||
try { | ||
|
||
DB::transaction(function () use ($command) { | ||
$this->service->buyItem($command); | ||
}); | ||
|
||
} catch (Exception $exception) { | ||
|
||
return response()->json([ | ||
'message' => 'Error buying item: ' . $exception->getMessage() | ||
], 500); | ||
} | ||
|
||
return response()->json(['message' => 'Item bought']); | ||
} | ||
|
||
public function sellItem(Request $request, SellItemCommandMapper $commandMapper): JsonResponse | ||
{ | ||
$command = $commandMapper->map($request); | ||
|
||
try { | ||
|
||
DB::transaction(function () use ($command) { | ||
$this->service->sellItem($command); | ||
}); | ||
|
||
} catch (Exception $exception) { | ||
|
||
return response()->json([ | ||
'message' => 'Error buying item: ' . $exception->getMessage() | ||
], 500); | ||
} | ||
|
||
return response()->json(['message' => 'Item bought']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Character; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Http\Request; | ||
|
||
class CharacterStoreController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth'); | ||
$this->middleware('has.character'); | ||
} | ||
|
||
public function index(Request $request, string $characterId): View | ||
{ | ||
/** @var Character $customer */ | ||
$customer = $request->user()->character; | ||
|
||
/** @var Character $trader */ | ||
$trader = Character::query()->findOrFail($characterId); | ||
|
||
return view('trade.store.index', compact('customer', 'trader')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Modules\Trade\Application\Commands; | ||
|
||
use App\Modules\Character\Domain\CharacterId; | ||
use App\Modules\Equipment\Domain\ItemId; | ||
use App\Modules\Trade\Domain\StoreId; | ||
|
||
class BuyItemCommand | ||
{ | ||
/** | ||
* @var CharacterId | ||
*/ | ||
private $customerId; | ||
/** | ||
* @var StoreId | ||
*/ | ||
private $storeId; | ||
/** | ||
* @var ItemId | ||
*/ | ||
private $itemId; | ||
|
||
public function __construct(CharacterId $customerId, StoreId $storeId, ItemId $itemId) | ||
{ | ||
$this->customerId = $customerId; | ||
$this->storeId = $storeId; | ||
$this->itemId = $itemId; | ||
} | ||
|
||
public function getCustomerId(): CharacterId | ||
{ | ||
return $this->customerId; | ||
} | ||
|
||
public function getStoreId(): StoreId | ||
{ | ||
return $this->storeId; | ||
} | ||
|
||
public function getItemId(): ItemId | ||
{ | ||
return $this->itemId; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/Modules/Trade/Application/Commands/SellItemCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Modules\Trade\Application\Commands; | ||
|
||
use App\Modules\Character\Domain\CharacterId; | ||
use App\Modules\Equipment\Domain\ItemId; | ||
use App\Modules\Trade\Domain\StoreId; | ||
|
||
class SellItemCommand | ||
{ | ||
/** | ||
* @var CharacterId | ||
*/ | ||
private $customerId; | ||
/** | ||
* @var StoreId | ||
*/ | ||
private $storeId; | ||
/** | ||
* @var ItemId | ||
*/ | ||
private $itemId; | ||
|
||
public function __construct(CharacterId $customerId, StoreId $storeId, ItemId $itemId) | ||
{ | ||
$this->customerId = $customerId; | ||
$this->storeId = $storeId; | ||
$this->itemId = $itemId; | ||
} | ||
|
||
public function getCustomerId(): CharacterId | ||
{ | ||
return $this->customerId; | ||
} | ||
|
||
public function getStoreId(): StoreId | ||
{ | ||
return $this->storeId; | ||
} | ||
|
||
public function getItemId(): ItemId | ||
{ | ||
return $this->itemId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/Modules/Trade/Application/Services/CreateStoreService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types=1); | ||
|
||
|
||
namespace App\Modules\Trade\Application\Services; | ||
|
||
use App\Modules\Equipment\Domain\Money; | ||
use App\Modules\Trade\Application\Commands\CreateStoreCommand; | ||
use App\Modules\Trade\Application\Contracts\StoreRepositoryInterface; | ||
use App\Modules\Trade\Domain\Store; | ||
use App\Modules\Trade\Domain\StoreType; | ||
use Illuminate\Support\Collection; | ||
|
||
class CreateStoreService | ||
{ | ||
/** | ||
* @var StoreRepositoryInterface | ||
*/ | ||
private $storeRepository; | ||
|
||
public function __construct(StoreRepositoryInterface $storeRepository) | ||
{ | ||
$this->storeRepository = $storeRepository; | ||
} | ||
|
||
public function create(CreateStoreCommand $command): Store | ||
{ | ||
$id = $this->storeRepository->nextIdentity(); | ||
|
||
$store = new Store($id, $command->getCharacterId(), StoreType::sellOnly(), Collection::make(), new Money(0)); | ||
|
||
$this->storeRepository->add($store); | ||
|
||
return $store; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.