-
Notifications
You must be signed in to change notification settings - Fork 130
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 #10572 from woocommerce/issue/10555-retrieve-campa…
…ign-data-logic Issue/10555 retrieve campaign data logic
- Loading branch information
Showing
5 changed files
with
288 additions
and
132 deletions.
There are no files selected for viewing
84 changes: 83 additions & 1 deletion
84
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/BlazeRepository.kt
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 |
---|---|---|
@@ -1,12 +1,94 @@ | ||
package com.woocommerce.android.ui.blaze | ||
|
||
import com.woocommerce.android.tools.SelectedSite | ||
import com.woocommerce.android.ui.products.ProductDetailRepository | ||
import com.woocommerce.android.util.TimezoneProvider | ||
import org.wordpress.android.fluxc.store.blaze.BlazeCampaignsStore | ||
import java.util.Date | ||
import javax.inject.Inject | ||
|
||
class BlazeRepository @Inject constructor( | ||
private val selectedSite: SelectedSite, | ||
private val blazeCampaignsStore: BlazeCampaignsStore | ||
private val blazeCampaignsStore: BlazeCampaignsStore, | ||
private val productDetailRepository: ProductDetailRepository, | ||
private val timezoneProvider: TimezoneProvider, | ||
) { | ||
companion object { | ||
const val DEFAULT_CURRENCY_CODE = "USD" // For now only USD are supported | ||
const val DEFAULT_CAMPAIGN_DURATION = 7 // Days | ||
const val DEFAULT_CAMPAIGN_TOTAL_BUDGET = 35F // USD | ||
const val ONE_DAY_IN_MILLIS = 1000 * 60 * 60 * 24 | ||
} | ||
|
||
suspend fun getMostRecentCampaign() = blazeCampaignsStore.getMostRecentBlazeCampaign(selectedSite.get()) | ||
|
||
fun getCampaignPreviewDetails(productId: Long): CampaignPreview { | ||
val product = productDetailRepository.getProduct(productId) | ||
return CampaignPreview( | ||
productId = productId, | ||
aiSuggestions = listOf(), | ||
budget = Budget( | ||
totalBudget = DEFAULT_CAMPAIGN_TOTAL_BUDGET, | ||
spentBudget = 0f, | ||
currencyCode = DEFAULT_CURRENCY_CODE, | ||
durationInDays = DEFAULT_CAMPAIGN_DURATION, | ||
startDate = Date().apply { time += ONE_DAY_IN_MILLIS }, // By default start tomorrow | ||
), | ||
languages = listOf(), | ||
devices = listOf(), | ||
locations = listOf(), | ||
interests = listOf(), | ||
userTimeZone = timezoneProvider.deviceTimezone.displayName, | ||
targetUrl = product?.permalink ?: "", | ||
urlParams = null, | ||
campaignImageUrl = product?.firstImageUrl | ||
) | ||
} | ||
|
||
data class CampaignPreview( | ||
val productId: Long, | ||
val aiSuggestions: List<AiSuggestionForAd>, | ||
val budget: Budget, | ||
val languages: List<Language>, | ||
val devices: List<Device>, | ||
val locations: List<Location>, | ||
val interests: List<Interest>, | ||
val userTimeZone: String, | ||
val targetUrl: String, | ||
val urlParams: Pair<String, String>?, | ||
val campaignImageUrl: String?, | ||
) | ||
|
||
data class AiSuggestionForAd( | ||
val title: String, | ||
val tagLine: String, | ||
) | ||
|
||
data class Budget( | ||
val totalBudget: Float, | ||
val spentBudget: Float, | ||
val currencyCode: String, | ||
val durationInDays: Int, | ||
val startDate: Date, | ||
) | ||
|
||
data class Location( | ||
val id: String, | ||
val name: String, | ||
) | ||
|
||
data class Language( | ||
val code: String, | ||
val name: String, | ||
) | ||
|
||
data class Device( | ||
val id: String, | ||
val name: String, | ||
) | ||
|
||
data class Interest( | ||
val id: String, | ||
val description: String, | ||
) | ||
} |
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.