Loading Api/AbstractApi.php +4 −4 Original line number Original line Diff line number Diff line Loading @@ -139,9 +139,9 @@ abstract class AbstractApi implements Interfaces\Api $this->sendError(500); $this->sendError(500); } } protected function sendBadRequest(): void protected function sendBadRequest(string $message = null): void { { $this->sendError(400); $this->sendError(400, $message); } } protected function sendNotImplemented(): void protected function sendNotImplemented(): void Loading @@ -154,9 +154,9 @@ abstract class AbstractApi implements Interfaces\Api $this->sendError(304); $this->sendError(304); } } protected function sendNotAcceptable(): void protected function sendNotAcceptable(string $message = null): void { { $this->sendError(406); $this->sendError(406, $message); } } protected function sendUnauthorised(): void protected function sendUnauthorised(): void Loading Core/Boost/Network/ElasticRepository.php +4 −1 Original line number Original line Diff line number Diff line Loading @@ -199,6 +199,9 @@ class ElasticRepository ->setImpressionsMet($doc['_source']['impressions_met']) ->setImpressionsMet($doc['_source']['impressions_met']) ->setBid($doc['_source']['bid']) ->setBid($doc['_source']['bid']) ->setBidType($doc['_source']['bid_type']); ->setBidType($doc['_source']['bid_type']); if (isset($doc['_source']['boost_type'])) { $boost->setBoostType($doc['_source']['boost_type']); } $offset = $boost->getCreatedTimestamp(); $offset = $boost->getCreatedTimestamp(); $response[] = $boost; $response[] = $boost; } } Loading Loading @@ -236,7 +239,7 @@ class ElasticRepository 'owner_guid' => $boost->getOwnerGuid(), 'owner_guid' => $boost->getOwnerGuid(), 'rating' => $boost->getRating(), 'rating' => $boost->getRating(), 'type' => $boost->getType(), 'type' => $boost->getType(), 'priority' => (bool) $boost->isPriority(), 'boost_type' => $boost->getBoostType(), ], ], 'doc_as_upsert' => true, 'doc_as_upsert' => true, ]; ]; Loading Core/Boost/Network/Manager.php +62 −0 Original line number Original line Diff line number Diff line Loading @@ -3,11 +3,14 @@ namespace Minds\Core\Boost\Network; namespace Minds\Core\Boost\Network; use Minds\Common\Repository\Response; use Minds\Common\Repository\Response; use Minds\Core\Boost\Checksum; use Minds\Core\Boost\Delegates\ValidateCampaignDatesDelegate; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\EntitiesBuilder; use Minds\Core\EntitiesBuilder; use Minds\Core\GuidBuilder; use Minds\Core\GuidBuilder; use Minds\Core\Events\Dispatcher; use Minds\Core\Events\Dispatcher; use Minds\Entities\Entity; use Minds\Entities\Entity; use Minds\Entities\User; class Manager class Manager { { Loading Loading @@ -265,4 +268,63 @@ class Manager return $offchainBoosts; return $offchainBoosts; } } public function getCampaigns(array $opts) { $opts = array_merge($opts, [ 'owner_guid' => $this->actor->getGUID(), 'boost_type' => Boost::BOOST_TYPE_CAMPAIGN ]); return $this->elasticRepository->getList($opts); } public function setActor(User $user): self { $this->actor = $user; return $this; } public function createCampaign(Campaign $campaign): Campaign { $campaign = $this->campaignUrnDelegate->onCreate($campaign); $campaign->setOwner($this->actor); if (!$campaign->getOwnerGuid()) { throw new CampaignException('Campaign should have an owner'); } if (!$campaign->getName()) { throw new CampaignException('Campaign should have a name'); } $validTypes = ['newsfeed', 'content', 'banner', 'video']; if (!in_array($campaign->getType(), $validTypes, true)) { throw new CampaignException('Invalid campaign type'); } /** TODO: Checksum Verification */ $checksum = (new Checksum())->setGuid($campaign->getGuid())->setEntity($campaign->getEntityGuid())->generate(); if (!$campaign->getChecksum() || ($campaign->getChecksum() !== $checksum)) { throw new CampaignException('Invalid checksum value'); } $campaign = (new ValidateCampaignDatesDelegate())->onCreate($campaign); $this->sync($campaign); return $campaign; } public function updateCampaign(Campaign $campaign): Campaign { // TODO: Implement this... return $campaign; } public function cancelCampaign(Campaign $campaign): Campaign { // TODO: Implement this... return $campaign; } } } Spec/Core/Boost/Network/ElasticRepositorySpec.php +1 −2 Original line number Original line Diff line number Diff line Loading @@ -56,8 +56,7 @@ class ElasticRepositorySpec extends ObjectBehavior && $body['doc']['impressions'] === 10000 && $body['doc']['impressions'] === 10000 && $body['doc']['impressions_met'] === 10 && $body['doc']['impressions_met'] === 10 && $body['doc']['owner_guid'] === 456 && $body['doc']['owner_guid'] === 456 && $body['doc']['type'] === 'newsfeed' && $body['doc']['type'] === 'newsfeed'; && $body['doc']['priority'] === false; })) })) ->shouldBeCalled() ->shouldBeCalled() ->willReturn(true); ->willReturn(true); Loading Loading
Api/AbstractApi.php +4 −4 Original line number Original line Diff line number Diff line Loading @@ -139,9 +139,9 @@ abstract class AbstractApi implements Interfaces\Api $this->sendError(500); $this->sendError(500); } } protected function sendBadRequest(): void protected function sendBadRequest(string $message = null): void { { $this->sendError(400); $this->sendError(400, $message); } } protected function sendNotImplemented(): void protected function sendNotImplemented(): void Loading @@ -154,9 +154,9 @@ abstract class AbstractApi implements Interfaces\Api $this->sendError(304); $this->sendError(304); } } protected function sendNotAcceptable(): void protected function sendNotAcceptable(string $message = null): void { { $this->sendError(406); $this->sendError(406, $message); } } protected function sendUnauthorised(): void protected function sendUnauthorised(): void Loading
Core/Boost/Network/ElasticRepository.php +4 −1 Original line number Original line Diff line number Diff line Loading @@ -199,6 +199,9 @@ class ElasticRepository ->setImpressionsMet($doc['_source']['impressions_met']) ->setImpressionsMet($doc['_source']['impressions_met']) ->setBid($doc['_source']['bid']) ->setBid($doc['_source']['bid']) ->setBidType($doc['_source']['bid_type']); ->setBidType($doc['_source']['bid_type']); if (isset($doc['_source']['boost_type'])) { $boost->setBoostType($doc['_source']['boost_type']); } $offset = $boost->getCreatedTimestamp(); $offset = $boost->getCreatedTimestamp(); $response[] = $boost; $response[] = $boost; } } Loading Loading @@ -236,7 +239,7 @@ class ElasticRepository 'owner_guid' => $boost->getOwnerGuid(), 'owner_guid' => $boost->getOwnerGuid(), 'rating' => $boost->getRating(), 'rating' => $boost->getRating(), 'type' => $boost->getType(), 'type' => $boost->getType(), 'priority' => (bool) $boost->isPriority(), 'boost_type' => $boost->getBoostType(), ], ], 'doc_as_upsert' => true, 'doc_as_upsert' => true, ]; ]; Loading
Core/Boost/Network/Manager.php +62 −0 Original line number Original line Diff line number Diff line Loading @@ -3,11 +3,14 @@ namespace Minds\Core\Boost\Network; namespace Minds\Core\Boost\Network; use Minds\Common\Repository\Response; use Minds\Common\Repository\Response; use Minds\Core\Boost\Checksum; use Minds\Core\Boost\Delegates\ValidateCampaignDatesDelegate; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\EntitiesBuilder; use Minds\Core\EntitiesBuilder; use Minds\Core\GuidBuilder; use Minds\Core\GuidBuilder; use Minds\Core\Events\Dispatcher; use Minds\Core\Events\Dispatcher; use Minds\Entities\Entity; use Minds\Entities\Entity; use Minds\Entities\User; class Manager class Manager { { Loading Loading @@ -265,4 +268,63 @@ class Manager return $offchainBoosts; return $offchainBoosts; } } public function getCampaigns(array $opts) { $opts = array_merge($opts, [ 'owner_guid' => $this->actor->getGUID(), 'boost_type' => Boost::BOOST_TYPE_CAMPAIGN ]); return $this->elasticRepository->getList($opts); } public function setActor(User $user): self { $this->actor = $user; return $this; } public function createCampaign(Campaign $campaign): Campaign { $campaign = $this->campaignUrnDelegate->onCreate($campaign); $campaign->setOwner($this->actor); if (!$campaign->getOwnerGuid()) { throw new CampaignException('Campaign should have an owner'); } if (!$campaign->getName()) { throw new CampaignException('Campaign should have a name'); } $validTypes = ['newsfeed', 'content', 'banner', 'video']; if (!in_array($campaign->getType(), $validTypes, true)) { throw new CampaignException('Invalid campaign type'); } /** TODO: Checksum Verification */ $checksum = (new Checksum())->setGuid($campaign->getGuid())->setEntity($campaign->getEntityGuid())->generate(); if (!$campaign->getChecksum() || ($campaign->getChecksum() !== $checksum)) { throw new CampaignException('Invalid checksum value'); } $campaign = (new ValidateCampaignDatesDelegate())->onCreate($campaign); $this->sync($campaign); return $campaign; } public function updateCampaign(Campaign $campaign): Campaign { // TODO: Implement this... return $campaign; } public function cancelCampaign(Campaign $campaign): Campaign { // TODO: Implement this... return $campaign; } } }
Spec/Core/Boost/Network/ElasticRepositorySpec.php +1 −2 Original line number Original line Diff line number Diff line Loading @@ -56,8 +56,7 @@ class ElasticRepositorySpec extends ObjectBehavior && $body['doc']['impressions'] === 10000 && $body['doc']['impressions'] === 10000 && $body['doc']['impressions_met'] === 10 && $body['doc']['impressions_met'] === 10 && $body['doc']['owner_guid'] === 456 && $body['doc']['owner_guid'] === 456 && $body['doc']['type'] === 'newsfeed' && $body['doc']['type'] === 'newsfeed'; && $body['doc']['priority'] === false; })) })) ->shouldBeCalled() ->shouldBeCalled() ->willReturn(true); ->willReturn(true); Loading