Created
July 4, 2019 06:05
-
-
Save juliuscanute/bdf035b55a585ccd8a6d12f12612ae84 to your computer and use it in GitHub Desktop.
Dictionary Repository
This file contains hidden or 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
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