82 lines
1.8 KiB
C++
82 lines
1.8 KiB
C++
#include "bs_util.h"
|
|
using namespace std;
|
|
|
|
int main()
|
|
{
|
|
Request req;
|
|
Session se(req);
|
|
Response res;
|
|
json j;
|
|
|
|
auto jsonfail=[&](int errcode,const std::string& dtl="")
|
|
{
|
|
jsonfail_func(j,errcode,dtl);
|
|
};
|
|
|
|
do
|
|
{
|
|
if(!se.isReady())
|
|
{
|
|
jsonfail(err_session);
|
|
break;
|
|
}
|
|
|
|
if(se.getUser().empty())
|
|
{
|
|
jsonfail(err_need_login);
|
|
break;
|
|
}
|
|
|
|
if(req.requestMethod!="POST")
|
|
{
|
|
jsonfail(err_method_not_supported);
|
|
break;
|
|
}
|
|
|
|
postval(id);
|
|
|
|
int id_real=ParseInt(id);
|
|
if(id_real<0)
|
|
{
|
|
jsonfail(err_parameter,"Failed to Parse ID");
|
|
break;
|
|
}
|
|
|
|
startdb();
|
|
|
|
if(conn.exec("set names utf8",nullptr)<0)
|
|
{
|
|
jsonfail(err_sql,"Failed to set names");
|
|
break;
|
|
}
|
|
|
|
if(conn.exec(make_str("select book_id,position,status from bs_bookstatus where class_id=",id_real),
|
|
[&](MySQLResult& res)
|
|
{
|
|
res.stepRow([&](char** val,unsigned long* len)
|
|
{
|
|
json x;
|
|
x["obj_id"]=string(val[0]);
|
|
x["book_pos"]=string(len[1]>0?val[1]:"");
|
|
x["book_status"]=string(val[2]);
|
|
|
|
j["result"].push_back(x);
|
|
});
|
|
})<0)
|
|
{
|
|
jsonfail(err_sql,"Step 1");
|
|
break;
|
|
}
|
|
|
|
j["success"]=1;
|
|
}
|
|
while(0);
|
|
|
|
se.writeToResponse(res);
|
|
res.content.append(j.dump());
|
|
|
|
return 0;
|
|
}
|
|
|
|
|