chatgpt wrote the database layer for me
This commit is contained in:
@@ -1 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <clickhouse/client.h>
|
||||
#include "skwyward-api-utils.hpp"
|
||||
|
||||
namespace database_utils {
|
||||
|
||||
// ---------- DB Handle ----------
|
||||
|
||||
using CHClient = std::shared_ptr<clickhouse::Client>;
|
||||
|
||||
// ---------- User ----------
|
||||
|
||||
struct UserRecord {
|
||||
std::string user_id; // UUID
|
||||
api_utils::Login login;
|
||||
};
|
||||
|
||||
// ---------- Snapshot ----------
|
||||
|
||||
struct GradeSnapshot {
|
||||
std::string response_id;
|
||||
api_utils::GradesResponse response;
|
||||
};
|
||||
|
||||
// ---------- Assignment Diff ----------
|
||||
|
||||
struct AssignmentDiff {
|
||||
std::string class_grade_id;
|
||||
std::string assignment_id;
|
||||
|
||||
std::optional<api_utils::AssignmentGrade> old_grade;
|
||||
api_utils::AssignmentGrade new_grade;
|
||||
};
|
||||
|
||||
// ---------- User ops ----------
|
||||
|
||||
std::vector<UserRecord>
|
||||
get_all_users(const CHClient& client);
|
||||
|
||||
bool
|
||||
register_user(
|
||||
const CHClient& client,
|
||||
const std::string& username,
|
||||
const std::string& password
|
||||
);
|
||||
|
||||
bool
|
||||
authenticate_user(
|
||||
const CHClient& client,
|
||||
const std::string& username,
|
||||
const std::string& password
|
||||
);
|
||||
|
||||
// ---------- Grades ----------
|
||||
|
||||
std::optional<GradeSnapshot>
|
||||
load_latest_grades(
|
||||
const CHClient& client,
|
||||
const std::string& user_id
|
||||
);
|
||||
|
||||
// ---------- Diff ----------
|
||||
|
||||
std::vector<AssignmentDiff>
|
||||
diff_grade_responses(
|
||||
const api_utils::GradesResponse& old_resp,
|
||||
const api_utils::GradesResponse& new_resp
|
||||
);
|
||||
|
||||
// ---------- Conditional insert ----------
|
||||
|
||||
bool
|
||||
conditionally_insert_grades(
|
||||
const CHClient& client,
|
||||
const std::string& user_id,
|
||||
const api_utils::GradesResponse& new_resp
|
||||
);
|
||||
|
||||
// ---------- Persist diffs ----------
|
||||
|
||||
void
|
||||
insert_grade_updates(
|
||||
const CHClient& client,
|
||||
const std::string& user_id,
|
||||
const std::string& old_response_id,
|
||||
const std::string& new_response_id,
|
||||
const std::vector<AssignmentDiff>& diffs
|
||||
);
|
||||
|
||||
} // namespace database_utils
|
||||
|
||||
|
||||
Reference in New Issue
Block a user