diff --git a/DBHomework.cbp b/DBHomework.cbp index 575d2ed..53e9103 100644 --- a/DBHomework.cbp +++ b/DBHomework.cbp @@ -31,99 +31,37 @@ + + + - - + - - + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DBHomework.depend b/DBHomework.depend index 59202df..28dd2eb 100644 --- a/DBHomework.depend +++ b/DBHomework.depend @@ -1,24 +1,16 @@ # depslib dependency file v1.0 -1510706148 source:d:\codeblocks_codes\dbhomework\main.cpp - - - - - - - - - "Request.h" - "Response.h" +1511504972 source:d:\codeblocks_codes\dbhomework\main.cpp + "Session.h" "Util.h" - "MySQLWrapper.h" + "jsonfail.h" "json.hpp" + "MySQLTransaction.h" 1511076615 d:\codeblocks_codes\dbhomework\mysqlwrapper\mysqlwrapper.h -1511076563 source:d:\codeblocks_codes\dbhomework\mysqlwrapper\mysqlwrapper.cpp +1511877230 source:d:\codeblocks_codes\dbhomework\mysqlwrapper\mysqlwrapper.cpp "MySQLWrapper.h" "MySQLInclude.h" @@ -96,38 +88,39 @@ "Util.h" -1510899241 source:d:\codeblocks_codes\dbhomework\httpwrapper\request.cpp +1511792433 source:d:\codeblocks_codes\dbhomework\httpwrapper\request.cpp "Request.h" "Util.h" + -1510899188 d:\codeblocks_codes\dbhomework\httpwrapper\request.h +1511686368 d:\codeblocks_codes\dbhomework\httpwrapper\request.h "Session.h" -1511136347 source:d:\codeblocks_codes\dbhomework\httpwrapper\response.cpp +1511686368 source:d:\codeblocks_codes\dbhomework\httpwrapper\response.cpp "Response.h" -1511136341 d:\codeblocks_codes\dbhomework\httpwrapper\response.h +1511686368 d:\codeblocks_codes\dbhomework\httpwrapper\response.h "CookieVec.h" -1511153903 source:d:\codeblocks_codes\dbhomework\httpwrapper\util.cpp +1511686368 source:d:\codeblocks_codes\dbhomework\httpwrapper\util.cpp "Util.h" -1511153929 d:\codeblocks_codes\dbhomework\httpwrapper\util.h +1511689007 d:\codeblocks_codes\dbhomework\httpwrapper\util.h - "MySQLWrapper.h" "Response.h" + "MySQLWrapper.h" 1510704940 d:\codeblocks_codes\dbhomework\json.hpp @@ -163,7 +156,7 @@ "Util.h" -1510973351 d:\codeblocks_codes\dbhomework\httpwrapper\cookievec.h +1511791095 d:\codeblocks_codes\dbhomework\httpwrapper\cookievec.h @@ -201,7 +194,7 @@ -1511147480 d:\codeblocks_codes\dbhomework\httpwrapper\session.h +1511250624 d:\codeblocks_codes\dbhomework\httpwrapper\session.h "Request.h" "Response.h" @@ -219,18 +212,20 @@ "Util.h" "json.hpp" -1511149331 source:d:\codeblocks_codes\dbhomework\login.cpp +1511687998 source:d:\codeblocks_codes\dbhomework\login.cpp + "Request.h" + "Response.h" "Session.h" "Util.h" - "json.hpp" - "jsonfail.h" + "MySQLWrapper.h" + "MySQLTransaction.h" 1511136779 source:d:\codeblocks_codes\dbhomework\addbooktype.cpp "Session.h" "Util.h" "json.hpp" -1511149002 source:d:\codeblocks_codes\dbhomework\jsonfail.cpp +1511158571 source:d:\codeblocks_codes\dbhomework\jsonfail.cpp "jsonfail.h" 1511153994 d:\codeblocks_codes\dbhomework\jsonfail.h @@ -259,3 +254,136 @@ 1511156696 d:\codeblocks_codes\dbhomework\mysqltransaction.h "MySQLWrapper.h" +1511248736 source:d:\codeblocks_codes\dbhomework\dopaste.cpp + "Request.h" + "Response.h" + "Util.h" + "json.hpp" + + + "windows.h" + +1511878138 source:d:\codeblocks_codes\dbhomework\httpwrapper\session_mysql.cpp + "Session.h" + "Singleton.hpp" + "Util.h" + "MySQLWrapper.h" + "MySQLTransaction.h" + + + + +1511337863 source:d:\codeblocks_codes\dbhomework\blockuser.cpp + "Session.h" + "Util.h" + "jsonfail.h" + "json.hpp" + +1511338065 source:d:\codeblocks_codes\dbhomework\allowuser.cpp + "Session.h" + "Util.h" + "jsonfail.h" + "json.hpp" + +1511416570 source:d:\codeblocks_codes\dbhomework\addbookobject.cpp + "Session.h" + "Util.h" + "jsonfail.h" + "json.hpp" + "MySQLTransaction.h" + +1511877177 d:\codeblocks_codes\dbhomework\mysqlwrapper\mysqltransaction.h + "MySQLWrapper.h" + +1511877161 source:d:\codeblocks_codes\dbhomework\mysqlwrapper\mysqltransaction.cpp + "MySQLTransaction.h" + +1511687385 source:d:\codeblocks_codes\dbhomework\install.cpp + "Request.h" + "Response.h" + "Session.h" + "Util.h" + "MySQLWrapper.h" + "MySQLTransaction.h" + +1511790374 source:d:\codeblocks_codes\dbhomework\old\login.cpp + "Session.h" + "Util.h" + "json.hpp" + "jsonfail.h" + +1510704940 d:\codeblocks_codes\dbhomework\\json.hpp + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1511153994 d:\codeblocks_codes\dbhomework\\jsonfail.h + +1511940029 source:d:\codeblocks_codes\dbhomework\src\login.cpp + "bs_util.h" + + + +1511939814 source:d:\codeblocks_codes\dbhomework\bs_util.cpp + "bs_util.h" + +1512014783 d:\codeblocks_codes\dbhomework\\bs_util.h + "Request.h" + "Response.h" + "Session.h" + "json.hpp" + "jsonfail.h" + "Util.h" + +1512014783 d:\codeblocks_codes\dbhomework\bs_util.h + "Request.h" + "Response.h" + "Session.h" + "json.hpp" + "jsonfail.h" + "Util.h" + +1511941430 source:d:\codeblocks_codes\dbhomework\src\dochecklogin.cpp + "bs_util.h" + +1511963515 source:d:\codeblocks_codes\dbhomework\src\dogetbookstatus.cpp + "bs_util.h" + +1511947446 source:d:\codeblocks_codes\dbhomework\src\doviewbook.cpp + "bs_util.h" + +1512096115 source:d:\codeblocks_codes\dbhomework\src\doborrowbook.cpp + "bs_util.h" + "MySQLTransaction.h" + +1512108415 source:d:\codeblocks_codes\dbhomework\src\doaddbook.cpp + "bs_util.h" + +1512703018 source:d:\codeblocks_codes\dbhomework\src\doaddbookobj.cpp + "bs_util.h" + "MySQLTransaction.h" + diff --git a/DBHomework.layout b/DBHomework.layout index 98df725..9f6eacc 100644 --- a/DBHomework.layout +++ b/DBHomework.layout @@ -1,100 +1,95 @@ - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - + diff --git a/bs_util.h b/bs_util.h index aa08a9d..b955303 100644 --- a/bs_util.h +++ b/bs_util.h @@ -19,4 +19,4 @@ int getPermissionLevel(const std::string& Username,Response& res); std::function SQLParseInt(int& nval); #define postval(NAME) if(req.post[#NAME].empty()){jsonfail(err_missing_parameter);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;} +#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;} diff --git a/dbconfig.txt b/dbconfig.txt new file mode 100644 index 0000000..2b098f3 --- /dev/null +++ b/dbconfig.txt @@ -0,0 +1,5 @@ +127.0.0.1 +root +ilovelgj +abc +3306 diff --git a/design.txt b/design.txt index bdf0f29..3f30711 100644 --- a/design.txt +++ b/design.txt @@ -1,118 +1,146 @@ -ݿҵ: - +数据库作业: +语言 JavaScript,HTML,C++ -ݿ: +数据库: MySQL =================== -ݿ +数据库表设计 =================== -ǰ׺: bs_ -û(bs_user) - ¼˺ varchar - ¼ varchar (hashed) - dz varchar - û integer (0 Ա 1 Ա 2 ͼݽĴ 3 ) - 3ûжӦûϢ! - ˻״̬ integer (0 1 ֹ½ 2 Ҫ֤ܼ 3 ½) - ״̬: Ըõ½˺ŵ½ʱʾ˻,עʱʾܲע - ֹ½: Ըõ½˺ŵ½ʱʾ˻ѱ - ֤: עûҪ֤½ʱʾ֤. ֤״̬Ϊ3 - ½: һ +表前缀: bs_ +用户表(bs_user) + 登录账号 varchar 主键 + 登录密码 varchar (hashed) + 昵称 varchar + 用户级别 integer (0 超级管理员 1 管理员 2 图书馆借阅处 3 读者) + 3级用户必须有对应的用户信息! + 账户状态 integer (0 隐藏 1 禁止登陆 2 需要验证才能激活 3 允许登陆) + 隐藏状态: 以该登陆账号登陆时会提示账户不存在,但注册时会提示不能不注册 + 禁止登陆: 以该登陆账号登陆时会提示账户已被禁用 + 待验证: 刚注册完的用户需要经过验证,登陆时会提示待验证. 验证后状态变为3 + 允许登陆: 一切正常 -(bs_level) - ȼ integer - Ĭͽ޶ integer - Ĭ߽޶ integer - Ĭͽʱ integer - Ĭ߽ʱ integer - ɽܵС money +级别表(bs_level) + 等级 integer 主键 + 默认最低借阅限额 integer + 默认最高借阅限额 integer + 默认最低借阅时间 integer + 默认最高借阅时间 integer + 可接受的最小余额额度 money -߱(bs_reader) - ¼˺ bs_user - varchar - ֤ varchar - ϵ绰 varchar - ȼ integer (->->ı޶Ϣ) bs_level - ɳֵ(ֵ) integer (ǩ;ֵȵ) - ޶ integer (뼶еĬֵһ,ʱܵӰ) - ʹýĶ integer - ʱ޶ integer () - integer (ǩ,,) - money +读者表(bs_reader) + 登录账号 外键到bs_user + 姓名 varchar + 身份证号 varchar + 联系电话 varchar + 等级 integer (触发器->升级->改变限额等信息) 外键到bs_level + 成长值(经验值) integer (签到送经验值等等) + 借阅限额 integer (可以与级别表中的默认值不一致,但升级时会受到影响进而重新评估) + 已使用借阅额度 integer 冗余 + 借阅时间限额 integer (天) + 积分 integer (签到,奖励,活动) + 余额 money -ͼ(bs_booktype) - varchar +图书类别表(bs_booktype) + 类别名称 varchar 主键 -ͼ(bs_book) - ͼ鶨 integer (ǵЩûISBN) - ISBN varchar - varchar - bs_booktype - varchar - varchar - date - ״̬ integer (0 1 2 ) - : ͼʾⱾϢ - : ֹⱾ +图书表(bs_book) + 图书定义序号 integer 主键 (考虑到有些书没有ISBN号) + ISBN号 varchar 主键 + 名称 varchar + 类别 外键到bs_booktype + 作者 varchar + 出版社 varchar + 出版日期 date + 状态 integer (0 隐藏 1 禁用 2 正常) + 隐藏: 不在图书搜索中显示这本书的信息 + 禁用: 禁止借阅这本书 -ͼ״̬(bs_bookstatus) - ͼʵ integer (һͼж౾) - ͼ bs_book - λ varchar (ʾͼλ) - ״̬ integer (0 1 ʧ 2 ڹ) - : 鼮ѽ,bs_borrowвҵ - ʧ: 鼮Ѷʧ,޷вҵйϢ.(ڱ涪ʧ) - ڹ: 鼮ڹ,Խ +图书状态表(bs_bookstatus) + 图书实体序号 integer 主键 (一本书可能在图书馆里有多本藏书) + 图书类别序号 外键到bs_book + 位置 varchar (用来提示图书所在位置) + 状态 integer (0 借出 1 丢失 2 在馆) + 借出: 书籍已借出,可以在bs_borrow中查找到 + 丢失: 书籍已丢失,且无法从其他表中查找到有关信息.(用于报告丢失) + 在馆: 书籍在馆,可以借出 -Ĺϵ(bs_borrow) - ˺ bs_user - ͼʵ bs_bookstatus - date - ٻ date (ʹûڽͼ,ҲĶ. ڽ鼮ʱ) - date Ϊ ûnullʾѹ黹Ϊʷݣ +借阅关系表(bs_borrow) + 借阅者账号 外键到bs_user + 图书实体序号 外键到bs_bookstatus + 借阅日期 date + 最迟还书日期 date (即使用户在借阅图书后升级,这个日期也不会改动. 此日期是在借阅书籍的时候计算的) + 还书日期 date 可以为空 (如果没还书就是null,否则表示书已归还,此条数据留存为历史数据) =================== - +特性设计 =================== -5Ӱװ(߰װ,Wordpress Install) -Ա˺ ޸˻룬˻ֻһ,ӹԱ˺,ͬԱ˺ -Ա˺ ޸Լͨû,/޸ͼ,ͬͼݽĴ˺ -ͼݽĴ˺ ޸Լ,/޸ĽĹϵ +5分钟安装(在线安装,类似Wordpress Install) +超级管理员账号 可以修改所有账户的密码,此账户只能有一个,可以添加管理员账号,其他功能同管理员账号 +管理员账号 可以修改自己和所有普通用户的密码,添加/修改图书类别表,其他功能同图书馆借阅处账号 +图书馆借阅处账号 可以修改自己的密码,添加/修改借阅关系表 =================== - +具体设计 =================== -5ӰװҪϢ: - ݿַ dbaddr - ݿ˿ dbport - ݿ˻ dbuser - ݿ dbpass - ݿ dbname - Ա supass (Ա˻Ϊroot) +5分钟安装需要的信息: + 数据库服务器地址 dbaddr + 数据库端口 dbport + 数据库账户 dbuser + 数据库口令 dbpass + 数据库名称 dbname + 超级管理员口令 supass (超级管理员账户锁定为root) -½˺: +新建账号: session + +http://localhost/cgi-bin/booksys/admin/install + 安装页面. 安装成功后再访问本页面将重定向到login. + +http://localhost/cgi-bin/booksys/login + 登录页面 + +http://localhost/cgi-bin/booksys/mainpage + 主页(搜索框) + +http://localhost/cgi-bin/booksys/dashboard + 个人页面(borrowed book那些) -ɾIJ ͼͼ飬˻ +http://localhost/cgi-bin/booksys/info + +http://localhost/cgi-bin/booksys/admin/workbench + +http://localhost/cgi-bin/booksys/admin/booktype + +http://localhost/cgi-bin/booksys/admin/newbook + +http://localhost/cgi-bin/booksys/viewbook? + +http://localhost/cgi-bin/booksys/ + + + + + +增删改查 : 图书类别,图书,账户 http://booksys.com/api/v1/install POST (install.cpp) POST: dbaddr,dbport,dbuser,dbpass,dbname,supass http://booksys.com/api/v1/search?type=...&name=... GET (search.cpp) GET: - type= 0 û 1 鼮 - name= û,鼮 - typename= 鼮,typeΪ1ʱЧ + type= 0 用户 1 书籍 + name= 用户名,书籍名称 + typename= 书籍种类名称,仅当type为1时有效 http://booksys.com/api/v1/explore GET GET: - ûв + 没有参数 http://booksys.com/api/v1/addbook POST (addbook.cpp) POST: - (ͼ鶨Զ) + (图书定义序号自动生成) isbn bookname booktype @@ -121,14 +149,14 @@ pubdate status - : - Ȩ޲,ʧ + 错误: + 权限不足,添加失败 http://booksys.com/api/v1/editbook POST (editbook.cpp) POST: - book_key (Ψһͼ鶨) + book_key (唯一图书定义序号) - оΪѡ: һдʱݵ޸ + 以下所有列均为可选: 当任一列存在时将引起数据的修改 isbn bookname booktype @@ -137,40 +165,40 @@ pubdate status - : - Ȩ޲,޸ʧ + 错误: + 权限不足,修改失败 http://booksys.com/api/v1/removebook POST (removebook.cpp) POST: - book_key (Ψһͼ鶨) + book_key (唯一图书定义序号) - : - ͼһʵ崦ڽ״̬ʱɾͼ鶨. + 错误: + 当图书的任一实体处于借出状态时将不能删除图书定义. http://booksys.com/api/v1/addbooktype POST (addbooktype.cpp) POST: booktype - : - µƷͻ + 错误: + 当新的类型名称发生冲突 http://booksys.com/api/v1/editbooktype POST (editbooktype.cpp) POST: booktype_old booktype_new - : - µƷͻ + 错误: + 当新的类型名称发生冲突 - : - ıͼԭͼϢ(δʵ) + 副作用: + 改变图书种类会引起所有与原种类相关图书的信息变更(未实现) http://booksys.com/api/v1/removebooktype POST (removebooktype.cpp) POST: booktype - : - һͼ鶨ʹô˶ʱɾͼ + 错误: + 当任一图书定义使用此定义时将不能删除图书种类 http://booksys.com/api/v1/join POST (join.cpp) POST: @@ -178,10 +206,10 @@ pass nickname - ʾ:ͨAPIעûȼΪ3. ע˻״̬2 + 提示:通过此API注册的用户等级锁定为3. 且注册后账户处于状态2 - : - ˻ظʱ + 错误: + 账户名称重复时 http://booksys.com/api/v1/enableuser POST (enableuser.cpp) POST: @@ -190,122 +218,122 @@ realid realphone - ʾ:ͨAPIûȼΪ3.(ߵȼûҪ˼) ˻״̬ԶΪ3. + 提示:通过此API激活的用户等级必须为3.(更高等级的用户不需要经此激活) 激活后账户状态将自动变更为3. - : - ֹ. + 错误: + 内容填充错误或禁止激活. http://booksys.com/api/v1/login POST (login.cpp) POST: account pass - ʾ:ͨAPIɵ½ûȼΪ0,1,2,3,˻״̬Ϊ3ܵ½ɹ,˻״̬Ϊ2ʱʾϢǰ,˻״̬Ϊ1ʱؽֹ½,˻״̬Ϊ0ʱҪϵԱϢ. + 提示:通过此API可登陆的用户等级为0,1,2,3,账户状态为3才能登陆成功,账户状态为2时返回提示信息前往激活,账户状态为1时返回禁止登陆,账户状态为0时返回需要联系管理员激活信息. - : - ˻(˻) + 错误: + 账户或密码错误(包括账户错误) - : - ½ɹʱUserSession. + 返回: + 当登陆成功时绑定User到Session. http://booksys.com/api/v1/logout GET/POST (logout.cpp) - ʾ:˳½. עSession. + 提示:退出登陆. 会立刻注销Session. http://booksys.com/api/v1/addbookobject POST (addbookobject.cpp) POST: - class_id ͼ鶨 - book_id ͼʵ(ѡ,д˲ʱԴ˲½鼮) - position λ - status ͼ״̬ + class_id 图书定义序号 + book_id 图书实体序号(可选,当有此参数时将尝试以此参数新建书籍) + position 藏书位置 + status 图书状态 - : - Ȩ޲ - ͼʵųͻ + 错误: + 权限不足 + 图书实体序号冲突 http://booksys.com/api/v1/editbookobject POST POST: - book_id_old ͼʵ - book_id_new ͼʵ (ѡ) - position_new ²λ (ѡ) - status ͼ״̬ + book_id_old 旧图书实体序号 + book_id_new 新图书实体序号 (可选) + position_new 新藏书位置 (可选) + status 图书新状态 - : - Ȩ޲ - ͼʵ岻 - ͼʵųͻ + 错误: + 权限不足 + 图书实体不存在 + 图书实体序号冲突 http://booksys.com/api/v1/removebookobject POST POST: - book_id ͼʵ + book_id 图书实体序号 - : - Ȩ޲ - ͼʵŲ - ͼѽ,ɾʵ + 错误: + 权限不足 + 图书实体序号不存在 + 图书已借出,不能删除实体 http://booksys.com/api/v1/borrowbook POST POST: - account ˻ - book_id ͼʵ + account 借阅者账户 + book_id 图书实体序号 - : - Ȩ޲(APIֻͼԱ(ȼ<=2)) - ͼ鲻ɽ - ʵ岻 + 错误: + 权限不足(此API只能由图书管理员以上(等级<=2)调用) + 图书不可借阅 + 实体不存在 http://booksys.com/api/v1/returnbook POST POST: - book_id ͼʵ + book_id 图书实体序号 - : - ͼ״̬(δȵ) - ʵ岻 + 错误: + 图书状态不允许还书(未借出等等) + 实体不存在 http://booksys.com/api/v1/blockuser POST (blockuser.cpp) POST: - account û + account 被操作用户 - ʾ: - ޸û״̬Ϊ1(ֹ½) + 提示: + 本操作将修改用户的状态为1(禁止登陆) - : - Ȩ޲. ֻм<=1ûʹñAPI. йԱֻ޸Լ͵ȼ>=2û. Ա޸ȫ˻. + 错误: + 权限不足. 只有级别<=1的用户可以使用本API. 其中管理员只能修改自己和等级>=2的用户. 超级管理员可以修改全部账户. http://booksys.com/api/v1/allowuser POST (allowuser.cpp) POST: - account û + account 被操作用户 - ʾ: - ޸û״̬Ϊ3(). ע: ûδ֤,֤. + 提示: + 本操作将修改用户的状态为3(正常). 注意: 若用户尚未完成身份验证,将忽视身份验证步骤. - : - Ȩ޲. ֻм<=1ûʹñAPI.йԱֻ޸Լ͵ȼ>=2û. Ա޸ȫ˻. + 错误: + 权限不足. 只有级别<=1的用户可以使用本API.其中管理员只能修改自己和等级>=2的用户. 超级管理员可以修改全部账户. http://booksys.com/api/v1/dashboard GET GET: - ޲ + 无参数 - : - عڵǰûȫϢ. (Session) + 返回: + 返回关于当前用户的全部信息. (Session关联) - : - δ¼ + 错误: + 未登录 http://booksys.com/api/v1/adminsearch POST POST: - ʾ: - Աר + 提示: + 管理员专用搜索 - : - Ȩ޲. ֻйԱ<=1ʹñAPI + 错误: + 权限不足. 只有管理员<=1能使用本API http://booksys.com/api/v1/advancedsearch POST POST: - ʾ: + 提示: - : - Ȩ޲㣬ֻ<=2ûʹñAPI + 错误: + 权限不足,只有<=2的用户能使用本API \ No newline at end of file diff --git a/setup.sql b/setup.sql index 6ba5c5b..e27d0c6 100644 --- a/setup.sql +++ b/setup.sql @@ -93,4 +93,42 @@ create table bs_session id char(32) primary key, last_time integer, username varchar(10) references bs_user(username) -); \ No newline at end of file +); + +DROP PROCEDURE IF EXISTS newbook; +DELIMITER // +create procedure newbook( + IN isbn varchar(13), + IN name varchar(20), + IN book_type varchar(10), + IN author varchar(10), + IN publisher varchar(20), + IN publish_time date, + IN status integer +) +begin + declare maxid integer; + declare idcnt integer; + declare result_code integer default 0; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET result_code = 1; + + start transaction; + select count(class_id) into idcnt from bs_book ; + select max(class_id) into maxid from bs_book; + + if (idcnt=0) then + set maxid=1; + else + set maxid=maxid+1; + end if; + insert into bs_book values (maxid,isbn,name,book_type,author,publisher,publish_time,status); + if result_code=1 then + rollback; + else + commit; + end if; + + select result_code; +end +// +DELIMITER ; diff --git a/sql_log.txt b/sql_log.txt new file mode 100644 index 0000000..c7ef9cc --- /dev/null +++ b/sql_log.txt @@ -0,0 +1,5 @@ +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' diff --git a/src/doAddBook.cpp b/src/doAddBook.cpp new file mode 100644 index 0000000..f51813b --- /dev/null +++ b/src/doAddBook.cpp @@ -0,0 +1,121 @@ +#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(book_isbn); + postval(book_type); + postval(book_name); + postval(book_author); + postval(book_publish); + postval(book_pubdate); + postval(book_status); + + int book_status_real=ParseInt(book_status); + if(book_status_real<0) + { + jsonfail(err_parameter,"Failed to parse status"); + break; + } + + if(book_status_real<0||book_status_real>2) + { + jsonfail(err_parameter,"Invalid Status"); + break; + } + + startdb(); + + /// Check Permission + int permission_level=-1; + if(conn.exec(make_str("select permission_level from bs_user where username='", + se.getUser(), + "'"), + SQLParseInt(permission_level))<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + if(permission_level<0) + { + jsonfail(err_data,"Failed to get permission level"); + break; + } + + if(permission_level>2) + { + jsonfail(err_permission_denied,"Permission Not Reach Required Level"); + break; + } + + int result_code=-1; + if(conn.exec(make_str("call newbook('", + book_isbn, + "','", + book_name, + "','", + book_type, + "','", + book_author, + "','", + book_publish, + "','", + book_pubdate, + "',", + book_status_real, + ")"), + SQLParseInt(result_code))<0) + { + jsonfail(err_sql,"Procedure 1"); + break; + } + + if(result_code==1) + { + /// Failed + jsonfail(err_sql_logic,"SQL Operation Failed"); + break; + } + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/doAddBookObj.cpp b/src/doAddBookObj.cpp new file mode 100644 index 0000000..c00d509 --- /dev/null +++ b/src/doAddBookObj.cpp @@ -0,0 +1,141 @@ +#include "bs_util.h" +#include "MySQLTransaction.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); + postval(book_pos); + postval(bookobj_status); + + int id_real=ParseInt(id); + if(id_real<0) + { + jsonfail(err_data,"Failed to parse id."); + break; + } + + int bookobj_status_real=ParseInt(bookobj_status); + if(bookobj_status_real<0) + { + jsonfail(err_data,"Failed to parse obj status"); + break; + } + + startdb(); + + Transaction ts(conn); + + /// Check Permission + int permission_level=-1; + if(conn.exec(make_str("select permission_level from bs_user where username='", + se.getUser(), + "'"), + SQLParseInt(permission_level))<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + if(permission_level<0 || permission_level>=3) + { + jsonfail(err_permission_denied); + break; + } + + /// Check If this is the first book object + int count_val=-1; + if(conn.exec("select count(book_id) from bs_bookstatus", + SQLParseInt(count_val))<0) + { + jsonfail(err_sql,"Step 2"); + break; + } + + if(count_val<0) + { + jsonfail(err_general,"This error should not exist."); + break; + } + + int current_maxbook_id=-1; + if(count_val==0) + { + current_maxbook_id=0; + } + else + { + /// Get Available BookObjID + + if(conn.exec("select max(book_id) from bs_bookstatus", + SQLParseInt(current_maxbook_id))<0) + { + jsonfail(err_sql,"Step 3"); + break; + } + + if(current_maxbook_id<0) + { + jsonfail(err_data,"Failed to generate book id."); + break; + } + } + + int nextbook_id=current_maxbook_id+1; + + /// Insert the book.(TODO) + if(conn.exec(make_str("insert into bs_bookstatus values (", + nextbook_id, + ",", + id_real, + ",'", + book_pos, + "',", + bookobj_status_real, + ")"), + nullptr)<0) + { + jsonfail(err_sql,"Step 4"); + break; + } + + ts.commit(); + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} diff --git a/src/doBorrowBook.cpp b/src/doBorrowBook.cpp new file mode 100644 index 0000000..53806fb --- /dev/null +++ b/src/doBorrowBook.cpp @@ -0,0 +1,167 @@ +#include "bs_util.h" +#include "MySQLTransaction.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(bid); + + int bid_real=ParseInt(bid); + if(bid_real<0) + { + jsonfail(err_parameter,"Failed to parse bid"); + break; + } + + startdb(); + + /// Start transaction + Transaction ts(conn); + if(!ts.isReady()) + { + jsonfail(err_sql_logic,"Failed to start transaction."); + break; + } + + /// Check if user can borrow... + int cntval; + if(conn.exec(make_str("select count(username) from bs_reader where username='", + se.getUser(), + "'"), + SQLParseInt(cntval))<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + if(cntval!=1) + { + jsonfail(err_permission_denied,"You are not in reader list!"); + break; + } + + int borrow_limit,borrow_used,borrow_time_limit; + if(conn.exec(make_str("select borrow_limit,borrow_used,borrow_time_limit from bs_reader where username='", + se.getUser(), + "'"), + [&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + borrow_limit=ParseInt(val[0]); + borrow_used=ParseInt(val[1]); + borrow_time_limit=ParseInt(val[2]); + }); + })<0) + { + jsonfail(err_sql,"Step 2"); + break; + } + + if(borrow_limit-borrow_used<=0) + { + jsonfail(err_general,"Reach Borrow Limit"); + break; + } + + /// Verify bid + if(conn.exec(make_str("select count(book_id) from bs_bookstatus where book_id=", + bid_real), + SQLParseInt(cntval))<0) + { + jsonfail(err_sql,"Step 3"); + break; + } + + if(cntval!=1) + { + jsonfail(err_parameter,"Failed to verify bid"); + break; + } + + /// Check if bid is allowed to be borrowed. + int book_status; + if(conn.exec(make_str("select status from bs_bookstatus where book_id=",bid_real), + SQLParseInt(book_status))<0) + { + jsonfail(err_sql,"Step 4"); + break; + } + + if(book_status!=2) + { + jsonfail(err_data,"Book is not allowed to borrow"); + break; + } + + /// DO UPDATE + if(conn.exec(make_str("update bs_reader set borrow_used=borrow_used+1 where username='", + se.getUser(), + "'"),nullptr)<0) + { + jsonfail(err_sql,"Update 1"); + break; + } + + if(conn.exec(make_str("update bs_bookstatus set status=0 where book_id=",bid_real),nullptr)<0) + { + jsonfail(err_sql,"Update 2"); + break; + } + + if(conn.exec(make_str("insert into bs_borrow values ('", + se.getUser(), + "',", + bid_real, + ",curdate(),date_add(curdate(),interval ", + borrow_time_limit, + " day),null)"),nullptr)<0) + { + jsonfail(err_sql,"Update 3"); + break; + } + + /// Commit it + ts.commit(); + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/doCheckLogin.cpp b/src/doCheckLogin.cpp new file mode 100644 index 0000000..8327fa4 --- /dev/null +++ b/src/doCheckLogin.cpp @@ -0,0 +1,47 @@ +#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; + } + + if(se.getUser().empty()) + { + jsonfail(err_need_login); + break; + } + + j["success"]=1; + j["next_url"]="/booksys/mainpage.html"; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/doCheckPermission.cpp b/src/doCheckPermission.cpp new file mode 100644 index 0000000..880cce3 --- /dev/null +++ b/src/doCheckPermission.cpp @@ -0,0 +1,79 @@ +#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(required); + int required_real=ParseInt(required); + if(required_real<0) + { + jsonfail(err_parameter,"Failed to parse permission level"); + break; + } + + startdb(); + + /// Get Permission + int xval=-1; + if(conn.exec(make_str("select permission_level from bs_user where username='", + se.getUser(), + "'"), + SQLParseInt(xval))<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + if(xval<0) + { + jsonfail(err_data,"Failed to parse X-Val"); + break; + } + + if(xval>required_real) + { + jsonfail(err_permission_denied,"Permission Not Reach Required Level"); + break; + } + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/doGetBookByObj.cpp b/src/doGetBookByObj.cpp new file mode 100644 index 0000000..a0f458c --- /dev/null +++ b/src/doGetBookByObj.cpp @@ -0,0 +1,70 @@ +#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(bid); + int bid_real=ParseInt(bid); + if(bid_real<0) + { + jsonfail(err_parameter,"Failed to parse BID"); + break; + } + + startdb(); + + string book_name; + if(conn.exec(make_str("select name from bs_book where class_id in (select class_id from bs_bookstatus where book_id=",bid_real,")"), + [&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + j["book_name"]=string(len[0]>0?val[0]:"(NULL)"); + }); + })<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/doGetBookStatus.cpp b/src/doGetBookStatus.cpp new file mode 100644 index 0000000..230e4a9 --- /dev/null +++ b/src/doGetBookStatus.cpp @@ -0,0 +1,81 @@ +#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; +} + + diff --git a/src/doGetBookTypes.cpp b/src/doGetBookTypes.cpp new file mode 100644 index 0000000..98ddd42 --- /dev/null +++ b/src/doGetBookTypes.cpp @@ -0,0 +1,63 @@ +#include "bs_util.h" +#include +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; + } + + startdb(); + + if(conn.exec("select book_type from bs_booktype", + [&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + j["result"].push_back(string(len[0]>0?val[0]:"")); + }); + })<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/doListBook.cpp b/src/doListBook.cpp new file mode 100644 index 0000000..bb17ffb --- /dev/null +++ b/src/doListBook.cpp @@ -0,0 +1,88 @@ +#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(startid); + postval(amount); + + int startid_real=ParseInt(startid); + if(startid_real<0) + { + jsonfail(err_parameter,"Failed to parse startid"); + break; + } + + int amount_real=ParseInt(amount); + if(amount_real<0) + { + jsonfail(err_parameter,"Failed to parse amount"); + break; + } + + /// Limit to 50. + if(amount_real>50) amount_real=50; + + startdb(); + + if(conn.exec(make_str("select class_id,name,book_type from bs_book where class_id>=", + startid_real, + " order by class_id limit ", + amount_real), + [&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + json s; + s["class_id"]=string(val[0]); + s["book_name"]=string(val[1]); + s["book_type"]=string(val[2]); + j["result"].push_back(s); + }); + })<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/login.cpp b/src/doLogin.cpp similarity index 94% rename from src/login.cpp rename to src/doLogin.cpp index 4171f69..e43f0c5 100644 --- a/src/login.cpp +++ b/src/doLogin.cpp @@ -1,6 +1,4 @@ #include "bs_util.h" -#include -#include using namespace std; int main() @@ -27,7 +25,7 @@ int main() { /// Logged in... j["success"]=2; - j["next_url"]="/booksys/dashboard.html"; + j["next_url"]="/booksys/mainpage.html"; break; } @@ -102,7 +100,7 @@ int main() else { j["success"]=1; - j["next_url"]="/booksys/dashboard.html"; + j["next_url"]="/booksys/mainpage.html"; } } while(0); diff --git a/src/doLogout.cpp b/src/doLogout.cpp new file mode 100644 index 0000000..5942f27 --- /dev/null +++ b/src/doLogout.cpp @@ -0,0 +1,48 @@ +#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()) + { + /// Not logged in + jsonfail(err_need_login); + break; + } + + int ret; + if((ret=se.setUser(""))<0) + { + jsonfail(err_session,make_str("Failed to reset session, SessionModule returns: ",ret)); + break; + } + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/doRemoveBook.cpp b/src/doRemoveBook.cpp new file mode 100644 index 0000000..3ddd2b8 --- /dev/null +++ b/src/doRemoveBook.cpp @@ -0,0 +1,124 @@ +#include "bs_util.h" +#include "MySQLTransaction.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(); + + Transaction ts(conn); + + /// Check Permission + int permission_level=-1; + if(conn.exec(make_str("select permission_level from bs_user where username='", + se.getUser(), + "'"), + SQLParseInt(permission_level))<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + if(permission_level<0) + { + jsonfail(err_general,"Failed to check Permission"); + break; + } + + if(permission_level>=3) + { + jsonfail(err_permission_denied); + break; + } + + /// Check if the book info can be removed. + /// count_val: Count of books with class_id={ID} and status is borrowed (0) + int count_val=-1; + if(conn.exec(make_str("select count(book_id) from bs_bookstatus where class_id=", + id_real, + " and status=0"), + SQLParseInt(count_val))<0) + { + jsonfail(err_sql,"Step 2"); + break; + } + + if(count_val<0) + { + jsonfail(err_data,"Failed to get book id data"); + break; + } + + if(count_val!=0) + { + jsonfail(err_data,make_str("Cannot remove book. Still ",count_val," books borrowed.")); + break; + } + + if(conn.exec(make_str("delete from bs_borrow where book_id in (select book_id from bs_bookstatus where class_id=",id_real),nullptr)<0) + { + jsonfail(err_sql,"Step 3"); + } + + if(conn.exec(make_str("delete from bs_bookstatus where class_id=",id_real),nullptr)<0) + { + jsonfail(err_sql,"Step 4"); + break; + } + + if(conn.exec(make_str("delete from bs_book where class_id=",id_real),nullptr)<0) + { + jsonfail(err_sql,"Step 5"); + break; + } + + ts.commit(); + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/doSearch.cpp b/src/doSearch.cpp new file mode 100644 index 0000000..ff258bb --- /dev/null +++ b/src/doSearch.cpp @@ -0,0 +1,73 @@ +#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(name); + + startdb(); + + if(conn.exec("set names utf8",nullptr)<0) + { + jsonfail(err_sql,"Failed to set names"); + break; + } + + if(conn.exec(make_str("select class_id,name,book_type from bs_book where name like '%", + name, + "%'"), + [&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + json s; + s["class_id"]=string(val[0]); + s["book_name"]=string(val[1]); + s["book_type"]=string(val[2]); + j["result"].push_back(s); + }); + })<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} diff --git a/src/doViewBook.cpp b/src/doViewBook.cpp new file mode 100644 index 0000000..3b45b4c --- /dev/null +++ b/src/doViewBook.cpp @@ -0,0 +1,80 @@ +#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(make_str("select name,isbn,book_type,author,publisher,publish_time,status from bs_book where class_id=", + id), + [&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + /// define ref + json& x=j; + + x["book_name"]=string(val[0]); + x["book_isbn"]=string(val[1]); + x["book_type"]=string(val[2]); + x["book_author"]=string(val[3]); + x["book_publisher"]=string(val[4]); + x["book_pubdate"]=string(val[5]); + x["book_status"]=ParseInt(val[6]); + }); + })<0) + { + jsonfail(err_sql,"Step 1"); + break; + } + + j["success"]=1; + } + while(0); + + se.writeToResponse(res); + res.content.append(j.dump()); + + return 0; +} + + diff --git a/src/search.cpp b/src/search.cpp deleted file mode 100644 index c94b20c..0000000 --- a/src/search.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "Request.h" -#include "Response.h" -#include "Util.h" -#include "json.hpp" -using namespace std; -using json=nlohmann::json; - -int main() -{ - Request req; - Response res; - json j; - - auto jsonfail=[&](int errcode,const std::string& errmsg) - { - j["success"]=0; - j["errcode"]=errcode; - j["errmsg"]=errmsg; - }; - - if(req.requestMethod=="GET") - { - if(req.get["type"].empty()) - { - jsonfail(2,"Missing Parameter: type"); - } - else - { - string searchType=req.get["type"]; - if(searchType=="0") - { - /// Search User - if(req.get["name"].empty()) - { - jsonfail(3,"Missing Parameter: name"); - } - else - { - /// Search User by ONLY nickname. - string nickname=req.get["name"]; - DBInfo db; - if(db.readConfig()<0) - { - /// Failed to read config. May be not installed. - jsonfail(4,"Failed to read configure."); - } - else - { - MySQLConn conn; - if(db.connectProxy(conn)<0) - { - jsonfail(5,"Failed to connect DB"); - } - else - { - vector> vec; - if(conn.exec(make_str("select name from bs_user where nickname like '%",nickname,"%'"),[&](MySQLResult& res) - { - res.stepRow([&](char** val,unsigned long* len) - { - vec.push_back(make_pair(val[0],val[1])); - }); - })<0) - { - jsonfail(6,"Failed to execute SQL."); - } - else - { - j["success"]=1; - int sz=vec.size(); - for(int i=0;i> vec; - if(conn.exec(make_str("select class_id,name from bs_book where name like '%",bookname,"%'"),[&](MySQLResult& res) - { - res.stepRow([&](char** val,unsigned long* len) - { - vec.push_back(make_pair(val[0],val[1])); - }); - })<0) - { - jsonfail(16,"Failed to execute SQL."); - } - else - { - j["success"]=1; - int sz=vec.size(); - for(int i=0;i + + + BookSystem 添加图书 + {{Header}} + {{navcss}} + + + + {{nav}} +
+ +

添加图书

+

ISBN:

+

图书种类: 添加或删除图书种类

+

图书名称:

+

作者:

+

出版商:

+

出版日期:

+

状态: + +

+ + +
+ + + + \ No newline at end of file diff --git a/web/booksys/addbookobj.html b/web/booksys/addbookobj.html new file mode 100644 index 0000000..cc1bac5 --- /dev/null +++ b/web/booksys/addbookobj.html @@ -0,0 +1,104 @@ + + + + BookSystem 添加图书实体 + {{Header}} + {{navcss}} + + + + {{nav}} +
+
+ +
+

添加图书实体

+

图书标题:【正在获取图书信息...】么?

+

存放位置:

+

状态: + +

+ + + +
+
+ + + + \ No newline at end of file diff --git a/web/booksys/borrow-success.html b/web/booksys/borrow-success.html new file mode 100644 index 0000000..b4e302d --- /dev/null +++ b/web/booksys/borrow-success.html @@ -0,0 +1,27 @@ + + + + BookSystem 图书借阅成功 + {{Header}} + {{navcss}} + + + + {{nav}} +
+

借阅成功!请及时到线下图书馆取走书籍

+ +
+ + + + \ No newline at end of file diff --git a/web/booksys/borrowbook.html b/web/booksys/borrowbook.html new file mode 100644 index 0000000..9ec0859 --- /dev/null +++ b/web/booksys/borrowbook.html @@ -0,0 +1,71 @@ + + + + BookSystem 图书借阅 + {{Header}} + {{navcss}} + + + + {{nav}} +
+

确认借阅: 【正在获取图书信息】 么?

+ + +
+ + + + \ No newline at end of file diff --git a/web/booksys/img/default_user.png b/web/booksys/img/default_user.png index 98bb652..d851dcc 100644 Binary files a/web/booksys/img/default_user.png and b/web/booksys/img/default_user.png differ diff --git a/web/booksys/img/search_icon.png b/web/booksys/img/search_icon.png new file mode 100644 index 0000000..cd3034a Binary files /dev/null and b/web/booksys/img/search_icon.png differ diff --git a/web/booksys/include/nav.css b/web/booksys/include/nav.css new file mode 100644 index 0000000..02e0cc0 --- /dev/null +++ b/web/booksys/include/nav.css @@ -0,0 +1,7 @@ +nav ul { + list-style: none; +} +nav li { + display: inline; + line-height: 50px; +} \ No newline at end of file diff --git a/web/booksys/install-success.html b/web/booksys/install-success.html index 13eda95..ad61d3c 100644 --- a/web/booksys/install-success.html +++ b/web/booksys/install-success.html @@ -2,12 +2,7 @@ 安装成功 - - - - - - + {{Header}} diff --git a/web/booksys/install.html b/web/booksys/install.html index 2cebf4b..d28c02f 100644 --- a/web/booksys/install.html +++ b/web/booksys/install.html @@ -2,12 +2,7 @@ BookSystem 安装 - - - - - - + {{Header}}