refactor: remove unnecessary classes
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "../Repositories/ChatMessageRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class ChatMessageHandler
|
||||
{
|
||||
public:
|
||||
ChatMessageHandler(Repositories::ChatMessageRepositoryInterface& repository) : m_Repository(repository)
|
||||
{
|
||||
|
||||
}
|
||||
ChatMessageHandler() = delete;
|
||||
virtual ~ChatMessageHandler() = default;
|
||||
|
||||
virtual const std::vector<ValueObjects::ChatMessage> GetMessages()
|
||||
{
|
||||
return m_Repository.GetMessages();
|
||||
}
|
||||
private:
|
||||
Repositories::ChatMessageRepositoryInterface& m_Repository;
|
||||
};
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include "../DTO/EntityState.h"
|
||||
#include "../Entities/WorldObject.h"
|
||||
#include "../Repositories/EntityRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class EntityHandler
|
||||
{
|
||||
public:
|
||||
EntityHandler(Repositories::EntityRepositoryInterface& repository) : m_Repository(repository)
|
||||
{
|
||||
|
||||
}
|
||||
EntityHandler() = delete;
|
||||
virtual ~EntityHandler() = default;
|
||||
|
||||
virtual const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities()
|
||||
{
|
||||
return m_Repository.GetEntities();
|
||||
}
|
||||
|
||||
void Invalidate()
|
||||
{
|
||||
m_Repository.Reset();
|
||||
}
|
||||
private:
|
||||
Repositories::EntityRepositoryInterface& m_Repository;
|
||||
};
|
||||
}
|
61
L2BotCore/Domain/Services/UnitOfWork.h
Normal file
61
L2BotCore/Domain/Services/UnitOfWork.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include "../Entities/EntityInterface.h"
|
||||
#include "../Enums/EntityStateEnum.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class UnitOfWork
|
||||
{
|
||||
public:
|
||||
const std::unordered_map<uint32_t, Enums::EntityStateEnum> ConnectEntities(const std::wstring& name, const std::unordered_map<uint32_t, std::shared_ptr<Entities::EntityInterface>>& entites)
|
||||
{
|
||||
std::unordered_map<uint32_t, Enums::EntityStateEnum> result;
|
||||
|
||||
auto& hashes = m_Hashes[name];
|
||||
|
||||
for (const auto& kvp : entites) {
|
||||
const auto &entity = kvp.second;
|
||||
|
||||
if (hashes.size() == 0) {
|
||||
result[entity->GetId()] = Enums::EntityStateEnum::created;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hashes.find(entity->GetId()) == hashes.end()) {
|
||||
result[entity->GetId()] = Enums::EntityStateEnum::created;
|
||||
}
|
||||
else if (hashes[entity->GetId()] != entity->GetHash()) {
|
||||
result[entity->GetId()] = Enums::EntityStateEnum::updated;
|
||||
}
|
||||
}
|
||||
|
||||
hashes[entity->GetId()] = entity->GetHash();
|
||||
}
|
||||
|
||||
|
||||
for (auto it = hashes.begin(); it != hashes.end();)
|
||||
{
|
||||
if (entites.find(it->first) == entites.end())
|
||||
{
|
||||
result[it->first] = Enums::EntityStateEnum::deleted;
|
||||
it = hashes.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map <std::wstring, std::unordered_map<uint32_t, size_t>> m_Hashes;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user