model = $model; } public function updateName(int $tactic_id, Account $account): HttpResponse { return Control::runChecked([ "name" => [Validators::lenBetween(1, 50), Validators::nameWithSpaces()], ], function (HttpRequest $request) use ($tactic_id, $account) { $failures = $this->model->updateName($tactic_id, $request["name"], $account->getId()); if (!empty($failures)) { //TODO find a system to handle Unauthorized error codes more easily from failures. return new JsonHttpResponse($failures, HttpCodes::BAD_REQUEST); } return HttpResponse::fromCode(HttpCodes::OK); }, true); } public function newTactic(Account $account): HttpResponse { return Control::runChecked([ "name" => [Validators::lenBetween(1, 50), Validators::nameWithSpaces()], ], function (HttpRequest $request) use ($account) { $tactic = $this->model->makeNew($request["name"], $account->getId()); $id = $tactic->getId(); return new JsonHttpResponse(["id" => $id]); }, true); } public function getTacticInfo(int $id, Account $account): HttpResponse { $tactic_info = $this->model->get($id); if ($tactic_info == null) { return new JsonHttpResponse("could not find tactic #$id", HttpCodes::NOT_FOUND); } return new JsonHttpResponse($tactic_info); } }