feat(domain): add entities and json helpers for sqlite schema
这个提交包含在:
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace csp::domain {
|
||||
|
||||
// Notes:
|
||||
// - All *_at fields use Unix timestamp seconds (int64).
|
||||
// - id fields match SQLite INTEGER PRIMARY KEY AUTOINCREMENT (int64).
|
||||
|
||||
struct User {
|
||||
int64_t id = 0;
|
||||
std::string username;
|
||||
std::string password_salt;
|
||||
std::string password_hash;
|
||||
int32_t rating = 0;
|
||||
int64_t created_at = 0;
|
||||
};
|
||||
|
||||
struct Session {
|
||||
std::string token; // PK
|
||||
int64_t user_id = 0;
|
||||
int64_t expires_at = 0;
|
||||
int64_t created_at = 0;
|
||||
};
|
||||
|
||||
struct Problem {
|
||||
int64_t id = 0;
|
||||
std::string slug;
|
||||
std::string title;
|
||||
std::string statement_md;
|
||||
int32_t difficulty = 1;
|
||||
std::string source;
|
||||
int64_t created_at = 0;
|
||||
};
|
||||
|
||||
struct ProblemTag {
|
||||
int64_t problem_id = 0;
|
||||
std::string tag;
|
||||
};
|
||||
|
||||
enum class SubmissionStatus {
|
||||
Pending,
|
||||
Compiling,
|
||||
Running,
|
||||
AC,
|
||||
WA,
|
||||
TLE,
|
||||
MLE,
|
||||
RE,
|
||||
CE,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
// MVP: only C++ is supported.
|
||||
enum class Language {
|
||||
Cpp,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
struct Submission {
|
||||
int64_t id = 0;
|
||||
int64_t user_id = 0;
|
||||
int64_t problem_id = 0;
|
||||
Language language = Language::Cpp;
|
||||
std::string code;
|
||||
SubmissionStatus status = SubmissionStatus::Pending;
|
||||
int32_t score = 0;
|
||||
int32_t time_ms = 0;
|
||||
int32_t memory_kb = 0;
|
||||
int64_t created_at = 0;
|
||||
};
|
||||
|
||||
struct WrongBookItem {
|
||||
int64_t user_id = 0;
|
||||
int64_t problem_id = 0;
|
||||
std::optional<int64_t> last_submission_id;
|
||||
std::string note;
|
||||
int64_t updated_at = 0;
|
||||
};
|
||||
|
||||
} // namespace csp::domain
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "csp/domain/entities.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace csp::domain {
|
||||
|
||||
// String mapping for persistence/API.
|
||||
|
||||
std::string ToString(SubmissionStatus s);
|
||||
SubmissionStatus SubmissionStatusFromString(const std::string& s);
|
||||
|
||||
std::string ToString(Language l);
|
||||
Language LanguageFromString(const std::string& s);
|
||||
|
||||
} // namespace csp::domain
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "csp/domain/entities.h"
|
||||
#include "csp/domain/enum_strings.h"
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
namespace csp::domain {
|
||||
|
||||
// These helpers are intended for API responses.
|
||||
// IMPORTANT: They intentionally exclude sensitive fields (password_salt/password_hash).
|
||||
|
||||
Json::Value ToPublicJson(const User& u);
|
||||
Json::Value ToJson(const Problem& p);
|
||||
Json::Value ToJson(const Submission& s);
|
||||
Json::Value ToJson(const WrongBookItem& w);
|
||||
|
||||
} // namespace csp::domain
|
||||
在新工单中引用
屏蔽一个用户