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

feat: STUD-366: Update GetSongs endpoint to sort earnings #587

Conversation

AndrewWestberg
Copy link
Member

No description provided.

@@ -1154,7 +1154,8 @@ class LedgerRepositoryImpl : LedgerRepository {
(AddressTxLogTable.id greater afterId) and
(AddressTxLogTable.blockNumber lessEq maxBlockNumber)
}.orderBy(AddressTxLogTable.id)
.limit(limit, offset)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is now deprecated in exposed. It actually contains a bug. Internally, it applies limit first and then offset. The ordering is very important to these two functions. offset MUST be applied before limit. If you have a list of 10 items and apply limit 5, offset 5, it will return you an empty list instead of the second 5 items of the original list.

@@ -69,7 +76,18 @@ fun Routing.createSongRoutes() {
}.sumOf { it.amount }
song.copy(earnings = allEarningsAmount)
}
respond(songsAndEarnings)
if (songFilters.sortedBy == "earnings") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat of the PR. The rest is the major exposed update. I attempted to update KTOR at the same time to version 3, but we need to wait until Koin supports that version of KTOR.

@@ -149,7 +147,6 @@ class SongEntity(

fun genres(filters: SongFilters): SizedIterable<String> {
val ops = filters.toOps()
val genre = SongTable.genres.unnest()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get our unnest() to work with the new Array support in exposed. I took the approach of just pulling all the data down and manipulating it in the kotlin code.


/**
* Invokes the `ANY` function on an expression.
*/
@JvmName("any")
fun <T> ExpressionWithColumnType<Array<T>>.any(): ExpressionWithColumnType<T> = anyFunc()
fun <T> ExpressionWithColumnType<List<T>>.any(): ExpressionWithColumnType<List<T>> = anyFunc()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if any of these work beyond the overlaps function. I think they are all unused as of now. The modifications are mostly to get the code to compile. If you use any of them, please test to make sure they work properly.

@AndrewWestberg AndrewWestberg merged commit c024a72 into master Nov 7, 2024
2 checks passed
@AndrewWestberg AndrewWestberg deleted the amw/STUD-366-Update-GetSongs-endpoint-to-be-able-to-sort-by-earnings-descending-ascending branch November 7, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants