/** * @param $username * @return bool */ public function addAction($username) { $user = User::findFirst([['username' => $username]]); if ($user) { return $this->succeed(['message' => 'User already exists.']); } $user = new User(); $user->username = $username; if ($user->save()) { return $this->succeed(); } else { return $this->fail(['message' => 'Error saving to Database.']); } }
/** * @param $username * @return bool */ public function listAction($username) { // Get User /** @var User $user */ $user = User::findFirst([['username' => $username]]); if (!$user) { return $this->fail(['message' => "User doesn't exist."]); } return $this->succeed($user->getNewsSourcesInfo()); }