added CORS
This commit is contained in:
73
source/shadowrun/ShadowrunDb.hpp
Normal file
73
source/shadowrun/ShadowrunDb.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#ifndef __SHADOWRUNDB_H__
|
||||
#define __SHADOWRUNDB_H__
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "json.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "sqlite_orm.h"
|
||||
#include "magic_enum.hpp"
|
||||
|
||||
namespace shadowrun {
|
||||
enum class Type {
|
||||
Unknown = 0,
|
||||
Info = 1,
|
||||
Attributes = 2,
|
||||
Skills = 3,
|
||||
Connections = 4,
|
||||
RangedWeapons = 5,
|
||||
MeleeWeapons = 6,
|
||||
Cyberware = 7,
|
||||
Bioware = 8,
|
||||
PositiveQualities = 9,
|
||||
NegativeQualities = 10,
|
||||
Notes = 11,
|
||||
};
|
||||
|
||||
struct ShadowrunCharacter {
|
||||
int id;
|
||||
std::string name;
|
||||
std::string created_at; // SQLite stores DATETIME as TEXT
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ShadowrunCharacter, id, name, created_at)
|
||||
|
||||
inline ShadowrunCharacter newShadowrunCharacter(const std::string& name){
|
||||
return ShadowrunCharacter {-1, name, utils::currentTime()};
|
||||
}
|
||||
|
||||
struct ShadowrunCharacterData {
|
||||
int id;
|
||||
int character_id;
|
||||
int type;
|
||||
std::string json;
|
||||
std::string created_at;
|
||||
std::string updated_at;
|
||||
};
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ShadowrunCharacterData, id, character_id, type, json, created_at, updated_at);
|
||||
|
||||
inline ShadowrunCharacterData newShadowrunCharacterData(int character_id, Type type, const std::string json){
|
||||
std::string time = utils::currentTime();
|
||||
return ShadowrunCharacterData {
|
||||
.id = -1,
|
||||
.character_id = character_id,
|
||||
.type = static_cast<int>(type),
|
||||
.json = json,
|
||||
.created_at = time,
|
||||
.updated_at = time,
|
||||
};
|
||||
}
|
||||
|
||||
int64_t createCharacter(const std::string& name);
|
||||
std::vector<ShadowrunCharacter> getCharacters();
|
||||
std::optional<ShadowrunCharacter> getChracter(int id);
|
||||
|
||||
std::vector<ShadowrunCharacterData> getChracterData(int character_id);
|
||||
int storeCharacterData(const ShadowrunCharacterData& data);
|
||||
int storeCharacterData(int characterId, const Type type, const std::string& json);
|
||||
}
|
||||
|
||||
|
||||
#endif // __SHADOWRUNDB_H__
|
||||
Reference in New Issue
Block a user