WIP: (feat): Boost Campaigns module
0/4 discussions resolved
added 1 commit
- ad87348f - (proto): Create campaign normalization and validation
37 if ($limit > 50 || $limit < 0) { 38 $limit = 12; 39 } 40 41 $guid = ''; 42 43 if ($urn) { 44 $limit = 1; 45 $offset = ''; 46 47 $urn = new Urn($urn); 48 $guid = (string) $urn->getNss(); 49 } 50 51 /** @var Repository $repository */ 52 $repository = Di::_()->get('Boost\Campaigns\Repository'); - Owner
Should always be manager
64 ]); 65 } 66 67 /** 68 * Equivalent to HTTP POST method 69 * @param array $pages 70 * @return mixed|null 71 */ 72 public function post($pages) 73 { 74 $campaign = new Campaign(); 75 76 $campaign 77 ->setName(trim($_POST['name'] ?? '')) 78 ->setType($_POST['type'] ?? '') 79 ->setEntityUrns($_POST['entity_urns'] ?? null) - Owner
Can we assume formatting being sent? Json object vs comma vs array?
118 throw new CampaignException('Campaign should have a budget'); 119 } 120 121 // TODO: Validate offchain balance, or set as pending for onchain 122 123 // Generate URN 124 125 $guid = $this->guid->build(); 126 $urn = "urn:campaign:{$guid}"; 127 128 $campaign 129 ->setUrn($urn); 130 131 // Normalize and validate entity URNs 132 133 $entityUrns = array_values(array_unique(array_filter(Text::buildArray($campaign->getEntityUrns())))); - Owner
not sure what we can do here to avoid function overload
124 125 $guid = $this->guid->build(); 126 $urn = "urn:campaign:{$guid}"; 127 128 $campaign 129 ->setUrn($urn); 130 131 // Normalize and validate entity URNs 132 133 $entityUrns = array_values(array_unique(array_filter(Text::buildArray($campaign->getEntityUrns())))); 134 135 if (!$entityUrns) { 136 throw new CampaignException('Campaign should have at least an entity'); 137 } 138 139 $entityUrns = array_map(function ($entityUrn) { - Owner
Can we separate into a new function?