Skip to content

Commit

Permalink
fix: add sort on followed episodes and group follow date
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Sep 5, 2024
1 parent 10ba826 commit 9a6ca9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ class MemberFollowEpisodeRepository : AbstractRepository<MemberFollowEpisode>()
cb.equal(root[MemberFollowEpisode_.member], member)
)

query.orderBy(cb.desc(root[MemberFollowEpisode_.followDateTime]))
query.orderBy(
cb.desc(root[MemberFollowEpisode_.followDateTime]),
cb.desc(root[MemberFollowEpisode_.episode][EpisodeMapping_.anime]),
cb.desc(root[MemberFollowEpisode_.episode][EpisodeMapping_.season]),
cb.desc(root[MemberFollowEpisode_.episode][EpisodeMapping_.episodeType]),
cb.desc(root[MemberFollowEpisode_.episode][EpisodeMapping_.number]),
)

buildPageableQuery(createReadOnlyQuery(it, query), page, limit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ class MemberFollowEpisodeService : AbstractService<MemberFollowEpisode, MemberFo
val elements = episodeMappingService.findAllByAnime(animeService.find(anime.uuid) ?: return Response.notFound())
.filter { it.episodeType != EpisodeType.SUMMARY }
val followed = memberFollowEpisodeRepository.findAllFollowedEpisodesByMemberAndEpisodes(member, elements)
val now = ZonedDateTime.now()

val filtered = elements.mapNotNull { element ->
if (element.uuid in followed) return@mapNotNull null
MemberFollowEpisode(member = member, episode = element)
MemberFollowEpisode(followDateTime = now, member = member, episode = element)
}

memberFollowEpisodeRepository.saveAll(filtered)
Expand Down

0 comments on commit 9a6ca9f

Please sign in to comment.