Skip to content

Commit

Permalink
Merge pull request #12616 from woocommerce/issue/12469-campaigns-obje…
Browse files Browse the repository at this point in the history
…ctives-endpoint

Campaigns objectives endpoint
  • Loading branch information
JorgeMucientes committed Sep 20, 2024
2 parents 692f475 + e93a0bb commit 525e121
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ class BlazeRepository @Inject constructor(
const val WEEKLY_DURATION = 7 // Used to calculate weekly budget in endless campaigns
}

fun observeObjectives() = blazeCampaignsStore.observeBlazeCampaignObjectives().map {
it.map { objective ->
Objective(
objective.id,
objective.title,
objective.description,
objective.suitableForDescription
)
}
}

suspend fun fetchObjectives(): Result<Unit> {
val result = blazeCampaignsStore.fetchBlazeCampaignObjectives(selectedSite.get())

return when {
result.isError -> {
WooLog.w(WooLog.T.BLAZE, "Failed to fetch objectives: ${result.error}")
Result.failure(OnChangedException(result.error))
}

else -> Result.success(Unit)
}
}

fun observeLanguages() = blazeCampaignsStore.observeBlazeTargetingLanguages()
.map { it.map { language -> Language(language.id, language.name) } }

Expand Down Expand Up @@ -378,6 +402,14 @@ class BlazeRepository @Inject constructor(
data class RemoteImage(val mediaId: Long, override val uri: String) : BlazeCampaignImage
}

@Parcelize
data class Objective(
val id: String,
val title: String,
val description: String,
val suitableForDescription: String
) : Parcelable

@Parcelize
data class TargetingParameters(
val locations: List<Location> = emptyList(),
Expand Down

0 comments on commit 525e121

Please sign in to comment.