私のアプリケーションには、Customers と Couriers があります。顧客は、宅配業者が現在オンラインで、両方のユーザーが同じ場所にいる場合にのみ、宅配業者に配達依頼を送信できます。
顧客が宅配便業者に配送リクエストを送信したい場合、私のDeliveryRequest
サービスにはsendDeliveryRequest(Request request)
から呼び出されるメソッドがありController
ます。
public function sendDeliveryRequest(Request $request) {
$customer = $this->recognitionService->getUser();
$courier = $this->entityFactory->build('Courier');
$courier->setId( $request->post('courierId') );
$courierMapper = $this->mapperFactory->build('Courier');
$courierMapper->fetch($courier);
$deliveryRequest = $this->entityFactory->build('DeliveryRequest');
$someRequestedItems = array();
$deliveryRequest->sendRequest($customer, $courier, $someRequestedItems);
}
これまでのところ、私のsendRequest(Customer $customer, Courier $courier, Array $items)
方法では次のとおりです。
public function sendRequest(Customer $customer, Courier $courier, Array $items) {
// Check if the couriers account is active
if( !$courier->isActive() ) {
return 'courier not active';
}
// Check if the courier is online
if( !$courier->isOnline() ) {
return 'courier not online';
}
// Check the status of the customers location, active/inactive
if( !$customer->getLocation()->isActive() ) {
return 'customers location disabled';
}
// Check if the customer and the courier live in the same location
if( !$customer->sameLocationAs($courier) ) {
return 'customer and courier in different locations';
}
// More checks
}
これまでのところ、問題なく動作しているように見えますが、ビジネス ロジック、特に!$customer->sameLocationAs($courier)
.
このメソッドは、提供された$courier
オブジェクトを使用して Couriers の場所 ( を持つオブジェクトid
) を取得し、それを Customers の場所と比較して、同じ場所にあるかどうかを確認します。それは完全に機能しますが、両方のユーザーが同じ場所にいるかどうかを確認するための最良の方法であるかどうかはわかりません. それは有効なビジネス ロジックですか?
また、 のアイテム$deliveryRequest
、そのデータ ( id
、quantity
) は$request
から渡されたオブジェクトに含まれるため、 でController
それぞれを作成Item
し、それらを配列に入れて、andを使用Service
して配列をメソッドに渡します。つまり、そのメソッド内でチェック(入力された数量が数量のデータベース値を超えていないかどうかなどを確認する)を行う必要があることを意味しますが、それは正しい方法ですか、それとも悪いですか?$customer
$courier
sendRequest()
チェック/検証を正しく、アプリケーションの正しい場所/レイヤーで行っていますか?
どんな助けでも大歓迎です。