|
|
|
|
@@ -36,11 +36,12 @@ RedeemItem ReadItem(sqlite3_stmt* stmt) {
|
|
|
|
|
item.unit_label = ColText(stmt, 3);
|
|
|
|
|
item.holiday_cost = sqlite3_column_int(stmt, 4);
|
|
|
|
|
item.studyday_cost = sqlite3_column_int(stmt, 5);
|
|
|
|
|
item.is_active = sqlite3_column_int(stmt, 6) != 0;
|
|
|
|
|
item.is_global = sqlite3_column_int(stmt, 7) != 0;
|
|
|
|
|
item.created_by = sqlite3_column_int64(stmt, 8);
|
|
|
|
|
item.created_at = sqlite3_column_int64(stmt, 9);
|
|
|
|
|
item.updated_at = sqlite3_column_int64(stmt, 10);
|
|
|
|
|
item.duration_minutes = sqlite3_column_int(stmt, 6);
|
|
|
|
|
item.is_active = sqlite3_column_int(stmt, 7) != 0;
|
|
|
|
|
item.is_global = sqlite3_column_int(stmt, 8) != 0;
|
|
|
|
|
item.created_by = sqlite3_column_int64(stmt, 9);
|
|
|
|
|
item.created_at = sqlite3_column_int64(stmt, 10);
|
|
|
|
|
item.updated_at = sqlite3_column_int64(stmt, 11);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -114,10 +115,10 @@ std::vector<RedeemItem> RedeemService::ListItems(bool include_inactive) {
|
|
|
|
|
sqlite3* db = db_.raw();
|
|
|
|
|
sqlite3_stmt* stmt = nullptr;
|
|
|
|
|
const char* sql_all =
|
|
|
|
|
"SELECT id,name,description,unit_label,holiday_cost,studyday_cost,is_active,is_global,created_by,created_at,updated_at "
|
|
|
|
|
"SELECT id,name,description,unit_label,holiday_cost,studyday_cost,duration_minutes,is_active,is_global,created_by,created_at,updated_at "
|
|
|
|
|
"FROM redeem_items ORDER BY id ASC";
|
|
|
|
|
const char* sql_active =
|
|
|
|
|
"SELECT id,name,description,unit_label,holiday_cost,studyday_cost,is_active,is_global,created_by,created_at,updated_at "
|
|
|
|
|
"SELECT id,name,description,unit_label,holiday_cost,studyday_cost,duration_minutes,is_active,is_global,created_by,created_at,updated_at "
|
|
|
|
|
"FROM redeem_items WHERE is_active=1 ORDER BY id ASC";
|
|
|
|
|
CheckSqlite(sqlite3_prepare_v2(db, include_inactive ? sql_all : sql_active, -1, &stmt, nullptr),
|
|
|
|
|
db,
|
|
|
|
|
@@ -136,7 +137,7 @@ std::optional<RedeemItem> RedeemService::GetItemById(int64_t item_id) {
|
|
|
|
|
sqlite3* db = db_.raw();
|
|
|
|
|
sqlite3_stmt* stmt = nullptr;
|
|
|
|
|
const char* sql =
|
|
|
|
|
"SELECT id,name,description,unit_label,holiday_cost,studyday_cost,is_active,is_global,created_by,created_at,updated_at "
|
|
|
|
|
"SELECT id,name,description,unit_label,holiday_cost,studyday_cost,duration_minutes,is_active,is_global,created_by,created_at,updated_at "
|
|
|
|
|
"FROM redeem_items WHERE id=?";
|
|
|
|
|
CheckSqlite(sqlite3_prepare_v2(db, sql, -1, &stmt, nullptr), db,
|
|
|
|
|
"prepare get redeem item");
|
|
|
|
|
@@ -156,8 +157,8 @@ RedeemItem RedeemService::CreateItem(int64_t admin_user_id, const RedeemItemWrit
|
|
|
|
|
sqlite3_stmt* stmt = nullptr;
|
|
|
|
|
const int64_t now = NowSec();
|
|
|
|
|
const char* sql =
|
|
|
|
|
"INSERT INTO redeem_items(name,description,unit_label,holiday_cost,studyday_cost,is_active,is_global,created_by,created_at,updated_at) "
|
|
|
|
|
"VALUES(?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
|
"INSERT INTO redeem_items(name,description,unit_label,holiday_cost,studyday_cost,duration_minutes,is_active,is_global,created_by,created_at,updated_at) "
|
|
|
|
|
"VALUES(?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
|
CheckSqlite(sqlite3_prepare_v2(db, sql, -1, &stmt, nullptr), db,
|
|
|
|
|
"prepare create redeem item");
|
|
|
|
|
CheckSqlite(sqlite3_bind_text(stmt, 1, input.name.c_str(), -1, SQLITE_TRANSIENT), db,
|
|
|
|
|
@@ -168,11 +169,12 @@ RedeemItem RedeemService::CreateItem(int64_t admin_user_id, const RedeemItemWrit
|
|
|
|
|
"bind unit_label");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 4, input.holiday_cost), db, "bind holiday_cost");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 5, input.studyday_cost), db, "bind studyday_cost");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 6, input.is_active ? 1 : 0), db, "bind is_active");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 7, input.is_global ? 1 : 0), db, "bind is_global");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 8, admin_user_id), db, "bind created_by");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 9, now), db, "bind created_at");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 10, now), db, "bind updated_at");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 6, input.duration_minutes), db, "bind duration_minutes");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 7, input.is_active ? 1 : 0), db, "bind is_active");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 8, input.is_global ? 1 : 0), db, "bind is_global");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 9, admin_user_id), db, "bind created_by");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 10, now), db, "bind created_at");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 11, now), db, "bind updated_at");
|
|
|
|
|
CheckSqlite(sqlite3_step(stmt), db, "create redeem item");
|
|
|
|
|
sqlite3_finalize(stmt);
|
|
|
|
|
|
|
|
|
|
@@ -190,7 +192,7 @@ RedeemItem RedeemService::UpdateItem(int64_t item_id, const RedeemItemWrite& inp
|
|
|
|
|
const int64_t now = NowSec();
|
|
|
|
|
const char* sql =
|
|
|
|
|
"UPDATE redeem_items "
|
|
|
|
|
"SET name=?,description=?,unit_label=?,holiday_cost=?,studyday_cost=?,is_active=?,is_global=?,updated_at=? "
|
|
|
|
|
"SET name=?,description=?,unit_label=?,holiday_cost=?,studyday_cost=?,duration_minutes=?,is_active=?,is_global=?,updated_at=? "
|
|
|
|
|
"WHERE id=?";
|
|
|
|
|
CheckSqlite(sqlite3_prepare_v2(db, sql, -1, &stmt, nullptr), db,
|
|
|
|
|
"prepare update redeem item");
|
|
|
|
|
@@ -202,10 +204,11 @@ RedeemItem RedeemService::UpdateItem(int64_t item_id, const RedeemItemWrite& inp
|
|
|
|
|
"bind unit_label");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 4, input.holiday_cost), db, "bind holiday_cost");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 5, input.studyday_cost), db, "bind studyday_cost");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 6, input.is_active ? 1 : 0), db, "bind is_active");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 7, input.is_global ? 1 : 0), db, "bind is_global");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 8, now), db, "bind updated_at");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 9, item_id), db, "bind item_id");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 6, input.duration_minutes), db, "bind duration_minutes");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 7, input.is_active ? 1 : 0), db, "bind is_active");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int(stmt, 8, input.is_global ? 1 : 0), db, "bind is_global");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 9, now), db, "bind updated_at");
|
|
|
|
|
CheckSqlite(sqlite3_bind_int64(stmt, 10, item_id), db, "bind item_id");
|
|
|
|
|
CheckSqlite(sqlite3_step(stmt), db, "update redeem item");
|
|
|
|
|
sqlite3_finalize(stmt);
|
|
|
|
|
if (sqlite3_changes(db) <= 0) throw std::runtime_error("redeem item not found");
|
|
|
|
|
|