Extracted user management
This commit is contained in:
@@ -16,10 +16,15 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/Http/Request.h>
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "services/database/Types.hpp"
|
||||
#include "utils/String.hpp"
|
||||
#include "SubsonicResponse.hpp"
|
||||
@@ -28,8 +33,7 @@ namespace API::Subsonic
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
std::vector<T>
|
||||
getMultiParametersAs(const Wt::Http::ParameterMap& parameterMap, const std::string& paramName)
|
||||
std::vector<T> getMultiParametersAs(const Wt::Http::ParameterMap& parameterMap, const std::string& paramName)
|
||||
{
|
||||
std::vector<T> res;
|
||||
|
||||
@@ -39,7 +43,7 @@ namespace API::Subsonic
|
||||
|
||||
for (const std::string& param : it->second)
|
||||
{
|
||||
auto value {StringUtils::readAs<T>(param)};
|
||||
auto value{ StringUtils::readAs<T>(param) };
|
||||
if (value)
|
||||
res.emplace_back(std::move(*value));
|
||||
}
|
||||
@@ -48,44 +52,37 @@ namespace API::Subsonic
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<T>
|
||||
getMandatoryMultiParametersAs(const Wt::Http::ParameterMap& parameterMap, const std::string& param)
|
||||
std::vector<T> getMandatoryMultiParametersAs(const Wt::Http::ParameterMap& parameterMap, const std::string& param)
|
||||
{
|
||||
std::vector<T> res {getMultiParametersAs<T>(parameterMap, param)};
|
||||
std::vector<T> res{ getMultiParametersAs<T>(parameterMap, param) };
|
||||
if (res.empty())
|
||||
throw RequiredParameterMissingError {param};
|
||||
throw RequiredParameterMissingError{ param };
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T>
|
||||
getParameterAs(const Wt::Http::ParameterMap& parameterMap, const std::string& param)
|
||||
std::optional<T> getParameterAs(const Wt::Http::ParameterMap& parameterMap, const std::string& param)
|
||||
{
|
||||
std::vector<T> params {getMultiParametersAs<T>(parameterMap, param)};
|
||||
std::vector<T> params{ getMultiParametersAs<T>(parameterMap, param) };
|
||||
|
||||
if (params.size() != 1)
|
||||
return std::nullopt;
|
||||
|
||||
return T { std::move(params.front()) };
|
||||
return T{ std::move(params.front()) };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
getMandatoryParameterAs(const Wt::Http::ParameterMap& parameterMap, const std::string& param)
|
||||
T getMandatoryParameterAs(const Wt::Http::ParameterMap& parameterMap, const std::string& param)
|
||||
{
|
||||
auto res {getParameterAs<T>(parameterMap, param)};
|
||||
auto res{ getParameterAs<T>(parameterMap, param) };
|
||||
if (!res)
|
||||
throw RequiredParameterMissingError {param};
|
||||
throw RequiredParameterMissingError{ param };
|
||||
|
||||
return *res;
|
||||
}
|
||||
|
||||
inline
|
||||
bool
|
||||
hasParameter(const Wt::Http::ParameterMap& parameterMap, const std::string& param)
|
||||
{
|
||||
return parameterMap.find(param) != std::cend(parameterMap);
|
||||
}
|
||||
bool hasParameter(const Wt::Http::ParameterMap& parameterMap, const std::string& param);
|
||||
std::string decodePasswordIfNeeded(const std::string& password);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user