feat: change message api to one interface
This commit is contained in:
52
L2BotCore/Domain/DTO/Message.h
Normal file
52
L2BotCore/Domain/DTO/Message.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include "../Entities/EntityInterface.h"
|
||||
#include "../Enums/EntityStateEnum.h"
|
||||
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
class Message : public Serializers::Serializable
|
||||
{
|
||||
public:
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
std::wstring operation = L"none";
|
||||
switch (m_Operation)
|
||||
{
|
||||
case Enums::EntityStateEnum::created:
|
||||
operation = L"create";
|
||||
break;
|
||||
case Enums::EntityStateEnum::updated:
|
||||
operation = L"update";
|
||||
break;
|
||||
case Enums::EntityStateEnum::deleted:
|
||||
operation = L"delete";
|
||||
}
|
||||
|
||||
return
|
||||
{
|
||||
Serializers::Node{ L"type", m_Type },
|
||||
Serializers::Node{ L"operation", operation },
|
||||
Serializers::Node{L"content", m_Content.BuildSerializationNodes()}
|
||||
};
|
||||
}
|
||||
|
||||
Message(const std::wstring& type, const Enums::EntityStateEnum operation, const Serializers::Serializable& content) :
|
||||
m_Type(type),
|
||||
m_Operation(operation),
|
||||
m_Content(content)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Message() = default;
|
||||
virtual ~Message() = default;
|
||||
private:
|
||||
const std::wstring m_Type;
|
||||
const Enums::EntityStateEnum m_Operation;
|
||||
const Serializers::Serializable& m_Content;
|
||||
};
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "../DTO/EntityState.h"
|
||||
#include "Serializable.h"
|
||||
|
||||
namespace L2Bot::Domain::Serializers
|
||||
{
|
||||
class SerializableStateContainer : public Serializers::Serializable
|
||||
{
|
||||
public:
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
std::vector<Serializers::Node> result;
|
||||
|
||||
for (const auto& kvp : m_Objects)
|
||||
{
|
||||
std::wstring operationName = L"";
|
||||
switch (kvp->GetState())
|
||||
{
|
||||
case Enums::EntityStateEnum::created:
|
||||
operationName = L"created";
|
||||
break;
|
||||
case Enums::EntityStateEnum::updated:
|
||||
operationName = L"updated";
|
||||
break;
|
||||
case Enums::EntityStateEnum::deleted:
|
||||
operationName = L"deleted";
|
||||
break;
|
||||
}
|
||||
|
||||
if (operationName != L"")
|
||||
{
|
||||
result.push_back(
|
||||
{
|
||||
m_ContainerName,
|
||||
std::vector<Serializers::Node>{ { operationName, kvp->GetEntity()->BuildSerializationNodes() } }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SerializableStateContainer(const std::vector<std::shared_ptr<DTO::EntityState>> objects, const std::wstring& containerName) :
|
||||
m_Objects(objects), m_ContainerName(containerName)
|
||||
{
|
||||
|
||||
}
|
||||
SerializableStateContainer() = delete;
|
||||
virtual ~SerializableStateContainer() = default;
|
||||
private:
|
||||
const std::vector<std::shared_ptr<DTO::EntityState>> m_Objects;
|
||||
const std::wstring m_ContainerName;
|
||||
};
|
||||
}
|
@@ -160,6 +160,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Domain\DTO\EntityState.h" />
|
||||
<ClInclude Include="Domain\DTO\Message.h" />
|
||||
<ClInclude Include="Domain\Entities\AbnormalEffect.h" />
|
||||
<ClInclude Include="Domain\Entities\ArmorItem.h" />
|
||||
<ClInclude Include="Domain\Entities\EntityInterface.h" />
|
||||
@@ -195,7 +196,6 @@
|
||||
<ClInclude Include="Domain\ValueObjects\ExperienceInfo.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\FullName.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\InventoryInfo.h" />
|
||||
<ClInclude Include="Domain\Serializers\SerializableStateContainer.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\PermanentStats.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\Phenotype.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\Reputation.h" />
|
||||
|
@@ -90,9 +90,6 @@
|
||||
<ClInclude Include="Domain\Serializers\Node.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Serializers\SerializableStateContainer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Transports\TransportInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -150,6 +147,9 @@
|
||||
<ClInclude Include="Domain\Repositories\ChatMessageRepositoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\Message.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
|
Reference in New Issue
Block a user