Skip to content

Instantly share code, notes, and snippets.

@juliuscanute
Created July 4, 2019 06:05
Show Gist options
  • Save juliuscanute/bdf035b55a585ccd8a6d12f12612ae84 to your computer and use it in GitHub Desktop.
Save juliuscanute/bdf035b55a585ccd8a6d12f12612ae84 to your computer and use it in GitHub Desktop.
Dictionary Repository
class DictionaryRepository : RepositoryInterface, KoinComponent {
companion object {
val RECORDS_PER_PAGE = 20
}
val client: DocumentClient by inject()
override fun getNumberOfPagesInDictionary(): Page {
var page: Page
try {
val document = client.queryDocuments(
System.getenv("COLLECTION_URI"),
"SELECT Dictionary.total AS TotalRecords FROM Dictionary WHERE Dictionary.partition = 'atoz' AND Dictionary.total > 0", null).queryIterable.first()
val total = document.getInt("TotalRecords")
val endPage = ceil(total.toFloat() / RECORDS_PER_PAGE.toFloat()).toInt()
page = Page(1, endPage, RECORDS_PER_PAGE)
} catch (e: Exception) {
throw PageRetrievalException(e.message ?: "Unable to retrieve data")
}
return page
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment