[Refactor] Encapsulate hostname query in MachineRepository.

This commit is contained in:
Ritchie Cunningham 2025-10-10 20:22:15 +01:00
parent 2a50d937ea
commit 3234ef7b3b
3 changed files with 10 additions and 4 deletions

View File

@ -30,3 +30,11 @@ std::vector<MachineData> MachineRepository::get_all_npcs(void) {
};
return machines;
}
std::string MachineRepository::get_hostname(long long machine_id) {
std::string hostname;
_db << "SELECT hostname FROM machines WHERE id = ?;"
<< machine_id
>> hostname;
return hostname;
}

View File

@ -19,6 +19,7 @@ public:
const std::string& ip_address);
int get_npc_count(void);
std::vector<MachineData> get_all_npcs(void);
std::string get_hostname(long long machine_id);
private:
sqlite::database& _db;

View File

@ -98,11 +98,8 @@ void build_tree(vfs_node* parent, const std::map<long long, vfs_node*>& nodes) {
Machine* MachineManager::load_machine(long long machine_id, DatabaseManager* db_manager) {
printf("DEBUG: load_machine called for machine_id: %lld\n", machine_id);
std::string hostname;
db_manager->_db << "SELECT hostname FROM machines WHERE id = ?;"
<< machine_id
>> hostname;
std::string hostname = _db_manager->machines().get_hostname(machine_id);
Machine* machine = new Machine(machine_id, hostname);