Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Campaigns objectives endpoint #12616

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading