Skip to content

Commit

Permalink
tweak student move controller code, no functional change
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 18, 2024
1 parent 8ce3307 commit f56652d
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions app/controllers/Clas.scala
Original file line number Diff line number Diff line change
Expand Up @@ -475,18 +475,21 @@ final class Clas(env: Env, authC: Auth) extends LilaController(env):
def studentMove(id: ClasId, username: UserStr) = Secure(_.Teacher) { ctx ?=> me ?=>
WithClassAndStudents(id): (clas, students) =>
WithStudent(clas, username): s =>
WithMyOtherClasses(clas): classes =>
Ok.page(views.clas.student.move(clas, students, s, classes))
for
classes <- env.clas.api.clas.of(me)
others = classes.filter(_.id != clas.id)
res <- Ok.page(views.clas.student.move(clas, students, s, others))
yield res
}

def studentMovePost(id: ClasId, username: UserStr, to: ClasId) = SecureBody(_.Teacher) { ctx ?=> me ?=>
WithClassAndStudents(id): (clas, students) =>
WithStudent(clas, username): s =>
WithClass(to): toClas =>
(env.clas.api.student
.createCopy(toClas, s, me) >>
env.clas.api.student.closeAccount(s))
.inject(Redirect(routes.Clas.show(clas.id)))
for
_ <- env.clas.api.student.createCopy(toClas, s, me)
_ <- env.clas.api.student.closeAccount(s)
yield Redirect(routes.Clas.show(clas.id))
}

def becomeTeacher = AuthBody { ctx ?=> me ?=>
Expand Down Expand Up @@ -540,14 +543,6 @@ final class Clas(env: Env, authC: Auth) extends LilaController(env):
WithClass(clasId): c =>
env.clas.api.student.activeOf(c).flatMap { f(c, _) }

private def WithMyOtherClasses(clas: lila.clas.Clas)(
f: (List[lila.clas.Clas]) => Fu[Result]
)(using teacher: Me): Fu[Result] =
val res =
for classes <- env.clas.api.clas.of(teacher)
yield classes.filter(_.id != clas.id)
res.flatMap(f)

private def WithStudent(clas: lila.clas.Clas, username: UserStr)(
f: lila.clas.Student.WithUser => Fu[Result]
)(using Context): Fu[Result] =
Expand Down

0 comments on commit f56652d

Please sign in to comment.