Pushed work

master
Kirigaya Kazuto 2017-12-28 18:18:44 +08:00
parent f792c9bc19
commit 445f088cda
43 changed files with 1742 additions and 99 deletions

View File

@ -60,8 +60,13 @@
<Unit filename="MySQLWrapper/MySQLWrapper.h" />
<Unit filename="bs_util.cpp" />
<Unit filename="bs_util.h" />
<Unit filename="handler.h" />
<Unit filename="jsonfail.cpp" />
<Unit filename="jsonfail.h" />
<Unit filename="main.cpp" />
<Unit filename="src/BookSearch.cpp" />
<Unit filename="src/bs_src_util.cpp" />
<Unit filename="src/bs_src_util.h" />
<Extensions>
<code_completion />
<envvars />

View File

@ -1,16 +1,13 @@
# depslib dependency file v1.0
1511504972 source:d:\codeblocks_codes\dbhomework\main.cpp
"Session.h"
"Util.h"
"jsonfail.h"
"json.hpp"
"MySQLTransaction.h"
1513923375 source:d:\codeblocks_codes\dbhomework\main.cpp
"bs_util.h"
"handler.h"
1511076615 d:\codeblocks_codes\dbhomework\mysqlwrapper\mysqlwrapper.h
<functional>
<string>
1511877230 source:d:\codeblocks_codes\dbhomework\mysqlwrapper\mysqlwrapper.cpp
1513907451 source:d:\codeblocks_codes\dbhomework\mysqlwrapper\mysqlwrapper.cpp
"MySQLWrapper.h"
"MySQLInclude.h"
<string>
@ -110,13 +107,13 @@
<string>
"CookieVec.h"
1511686368 source:d:\codeblocks_codes\dbhomework\httpwrapper\util.cpp
1513919601 source:d:\codeblocks_codes\dbhomework\httpwrapper\util.cpp
"Util.h"
<fstream>
<sstream>
<cstdio>
1511689007 d:\codeblocks_codes\dbhomework\httpwrapper\util.h
1513919626 d:\codeblocks_codes\dbhomework\httpwrapper\util.h
<string>
<sstream>
"Response.h"
@ -351,7 +348,7 @@
1511939814 source:d:\codeblocks_codes\dbhomework\bs_util.cpp
"bs_util.h"
1512014783 d:\codeblocks_codes\dbhomework\\bs_util.h
1513855513 d:\codeblocks_codes\dbhomework\\bs_util.h
"Request.h"
"Response.h"
"Session.h"
@ -359,7 +356,7 @@
"jsonfail.h"
"Util.h"
1512014783 d:\codeblocks_codes\dbhomework\bs_util.h
1513855513 d:\codeblocks_codes\dbhomework\bs_util.h
"Request.h"
"Response.h"
"Session.h"
@ -387,3 +384,28 @@
"bs_util.h"
"MySQLTransaction.h"
1513848624 source:d:\codeblocks_codes\dbhomework\src\main.cpp
"bs_util.h"
1513919020 d:\codeblocks_codes\dbhomework\handler.h
"bs_util.h"
1513924533 source:d:\codeblocks_codes\dbhomework\src\booksearch.cpp
"handler.h"
"MySQLTransaction.h"
1513919020 d:\codeblocks_codes\dbhomework\\handler.h
"bs_util.h"
1513850958 source:d:\codeblocks_codes\dbhomework\src\bs_src_util.cpp
1514456083 d:\codeblocks_codes\dbhomework\mysqlwrapper\include\mysqlwrapper.h
<functional>
<string>
1514456083 d:\codeblocks_codes\dbhomework\mysqlwrapper\include\mysqltransaction.h
"MySQLWrapper.h"
1514456083 source:d:\codeblocks_codes\dbhomework\mysqlwrapper\src\mysqltransaction.cpp
"MySQLTransaction.h"

View File

@ -2,94 +2,119 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="HTTPWrapper\Response.cpp" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="858" topLine="27" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLWrapper.cpp" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1894" topLine="81" />
</Cursor>
</File>
<File name="HTTPWrapper\Session_MySQL.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="2533" topLine="95" />
</Cursor>
</File>
<File name="jsonfail.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="366" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Singleton.hpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="217" topLine="27" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLTransaction.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="536" topLine="19" />
</Cursor>
</File>
<File name="bs_util.cpp" open="1" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1534" topLine="54" />
</Cursor>
</File>
<File name="HTTPWrapper\CookieVec.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2194" topLine="0" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLWrapper.h" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="556" topLine="26" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLTransaction.h" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="506" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Util.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2712" topLine="118" />
</Cursor>
</File>
<File name="HTTPWrapper\Request.cpp" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
<Cursor>
<Cursor1 position="369" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Request.h" open="1" top="1" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="472" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Response.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="292" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Session.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="745" topLine="3" />
</Cursor>
</File>
<File name="HTTPWrapper\Util.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1586" topLine="0" />
</Cursor>
</File>
<File name="bs_util.h" open="1" top="0" tabpos="16" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="29" topLine="0" />
</Cursor>
</File>
<File name="jsonfail.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="559" topLine="0" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLWrapper.cpp" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1849" topLine="80" />
</Cursor>
</File>
<File name="HTTPWrapper\CookieVec.h" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2194" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Session_MySQL.cpp" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="1693" topLine="0" />
</Cursor>
</File>
<File name="src\bs_src_util.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<Cursor>
<Cursor1 position="14" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Session.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="120" topLine="10" />
</Cursor>
</File>
<File name="bs_util.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="208" topLine="0" />
</Cursor>
</File>
<File name="jsonfail.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="364" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Util.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="419" topLine="12" />
</Cursor>
</File>
<File name="src\bs_src_util.cpp" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Response.cpp" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="858" topLine="0" />
</Cursor>
</File>
<File name="handler.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="530" topLine="0" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLTransaction.h" open="0" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="506" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Util.cpp" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="563" topLine="10" />
</Cursor>
</File>
<File name="HTTPWrapper\Request.cpp" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
<Cursor>
<Cursor1 position="369" topLine="0" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLWrapper.h" open="0" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="556" topLine="26" />
</Cursor>
</File>
<File name="bs_util.cpp" open="0" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1732" topLine="56" />
</Cursor>
</File>
<File name="HTTPWrapper\Request.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="71" topLine="4" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2340" topLine="82" />
</Cursor>
</File>
<File name="HTTPWrapper\Response.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="292" topLine="0" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLTransaction.cpp" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="536" topLine="19" />
</Cursor>
</File>
<File name="src\BookSearch.cpp" open="1" top="1" tabpos="7" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="39511" topLine="1366" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -1 +1 @@
Subproject commit af77d51fd8071cd598c94ab8a49a632f5ccdca8d
Subproject commit 1c9bcf0652270e8e63dbc8cd162f5c3c335aa496

@ -1 +1 @@
Subproject commit 621ef36565bd0d262437e879a833ae3a5c59cd0d
Subproject commit 860678048e84d31004ba4020040d9f199c1821c5

View File

@ -18,5 +18,6 @@ int getPermissionLevel(const std::string& Username,Response& res);
std::function<void(MySQLResult&)> SQLParseInt(int& nval);
#define postval(NAME) if(req.post[#NAME].empty()){jsonfail(err_missing_parameter);break;}string NAME=req.post[#NAME]
#define default_jsonfail() auto jsonfail=[&](int errcode,const std::string& dtl=""){jsonfail_func(j,errcode,dtl);}
#define postval(NAME) if(req.post[#NAME].empty()){jsonfail(err_missing_parameter,#NAME);break;}string NAME=req.post[#NAME]
#define startdb() DBInfo db;if(db.readConfig()<0){jsonfail(err_config);break;} MySQLConn conn;if(db.connectProxy(conn)<0){jsonfail(err_connect);break;}if(conn.exec("set names utf8",nullptr)<0){jsonfail(err_sql,"Failed to set names");break;}

42
code_template_1.txt Normal file
View File

@ -0,0 +1,42 @@
#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(req.requestMethod!="POST")
{
jsonfail(err_method_not_supported);
break;
}
startdb();
}
while(0);
se.writeToResponse(res);
res.content.append(j.dump());
return 0;
}

38
handler.h Normal file
View File

@ -0,0 +1,38 @@
#pragma once
#include "bs_util.h"
#define DECL_HANDLER(fname) extern void fname(Request& req,Session& se,Response& res,json& j)
DECL_HANDLER(UserLogin);
DECL_HANDLER(UserLogout);
DECL_HANDLER(CheckLogin);
DECL_HANDLER(CheckLoginX);
DECL_HANDLER(UserReaderAdd);
DECL_HANDLER(UserReaderEdit);
DECL_HANDLER(UserReaderRemove);
DECL_HANDLER(UserSearch);
DECL_HANDLER(UserReaderGet);
DECL_HANDLER(UserReaderGetLow);
DECL_HANDLER(BookAdd);
DECL_HANDLER(BookEdit);
DECL_HANDLER(BookRemove);
DECL_HANDLER(BookObjAdd);
DECL_HANDLER(BookObjEdit);
DECL_HANDLER(BookObjRemove);
DECL_HANDLER(BookTypeGet);
DECL_HANDLER(BookTypeAdd);
DECL_HANDLER(BookTypeEdit);
DECL_HANDLER(BookTypeRemove);
DECL_HANDLER(BookSearch);
DECL_HANDLER(BookGetInfo);
DECL_HANDLER(BookGetObjInfo);
DECL_HANDLER(BookGetBorrowed);
DECL_HANDLER(BookBorrow);
DECL_HANDLER(BookReturn);

109
main.cpp Normal file
View File

@ -0,0 +1,109 @@
#include "bs_util.h"
#include "handler.h"
using namespace std;
map<int,function<void(Request& req,Session& se,Response& res,json& j)>> _handlers;
int RequestDispatch(Request& req,Session& se,Response& res,json& j,int Key)
{
if(_handlers.find(Key)!=_handlers.end())
{
if(_handlers[Key])
{
j["RDKey"]=Key;
_handlers[Key](req,se,res,j);
return 0;
}
else
{
jsonfail_func(j,err_general,"No action is associated to key.");
return -1;
}
}
else
{
jsonfail_func(j,err_general,"Failed to find appropriate action to key.");
return -1;
}
}
#define REG_HANDLER(fn,key) _handlers.insert(make_pair(key,fn))
void InitHandlers()
{
REG_HANDLER(UserLogin,1); /// 用户登录
REG_HANDLER(UserLogout,2); /// 用户登出
REG_HANDLER(CheckLogin,3); /// 检查是否已登录
REG_HANDLER(CheckLoginX,4); /// 检查是否已登录(专用于登录页面,用于快速登录)
REG_HANDLER(UserReaderAdd,5); /// 添加用户(同时添加读者信息)
REG_HANDLER(UserReaderEdit,6); /// 修改用户(除管理员外)
REG_HANDLER(UserReaderRemove,7); /// 删除用户(仅能删除读者账户)
REG_HANDLER(UserSearch,8); /// 用户搜索
REG_HANDLER(UserReaderGet,9); /// 账户读者信息获取
//REG_HANDLER(UserReaderGetLow,10); /// 账户读者信息获取(低权限)
REG_HANDLER(BookSearch,11); /// 图书搜索
REG_HANDLER(BookGetInfo,12); /// 获取图书信息
REG_HANDLER(BookGetObjInfo,13); /// 获取图书实体信息
REG_HANDLER(BookGetBorrowed,14); /// 获取已借阅的书籍
REG_HANDLER(BookObjAdd,15);
REG_HANDLER(BookObjEdit,16);
REG_HANDLER(BookObjRemove,17);
REG_HANDLER(BookBorrow,21); /// 图书借阅
REG_HANDLER(BookReturn,22); /// 图书归还
REG_HANDLER(BookTypeGet,30); /// 查询已存在的图书种类
REG_HANDLER(BookTypeAdd,31); /// 添加图书种类
REG_HANDLER(BookTypeEdit,32); /// 修改图书种类
REG_HANDLER(BookTypeRemove,33); /// 删除加图书种类
REG_HANDLER(BookAdd,41); /// 添加图书信息
REG_HANDLER(BookEdit,42); /// 修改图书信息
REG_HANDLER(BookRemove,43); /// 删除图书信息
}
int main()
{
InitHandlers();
Request req;
Session se(req);
Response res;
res.showOnDestroy(true);
json j;
default_jsonfail();
do
{
/// Must be post
if(req.requestMethod!="POST")
{
jsonfail(err_method_not_supported);
break;
}
postval(action);
int key_real=ParseInt(action);
int ret;
if((ret=RequestDispatch(req,se,res,j,key_real))>=0)
{
j["RD"]="success";
}
else
{
j["RD"]="fail";
}
j["RDCode"]=ret;
}while(0);
se.writeToResponse(res);
res.content.append(j.dump());
return 0;
}

View File

@ -132,3 +132,16 @@ begin
end
//
DELIMITER ;
DELIMITER //
create trigger clean_up after insert on bs_session
for each row
begin
delete from bs_session where last_time+600<unix_timestamp(now());
end
//
DELIMITER ;
create view bs_userreader as select * from bs_user natural join bs_reader;
create view bs_bookdup as (select name,book_id from bs_book A inner join bs_bookstatus B on A.class_id=B.class_id)
create view bs_userborrow as select username,book_id from bs_user natural join bs_borrow where return_time is null

View File

@ -1,5 +0,0 @@
start transaction
select count(id) from bs_session where id='0284A830DCADD84758B2F1E945C744FA'
insert into bs_session values ('0284A830DCADD84758B2F1E945C744FA',1512108423,null)
commit
select username from bs_session where id='0284A830DCADD84758B2F1E945C744FA'

1392
src/BookSearch.cpp Normal file

File diff suppressed because it is too large Load Diff

0
src/bs_src_util.cpp Normal file
View File

1
src/bs_src_util.h Normal file
View File

@ -0,0 +1 @@
#pragma once

BIN
webdesign.pptx Normal file

Binary file not shown.