Add: Repositories & categories (filter out) arguments to Product query builder

This commit is contained in:
machiav3lli 2022-09-26 00:18:29 +02:00
parent b52e89512e
commit ccd72d3944

View File

@ -124,6 +124,8 @@ interface ProductDao : BaseDao<Product> {
updates: Boolean,
searchQuery: String,
section: Section,
filteredOutRepos: Set<String> = emptySet(),
filteredOutCategories: Set<String> = emptySet(),
order: Order,
ascending: Boolean = false,
numberOfItems: Int = 0,
@ -178,14 +180,22 @@ interface ProductDao : BaseDao<Product> {
ON $TABLE_PRODUCT.$ROW_PACKAGE_NAME = $TABLE_INSTALLED.$ROW_PACKAGE_NAME"""
// Merge the matching category
if (section is Section.Category) {
builder += """JOIN $TABLE_CATEGORY_NAME AS $TABLE_CATEGORY
ON $TABLE_PRODUCT.$ROW_PACKAGE_NAME = $TABLE_CATEGORY.$ROW_PACKAGE_NAME"""
}
builder += """JOIN $TABLE_CATEGORY_NAME AS $TABLE_CATEGORY
ON $TABLE_PRODUCT.$ROW_PACKAGE_NAME = $TABLE_CATEGORY.$ROW_PACKAGE_NAME"""
// Filter only active repositories
builder += """WHERE $TABLE_REPOSITORY.$ROW_ENABLED != 0"""
// Filter out repositories
if (filteredOutRepos.isNotEmpty()) {
builder += "AND $TABLE_PRODUCT.$ROW_REPOSITORY_ID NOT IN(${filteredOutRepos.joinToString { "'$it'" }})"
}
// Filter out categories
if (filteredOutCategories.isNotEmpty()) {
builder += "AND $TABLE_CATEGORY.$ROW_LABEL NOT IN(${filteredOutCategories.joinToString { "'$it'" }})"
}
// Filter only the selected repository/category
if (section is Section.Category) {
builder += "AND $TABLE_CATEGORY.$ROW_LABEL = ?"