From 40a5a9730f1c065a3bec442804eea130cfd6d613 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 11 Mar 2024 13:16:59 -0500 Subject: [PATCH] Fix bio updates --- app/controllers/RobotController.scala | 36 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/app/controllers/RobotController.scala b/app/controllers/RobotController.scala index 06ac667..d2f7020 100644 --- a/app/controllers/RobotController.scala +++ b/app/controllers/RobotController.scala @@ -122,23 +122,29 @@ class RobotController @Inject()( ) }, data => { - robotsRepo.findBare(user.id, data.name)(LoggedIn(user)) flatMap { - case Some(_) => - Future successful BadRequest( - views.html.robot.update( - UpdateRobotForm.form - .fill(data) - .withGlobalError("Robot with this name already exists"), - robot, - assetsFinder - ) + val success = () => + robotsRepo.update(robot.id, data.name, data.bio, data.openSource) map { _ => + Redirect( + routes.RobotController.view(user.username, data.name) ) - case None => - robotsRepo.update(robot.id, data.name, data.bio, data.openSource) map { _ => - Redirect( - routes.RobotController.view(user.username, data.name) + } + if (data.name != robot.name) { + robotsRepo.findBare(user.id, data.name)(LoggedIn(user)) flatMap { + case Some(_) => + Future successful BadRequest( + views.html.robot.update( + UpdateRobotForm.form + .fill(data) + .withGlobalError("Robot with this name already exists"), + robot, + assetsFinder + ) ) - } + case None => + success() + } + } else { + success() } } )