Isolated ResponseFormat in a new file

This commit is contained in:
emeric
2024-11-29 21:37:38 +01:00
parent e3a94d0540
commit 13a0aab09c
8 changed files with 80 additions and 25 deletions
+1 -1
View File
@@ -27,7 +27,7 @@
#include "ClientInfo.hpp"
#include "ProtocolVersion.hpp"
#include "SubsonicResponse.hpp"
#include "ResponseFormat.hpp"
namespace lms::db
{
+38
View File
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2024 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ResponseFormat.hpp"
#include <string_view>
namespace lms::api::subsonic
{
std::string_view ResponseFormatToMimeType(ResponseFormat format)
{
switch (format)
{
case ResponseFormat::xml:
return "text/xml";
case ResponseFormat::json:
return "application/json";
}
return "";
}
} // namespace lms::api::subsonic
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2024 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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 <string_view>
namespace lms::api::subsonic
{
enum class ResponseFormat
{
xml,
json,
};
std::string_view ResponseFormatToMimeType(ResponseFormat format);
} // namespace lms::api::subsonic
@@ -32,19 +32,6 @@
namespace lms::api::subsonic
{
std::string_view ResponseFormatToMimeType(ResponseFormat format)
{
switch (format)
{
case ResponseFormat::xml:
return "text/xml";
case ResponseFormat::json:
return "application/json";
}
return "";
}
void Response::Node::setValue(std::string_view value)
{
assert(_children.empty() && _childrenArrays.empty() && _childrenValues.empty());
+3 -10
View File
@@ -28,6 +28,7 @@
#include "core/LiteralString.hpp"
#include "ProtocolVersion.hpp"
#include "ResponseFormat.hpp"
#include "SubsonicResponseAllocator.hpp"
namespace lms::api::subsonic
@@ -35,14 +36,6 @@ namespace lms::api::subsonic
// Max count expected from all API methods that expose a count
static inline constexpr std::size_t defaultMaxCountSize{ 1'000 };
enum class ResponseFormat
{
xml,
json,
};
std::string_view ResponseFormatToMimeType(ResponseFormat format);
class Error
{
public:
@@ -244,7 +237,7 @@ namespace lms::api::subsonic
std::size_t _max;
};
class Response
class Response final
{
public:
class Node
@@ -306,7 +299,7 @@ namespace lms::api::subsonic
static Response createOkResponse(ProtocolVersion protocolVersion);
static Response createFailedResponse(ProtocolVersion protocolVersion, const Error& error);
virtual ~Response() {}
~Response() = default;
Response(const Response&) = delete;
Response& operator=(const Response&) = delete;
Response(Response&&) = default;
@@ -36,6 +36,7 @@
#include "services/artwork/IArtworkService.hpp"
#include "ParameterParsing.hpp"
#include "RequestContext.hpp"
#include "SubsonicId.hpp"
#include "responses/Lyrics.hpp"
@@ -22,10 +22,12 @@
#include <Wt/Http/Request.h>
#include <Wt/Http/Response.h>
#include "RequestContext.hpp"
#include "SubsonicResponse.hpp"
namespace lms::api::subsonic
{
class RequestContext;
Response handleGetLyrics(RequestContext& context);
Response handleGetLyricsBySongId(RequestContext& context);