redirect to last chapter after importing a game into a study
parent
300259161c
commit
d7b8712ba8
|
@ -292,7 +292,7 @@ final class Study(
|
|||
) =
|
||||
env.study.api.importGame(lila.study.StudyMaker.ImportGame(data), me) flatMap {
|
||||
_.fold(notFound) { sc =>
|
||||
Redirect(routes.Study.show(sc.study.id.value)).fuccess
|
||||
Redirect(routes.Study.chapter(sc.study.id.value, sc.chapter.id.value)).fuccess
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ final class ChapterRepo(val coll: AsyncColl)(implicit
|
|||
def firstByStudy(studyId: Study.Id): Fu[Option[Chapter]] =
|
||||
coll(_.find($studyId(studyId)).sort($sort asc "order").one[Chapter])
|
||||
|
||||
private[study] def lastByStudy(studyId: Study.Id): Fu[Option[Chapter]] =
|
||||
coll(_.find($studyId(studyId)).sort($sort desc "order").one[Chapter])
|
||||
|
||||
def existsByStudy(studyId: Study.Id): Fu[Boolean] =
|
||||
coll(_ exists $studyId(studyId))
|
||||
|
||||
|
|
|
@ -76,9 +76,18 @@ final class StudyApi(
|
|||
}
|
||||
|
||||
def byIdWithFirstChapter(id: Study.Id): Fu[Option[Study.WithChapter]] =
|
||||
byIdWithChapterFinder(id, chapterRepo firstByStudy id)
|
||||
|
||||
private[study] def byIdWithLastChapter(id: Study.Id): Fu[Option[Study.WithChapter]] =
|
||||
byIdWithChapterFinder(id, chapterRepo lastByStudy id)
|
||||
|
||||
private def byIdWithChapterFinder(
|
||||
id: Study.Id,
|
||||
chapterFinder: => Fu[Option[Chapter]]
|
||||
): Fu[Option[Study.WithChapter]] =
|
||||
byId(id) flatMap {
|
||||
_ ?? { study =>
|
||||
chapterRepo.firstByStudy(study.id) map {
|
||||
chapterFinder map {
|
||||
_ ?? { Study.WithChapter(study, _).some }
|
||||
} orElse byIdWithChapter(id)
|
||||
}
|
||||
|
@ -112,7 +121,7 @@ final class StudyApi(
|
|||
studyId = study.id,
|
||||
data = data.form.toChapterData,
|
||||
sticky = study.settings.sticky
|
||||
)(Who(user.id, Sri(""))) >> byIdWithChapter(studyId)
|
||||
)(Who(user.id, Sri(""))) >> byIdWithLastChapter(studyId)
|
||||
case _ => fuccess(none)
|
||||
} orElse importGame(data.copy(form = data.form.copy(asStr = none)), user)
|
||||
}) addEffect {
|
||||
|
|
Loading…
Reference in New Issue