|
1 | 1 | use crate::{
|
2 |
| - targeting::Rules, |
3 | 2 | validator::{ApproveState, Heartbeat, MessageTypes, NewState, Type as MessageType},
|
4 |
| - Address, BalancesMap, BigNum, Channel, ChannelId, ValidatorId, IPFS, |
| 3 | + Address, BigNum, Channel, ChannelId, ValidatorId, IPFS, |
5 | 4 | };
|
6 | 5 | use chrono::{DateTime, Utc};
|
7 | 6 | use serde::{Deserialize, Serialize};
|
@@ -361,6 +360,85 @@ pub mod campaign_create {
|
361 | 360 | }
|
362 | 361 | }
|
363 | 362 | }
|
| 363 | + |
| 364 | + /// This implementation helps with test setup |
| 365 | + /// **NOTE:** It erases the CampaignId, since the creation of the campaign gives it's CampaignId |
| 366 | + impl From<Campaign> for CreateCampaign { |
| 367 | + fn from(campaign: Campaign) -> Self { |
| 368 | + Self { |
| 369 | + channel: campaign.channel, |
| 370 | + creator: campaign.creator, |
| 371 | + budget: campaign.budget, |
| 372 | + validators: campaign.validators, |
| 373 | + title: campaign.title, |
| 374 | + pricing_bounds: campaign.pricing_bounds, |
| 375 | + event_submission: campaign.event_submission, |
| 376 | + ad_units: campaign.ad_units, |
| 377 | + targeting_rules: campaign.targeting_rules, |
| 378 | + created: campaign.created, |
| 379 | + active: campaign.active, |
| 380 | + } |
| 381 | + } |
| 382 | + } |
| 383 | + |
| 384 | + // All editable fields stored in one place, used for checking when a budget is changed |
| 385 | + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 386 | + pub struct ModifyCampaign { |
| 387 | + pub budget: Option<UnifiedNum>, |
| 388 | + pub validators: Option<Validators>, |
| 389 | + pub title: Option<String>, |
| 390 | + pub pricing_bounds: Option<PricingBounds>, |
| 391 | + pub event_submission: Option<EventSubmission>, |
| 392 | + pub ad_units: Option<Vec<AdUnit>>, |
| 393 | + pub targeting_rules: Option<Rules>, |
| 394 | + } |
| 395 | + |
| 396 | + impl ModifyCampaign { |
| 397 | + pub fn from_campaign(campaign: Campaign) -> Self { |
| 398 | + ModifyCampaign { |
| 399 | + budget: Some(campaign.budget), |
| 400 | + validators: Some(campaign.validators), |
| 401 | + title: campaign.title, |
| 402 | + pricing_bounds: campaign.pricing_bounds, |
| 403 | + event_submission: campaign.event_submission, |
| 404 | + ad_units: Some(campaign.ad_units), |
| 405 | + targeting_rules: Some(campaign.targeting_rules), |
| 406 | + } |
| 407 | + } |
| 408 | + |
| 409 | + pub fn apply(self, mut campaign: Campaign) -> Campaign { |
| 410 | + if let Some(new_budget) = self.budget { |
| 411 | + campaign.budget = new_budget; |
| 412 | + } |
| 413 | + |
| 414 | + if let Some(new_validators) = self.validators { |
| 415 | + campaign.validators = new_validators; |
| 416 | + } |
| 417 | + |
| 418 | + // check if it was passed otherwise not sending a Title will result in clearing of the current one |
| 419 | + if let Some(new_title) = self.title { |
| 420 | + campaign.title = Some(new_title); |
| 421 | + } |
| 422 | + |
| 423 | + if let Some(new_pricing_bounds) = self.pricing_bounds { |
| 424 | + campaign.pricing_bounds = Some(new_pricing_bounds); |
| 425 | + } |
| 426 | + |
| 427 | + if let Some(new_event_submission) = self.event_submission { |
| 428 | + campaign.event_submission = Some(new_event_submission); |
| 429 | + } |
| 430 | + |
| 431 | + if let Some(new_ad_units) = self.ad_units { |
| 432 | + campaign.ad_units = new_ad_units; |
| 433 | + } |
| 434 | + |
| 435 | + if let Some(new_targeting_rules) = self.targeting_rules { |
| 436 | + campaign.targeting_rules = new_targeting_rules; |
| 437 | + } |
| 438 | + |
| 439 | + campaign |
| 440 | + } |
| 441 | + } |
364 | 442 | }
|
365 | 443 |
|
366 | 444 | #[cfg(feature = "postgres")]
|
|
0 commit comments