Rewrote Frontend
This commit is contained in:
		
							
								
								
									
										1254
									
								
								backend/model/Inode.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1254
									
								
								backend/model/Inode.cc
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										295
									
								
								backend/model/Inode.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										295
									
								
								backend/model/Inode.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,295 @@
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 *  Inode.h
 | 
			
		||||
 *  DO NOT EDIT. This file is generated by drogon_ctl
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "drogon/orm/Result.h"
 | 
			
		||||
#include "drogon/orm/Row.h"
 | 
			
		||||
#include "drogon/orm/Field.h"
 | 
			
		||||
#include "drogon/orm/SqlBinder.h"
 | 
			
		||||
#include "drogon/orm/Mapper.h"
 | 
			
		||||
#ifdef __cpp_impl_coroutine
 | 
			
		||||
#include <drogon/orm/CoroMapper.h>
 | 
			
		||||
#endif
 | 
			
		||||
#include "trantor/utils/Date.h"
 | 
			
		||||
#include "trantor/utils/Logger.h"
 | 
			
		||||
#include "json/json.h"
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <tuple>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
namespace drogon
 | 
			
		||||
{
 | 
			
		||||
namespace orm
 | 
			
		||||
{
 | 
			
		||||
class DbClient;
 | 
			
		||||
using DbClientPtr = std::shared_ptr<DbClient>;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
namespace drogon_model
 | 
			
		||||
{
 | 
			
		||||
namespace sqlite3
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class Inode
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    struct Cols
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string _id;
 | 
			
		||||
        static const std::string _is_file;
 | 
			
		||||
        static const std::string _name;
 | 
			
		||||
        static const std::string _parent_id;
 | 
			
		||||
        static const std::string _owner_id;
 | 
			
		||||
        static const std::string _size;
 | 
			
		||||
        static const std::string _has_preview;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const static int primaryKeyNumber;
 | 
			
		||||
    const static std::string tableName;
 | 
			
		||||
    const static bool hasPrimaryKey;
 | 
			
		||||
    const static std::string primaryKeyName;
 | 
			
		||||
    using PrimaryKeyType = uint64_t;
 | 
			
		||||
    const PrimaryKeyType &getPrimaryKey() const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param r One row of records in the SQL query result.
 | 
			
		||||
     * @param indexOffset Set the offset to -1 to access all columns by column names,
 | 
			
		||||
     * otherwise access all columns by offsets.
 | 
			
		||||
     * @note If the SQL is not a style of 'select * from table_name ...' (select all
 | 
			
		||||
     * columns by an asterisk), please set the offset to -1.
 | 
			
		||||
     */
 | 
			
		||||
    explicit Inode(const drogon::orm::Row &r, const ssize_t indexOffset = 0) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param pJson The json object to construct a new instance.
 | 
			
		||||
     */
 | 
			
		||||
    explicit Inode(const Json::Value &pJson) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param pJson The json object to construct a new instance.
 | 
			
		||||
     * @param pMasqueradingVector The aliases of table columns.
 | 
			
		||||
     */
 | 
			
		||||
    Inode(const Json::Value &pJson, const std::vector<std::string> &pMasqueradingVector) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    Inode() = default;
 | 
			
		||||
 | 
			
		||||
    void updateByJson(const Json::Value &pJson) noexcept(false);
 | 
			
		||||
    void updateByMasqueradedJson(const Json::Value &pJson,
 | 
			
		||||
                                 const std::vector<std::string> &pMasqueradingVector) noexcept(false);
 | 
			
		||||
    static bool validateJsonForCreation(const Json::Value &pJson, std::string &err);
 | 
			
		||||
    static bool validateMasqueradedJsonForCreation(const Json::Value &,
 | 
			
		||||
                                                const std::vector<std::string> &pMasqueradingVector,
 | 
			
		||||
                                                    std::string &err);
 | 
			
		||||
    static bool validateJsonForUpdate(const Json::Value &pJson, std::string &err);
 | 
			
		||||
    static bool validateMasqueradedJsonForUpdate(const Json::Value &,
 | 
			
		||||
                                          const std::vector<std::string> &pMasqueradingVector,
 | 
			
		||||
                                          std::string &err);
 | 
			
		||||
    static bool validJsonOfField(size_t index,
 | 
			
		||||
                          const std::string &fieldName,
 | 
			
		||||
                          const Json::Value &pJson,
 | 
			
		||||
                          std::string &err,
 | 
			
		||||
                          bool isForCreation);
 | 
			
		||||
 | 
			
		||||
    /**  For column id  */
 | 
			
		||||
    ///Get the value of the column id, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfId() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getId() const noexcept;
 | 
			
		||||
    ///Set the value of the column id
 | 
			
		||||
    void setId(const uint64_t &pId) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column is_file  */
 | 
			
		||||
    ///Get the value of the column is_file, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfIsFile() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getIsFile() const noexcept;
 | 
			
		||||
    ///Set the value of the column is_file
 | 
			
		||||
    void setIsFile(const uint64_t &pIsFile) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column name  */
 | 
			
		||||
    ///Get the value of the column name, returns the default value if the column is null
 | 
			
		||||
    const std::string &getValueOfName() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<std::string> &getName() const noexcept;
 | 
			
		||||
    ///Set the value of the column name
 | 
			
		||||
    void setName(const std::string &pName) noexcept;
 | 
			
		||||
    void setName(std::string &&pName) noexcept;
 | 
			
		||||
    void setNameToNull() noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column parent_id  */
 | 
			
		||||
    ///Get the value of the column parent_id, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfParentId() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getParentId() const noexcept;
 | 
			
		||||
    ///Set the value of the column parent_id
 | 
			
		||||
    void setParentId(const uint64_t &pParentId) noexcept;
 | 
			
		||||
    void setParentIdToNull() noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column owner_id  */
 | 
			
		||||
    ///Get the value of the column owner_id, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfOwnerId() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getOwnerId() const noexcept;
 | 
			
		||||
    ///Set the value of the column owner_id
 | 
			
		||||
    void setOwnerId(const uint64_t &pOwnerId) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column size  */
 | 
			
		||||
    ///Get the value of the column size, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfSize() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getSize() const noexcept;
 | 
			
		||||
    ///Set the value of the column size
 | 
			
		||||
    void setSize(const uint64_t &pSize) noexcept;
 | 
			
		||||
    void setSizeToNull() noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column has_preview  */
 | 
			
		||||
    ///Get the value of the column has_preview, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfHasPreview() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getHasPreview() const noexcept;
 | 
			
		||||
    ///Set the value of the column has_preview
 | 
			
		||||
    void setHasPreview(const uint64_t &pHasPreview) noexcept;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    static size_t getColumnNumber() noexcept {  return 7;  }
 | 
			
		||||
    static const std::string &getColumnName(size_t index) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    Json::Value toJson() const;
 | 
			
		||||
    Json::Value toMasqueradedJson(const std::vector<std::string> &pMasqueradingVector) const;
 | 
			
		||||
    /// Relationship interfaces
 | 
			
		||||
  private:
 | 
			
		||||
    friend drogon::orm::Mapper<Inode>;
 | 
			
		||||
#ifdef __cpp_impl_coroutine
 | 
			
		||||
    friend drogon::orm::CoroMapper<Inode>;
 | 
			
		||||
#endif
 | 
			
		||||
    static const std::vector<std::string> &insertColumns() noexcept;
 | 
			
		||||
    void outputArgs(drogon::orm::internal::SqlBinder &binder) const;
 | 
			
		||||
    const std::vector<std::string> updateColumns() const;
 | 
			
		||||
    void updateArgs(drogon::orm::internal::SqlBinder &binder) const;
 | 
			
		||||
    ///For mysql or sqlite3
 | 
			
		||||
    void updateId(const uint64_t id);
 | 
			
		||||
    std::shared_ptr<uint64_t> id_;
 | 
			
		||||
    std::shared_ptr<uint64_t> isFile_;
 | 
			
		||||
    std::shared_ptr<std::string> name_;
 | 
			
		||||
    std::shared_ptr<uint64_t> parentId_;
 | 
			
		||||
    std::shared_ptr<uint64_t> ownerId_;
 | 
			
		||||
    std::shared_ptr<uint64_t> size_;
 | 
			
		||||
    std::shared_ptr<uint64_t> hasPreview_;
 | 
			
		||||
    struct MetaData
 | 
			
		||||
    {
 | 
			
		||||
        const std::string colName_;
 | 
			
		||||
        const std::string colType_;
 | 
			
		||||
        const std::string colDatabaseType_;
 | 
			
		||||
        const ssize_t colLength_;
 | 
			
		||||
        const bool isAutoVal_;
 | 
			
		||||
        const bool isPrimaryKey_;
 | 
			
		||||
        const bool notNull_;
 | 
			
		||||
    };
 | 
			
		||||
    static const std::vector<MetaData> metaData_;
 | 
			
		||||
    bool dirtyFlag_[7]={ false };
 | 
			
		||||
  public:
 | 
			
		||||
    static const std::string &sqlForFindingByPrimaryKey()
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string sql="select * from " + tableName + " where id = ?";
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static const std::string &sqlForDeletingByPrimaryKey()
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string sql="delete from " + tableName + " where id = ?";
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
    std::string sqlForInserting(bool &needSelection) const
 | 
			
		||||
    {
 | 
			
		||||
        std::string sql="insert into " + tableName + " (";
 | 
			
		||||
        size_t parametersCount = 0;
 | 
			
		||||
        needSelection = false;
 | 
			
		||||
        if(dirtyFlag_[1])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "is_file,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[2])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "name,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[3])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "parent_id,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[4])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "owner_id,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[5])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "size,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[6])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "has_preview,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(parametersCount > 0)
 | 
			
		||||
        {
 | 
			
		||||
            sql[sql.length()-1]=')';
 | 
			
		||||
            sql += " values (";
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            sql += ") values (";
 | 
			
		||||
 | 
			
		||||
        if(dirtyFlag_[1])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[2])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[3])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[4])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[5])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[6])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(parametersCount > 0)
 | 
			
		||||
        {
 | 
			
		||||
            sql.resize(sql.length() - 1);
 | 
			
		||||
        }
 | 
			
		||||
        sql.append(1, ')');
 | 
			
		||||
        LOG_TRACE << sql;
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
} // namespace sqlite3
 | 
			
		||||
} // namespace drogon_model
 | 
			
		||||
							
								
								
									
										631
									
								
								backend/model/Tokens.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										631
									
								
								backend/model/Tokens.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,631 @@
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 *  Tokens.cc
 | 
			
		||||
 *  DO NOT EDIT. This file is generated by drogon_ctl
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "Tokens.h"
 | 
			
		||||
#include "drogon/utils/Utilities.h"
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
using namespace drogon;
 | 
			
		||||
using namespace drogon::orm;
 | 
			
		||||
using namespace drogon_model::sqlite3;
 | 
			
		||||
 | 
			
		||||
const std::string Tokens::Cols::_id = "id";
 | 
			
		||||
const std::string Tokens::Cols::_owner_id = "owner_id";
 | 
			
		||||
const std::string Tokens::Cols::_exp = "exp";
 | 
			
		||||
const std::string Tokens::primaryKeyName = "id";
 | 
			
		||||
const bool Tokens::hasPrimaryKey = true;
 | 
			
		||||
const std::string Tokens::tableName = "tokens";
 | 
			
		||||
 | 
			
		||||
const std::vector<typename Tokens::MetaData> Tokens::metaData_={
 | 
			
		||||
{"id","uint64_t","integer",8,1,1,1},
 | 
			
		||||
{"owner_id","uint64_t","integer",8,0,0,1},
 | 
			
		||||
{"exp","uint64_t","integer",8,0,0,1}
 | 
			
		||||
};
 | 
			
		||||
const std::string &Tokens::getColumnName(size_t index) noexcept(false)
 | 
			
		||||
{
 | 
			
		||||
    assert(index < metaData_.size());
 | 
			
		||||
    return metaData_[index].colName_;
 | 
			
		||||
}
 | 
			
		||||
Tokens::Tokens(const Row &r, const ssize_t indexOffset) noexcept
 | 
			
		||||
{
 | 
			
		||||
    if(indexOffset < 0)
 | 
			
		||||
    {
 | 
			
		||||
        if(!r["id"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            id_=std::make_shared<uint64_t>(r["id"].as<uint64_t>());
 | 
			
		||||
        }
 | 
			
		||||
        if(!r["owner_id"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            ownerId_=std::make_shared<uint64_t>(r["owner_id"].as<uint64_t>());
 | 
			
		||||
        }
 | 
			
		||||
        if(!r["exp"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            exp_=std::make_shared<uint64_t>(r["exp"].as<uint64_t>());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        size_t offset = (size_t)indexOffset;
 | 
			
		||||
        if(offset + 3 > r.size())
 | 
			
		||||
        {
 | 
			
		||||
            LOG_FATAL << "Invalid SQL result for this model";
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        size_t index;
 | 
			
		||||
        index = offset + 0;
 | 
			
		||||
        if(!r[index].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            id_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
 | 
			
		||||
        }
 | 
			
		||||
        index = offset + 1;
 | 
			
		||||
        if(!r[index].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            ownerId_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
 | 
			
		||||
        }
 | 
			
		||||
        index = offset + 2;
 | 
			
		||||
        if(!r[index].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            exp_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Tokens::Tokens(const Json::Value &pJson, const std::vector<std::string> &pMasqueradingVector) noexcept(false)
 | 
			
		||||
{
 | 
			
		||||
    if(pMasqueradingVector.size() != 3)
 | 
			
		||||
    {
 | 
			
		||||
        LOG_ERROR << "Bad masquerading vector";
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[0] = true;
 | 
			
		||||
        if(!pJson[pMasqueradingVector[0]].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            id_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[1] = true;
 | 
			
		||||
        if(!pJson[pMasqueradingVector[1]].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            ownerId_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[2] = true;
 | 
			
		||||
        if(!pJson[pMasqueradingVector[2]].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            exp_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[2]].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Tokens::Tokens(const Json::Value &pJson) noexcept(false)
 | 
			
		||||
{
 | 
			
		||||
    if(pJson.isMember("id"))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[0]=true;
 | 
			
		||||
        if(!pJson["id"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            id_=std::make_shared<uint64_t>((uint64_t)pJson["id"].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(pJson.isMember("owner_id"))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[1]=true;
 | 
			
		||||
        if(!pJson["owner_id"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            ownerId_=std::make_shared<uint64_t>((uint64_t)pJson["owner_id"].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(pJson.isMember("exp"))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[2]=true;
 | 
			
		||||
        if(!pJson["exp"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            exp_=std::make_shared<uint64_t>((uint64_t)pJson["exp"].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Tokens::updateByMasqueradedJson(const Json::Value &pJson,
 | 
			
		||||
                                            const std::vector<std::string> &pMasqueradingVector) noexcept(false)
 | 
			
		||||
{
 | 
			
		||||
    if(pMasqueradingVector.size() != 3)
 | 
			
		||||
    {
 | 
			
		||||
        LOG_ERROR << "Bad masquerading vector";
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
 | 
			
		||||
    {
 | 
			
		||||
        if(!pJson[pMasqueradingVector[0]].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            id_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[1] = true;
 | 
			
		||||
        if(!pJson[pMasqueradingVector[1]].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            ownerId_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[2] = true;
 | 
			
		||||
        if(!pJson[pMasqueradingVector[2]].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            exp_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[2]].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Tokens::updateByJson(const Json::Value &pJson) noexcept(false)
 | 
			
		||||
{
 | 
			
		||||
    if(pJson.isMember("id"))
 | 
			
		||||
    {
 | 
			
		||||
        if(!pJson["id"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            id_=std::make_shared<uint64_t>((uint64_t)pJson["id"].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(pJson.isMember("owner_id"))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[1] = true;
 | 
			
		||||
        if(!pJson["owner_id"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            ownerId_=std::make_shared<uint64_t>((uint64_t)pJson["owner_id"].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(pJson.isMember("exp"))
 | 
			
		||||
    {
 | 
			
		||||
        dirtyFlag_[2] = true;
 | 
			
		||||
        if(!pJson["exp"].isNull())
 | 
			
		||||
        {
 | 
			
		||||
            exp_=std::make_shared<uint64_t>((uint64_t)pJson["exp"].asUInt64());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const uint64_t &Tokens::getValueOfId() const noexcept
 | 
			
		||||
{
 | 
			
		||||
    const static uint64_t defaultValue = uint64_t();
 | 
			
		||||
    if(id_)
 | 
			
		||||
        return *id_;
 | 
			
		||||
    return defaultValue;
 | 
			
		||||
}
 | 
			
		||||
const std::shared_ptr<uint64_t> &Tokens::getId() const noexcept
 | 
			
		||||
{
 | 
			
		||||
    return id_;
 | 
			
		||||
}
 | 
			
		||||
void Tokens::setId(const uint64_t &pId) noexcept
 | 
			
		||||
{
 | 
			
		||||
    id_ = std::make_shared<uint64_t>(pId);
 | 
			
		||||
    dirtyFlag_[0] = true;
 | 
			
		||||
}
 | 
			
		||||
const typename Tokens::PrimaryKeyType & Tokens::getPrimaryKey() const
 | 
			
		||||
{
 | 
			
		||||
    assert(id_);
 | 
			
		||||
    return *id_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const uint64_t &Tokens::getValueOfOwnerId() const noexcept
 | 
			
		||||
{
 | 
			
		||||
    const static uint64_t defaultValue = uint64_t();
 | 
			
		||||
    if(ownerId_)
 | 
			
		||||
        return *ownerId_;
 | 
			
		||||
    return defaultValue;
 | 
			
		||||
}
 | 
			
		||||
const std::shared_ptr<uint64_t> &Tokens::getOwnerId() const noexcept
 | 
			
		||||
{
 | 
			
		||||
    return ownerId_;
 | 
			
		||||
}
 | 
			
		||||
void Tokens::setOwnerId(const uint64_t &pOwnerId) noexcept
 | 
			
		||||
{
 | 
			
		||||
    ownerId_ = std::make_shared<uint64_t>(pOwnerId);
 | 
			
		||||
    dirtyFlag_[1] = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const uint64_t &Tokens::getValueOfExp() const noexcept
 | 
			
		||||
{
 | 
			
		||||
    const static uint64_t defaultValue = uint64_t();
 | 
			
		||||
    if(exp_)
 | 
			
		||||
        return *exp_;
 | 
			
		||||
    return defaultValue;
 | 
			
		||||
}
 | 
			
		||||
const std::shared_ptr<uint64_t> &Tokens::getExp() const noexcept
 | 
			
		||||
{
 | 
			
		||||
    return exp_;
 | 
			
		||||
}
 | 
			
		||||
void Tokens::setExp(const uint64_t &pExp) noexcept
 | 
			
		||||
{
 | 
			
		||||
    exp_ = std::make_shared<uint64_t>(pExp);
 | 
			
		||||
    dirtyFlag_[2] = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Tokens::updateId(const uint64_t id)
 | 
			
		||||
{
 | 
			
		||||
    id_ = std::make_shared<uint64_t>(id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const std::vector<std::string> &Tokens::insertColumns() noexcept
 | 
			
		||||
{
 | 
			
		||||
    static const std::vector<std::string> inCols={
 | 
			
		||||
        "owner_id",
 | 
			
		||||
        "exp"
 | 
			
		||||
    };
 | 
			
		||||
    return inCols;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Tokens::outputArgs(drogon::orm::internal::SqlBinder &binder) const
 | 
			
		||||
{
 | 
			
		||||
    if(dirtyFlag_[1])
 | 
			
		||||
    {
 | 
			
		||||
        if(getOwnerId())
 | 
			
		||||
        {
 | 
			
		||||
            binder << getValueOfOwnerId();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            binder << nullptr;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(dirtyFlag_[2])
 | 
			
		||||
    {
 | 
			
		||||
        if(getExp())
 | 
			
		||||
        {
 | 
			
		||||
            binder << getValueOfExp();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            binder << nullptr;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const std::vector<std::string> Tokens::updateColumns() const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> ret;
 | 
			
		||||
    if(dirtyFlag_[1])
 | 
			
		||||
    {
 | 
			
		||||
        ret.push_back(getColumnName(1));
 | 
			
		||||
    }
 | 
			
		||||
    if(dirtyFlag_[2])
 | 
			
		||||
    {
 | 
			
		||||
        ret.push_back(getColumnName(2));
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Tokens::updateArgs(drogon::orm::internal::SqlBinder &binder) const
 | 
			
		||||
{
 | 
			
		||||
    if(dirtyFlag_[1])
 | 
			
		||||
    {
 | 
			
		||||
        if(getOwnerId())
 | 
			
		||||
        {
 | 
			
		||||
            binder << getValueOfOwnerId();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            binder << nullptr;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(dirtyFlag_[2])
 | 
			
		||||
    {
 | 
			
		||||
        if(getExp())
 | 
			
		||||
        {
 | 
			
		||||
            binder << getValueOfExp();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            binder << nullptr;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
Json::Value Tokens::toJson() const
 | 
			
		||||
{
 | 
			
		||||
    Json::Value ret;
 | 
			
		||||
    if(getId())
 | 
			
		||||
    {
 | 
			
		||||
        ret["id"]=(Json::UInt64)getValueOfId();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ret["id"]=Json::Value();
 | 
			
		||||
    }
 | 
			
		||||
    if(getOwnerId())
 | 
			
		||||
    {
 | 
			
		||||
        ret["owner_id"]=(Json::UInt64)getValueOfOwnerId();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ret["owner_id"]=Json::Value();
 | 
			
		||||
    }
 | 
			
		||||
    if(getExp())
 | 
			
		||||
    {
 | 
			
		||||
        ret["exp"]=(Json::UInt64)getValueOfExp();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ret["exp"]=Json::Value();
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Json::Value Tokens::toMasqueradedJson(
 | 
			
		||||
    const std::vector<std::string> &pMasqueradingVector) const
 | 
			
		||||
{
 | 
			
		||||
    Json::Value ret;
 | 
			
		||||
    if(pMasqueradingVector.size() == 3)
 | 
			
		||||
    {
 | 
			
		||||
        if(!pMasqueradingVector[0].empty())
 | 
			
		||||
        {
 | 
			
		||||
            if(getId())
 | 
			
		||||
            {
 | 
			
		||||
                ret[pMasqueradingVector[0]]=(Json::UInt64)getValueOfId();
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                ret[pMasqueradingVector[0]]=Json::Value();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if(!pMasqueradingVector[1].empty())
 | 
			
		||||
        {
 | 
			
		||||
            if(getOwnerId())
 | 
			
		||||
            {
 | 
			
		||||
                ret[pMasqueradingVector[1]]=(Json::UInt64)getValueOfOwnerId();
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                ret[pMasqueradingVector[1]]=Json::Value();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if(!pMasqueradingVector[2].empty())
 | 
			
		||||
        {
 | 
			
		||||
            if(getExp())
 | 
			
		||||
            {
 | 
			
		||||
                ret[pMasqueradingVector[2]]=(Json::UInt64)getValueOfExp();
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                ret[pMasqueradingVector[2]]=Json::Value();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
    LOG_ERROR << "Masquerade failed";
 | 
			
		||||
    if(getId())
 | 
			
		||||
    {
 | 
			
		||||
        ret["id"]=(Json::UInt64)getValueOfId();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ret["id"]=Json::Value();
 | 
			
		||||
    }
 | 
			
		||||
    if(getOwnerId())
 | 
			
		||||
    {
 | 
			
		||||
        ret["owner_id"]=(Json::UInt64)getValueOfOwnerId();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ret["owner_id"]=Json::Value();
 | 
			
		||||
    }
 | 
			
		||||
    if(getExp())
 | 
			
		||||
    {
 | 
			
		||||
        ret["exp"]=(Json::UInt64)getValueOfExp();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ret["exp"]=Json::Value();
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Tokens::validateJsonForCreation(const Json::Value &pJson, std::string &err)
 | 
			
		||||
{
 | 
			
		||||
    if(pJson.isMember("id"))
 | 
			
		||||
    {
 | 
			
		||||
        if(!validJsonOfField(0, "id", pJson["id"], err, true))
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
    if(pJson.isMember("owner_id"))
 | 
			
		||||
    {
 | 
			
		||||
        if(!validJsonOfField(1, "owner_id", pJson["owner_id"], err, true))
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        err="The owner_id column cannot be null";
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if(pJson.isMember("exp"))
 | 
			
		||||
    {
 | 
			
		||||
        if(!validJsonOfField(2, "exp", pJson["exp"], err, true))
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        err="The exp column cannot be null";
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
bool Tokens::validateMasqueradedJsonForCreation(const Json::Value &pJson,
 | 
			
		||||
                                                const std::vector<std::string> &pMasqueradingVector,
 | 
			
		||||
                                                std::string &err)
 | 
			
		||||
{
 | 
			
		||||
    if(pMasqueradingVector.size() != 3)
 | 
			
		||||
    {
 | 
			
		||||
        err = "Bad masquerading vector";
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
      if(!pMasqueradingVector[0].empty())
 | 
			
		||||
      {
 | 
			
		||||
          if(pJson.isMember(pMasqueradingVector[0]))
 | 
			
		||||
          {
 | 
			
		||||
              if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, true))
 | 
			
		||||
                  return false;
 | 
			
		||||
          }
 | 
			
		||||
      }
 | 
			
		||||
      if(!pMasqueradingVector[1].empty())
 | 
			
		||||
      {
 | 
			
		||||
          if(pJson.isMember(pMasqueradingVector[1]))
 | 
			
		||||
          {
 | 
			
		||||
              if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, true))
 | 
			
		||||
                  return false;
 | 
			
		||||
          }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            err="The " + pMasqueradingVector[1] + " column cannot be null";
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if(!pMasqueradingVector[2].empty())
 | 
			
		||||
      {
 | 
			
		||||
          if(pJson.isMember(pMasqueradingVector[2]))
 | 
			
		||||
          {
 | 
			
		||||
              if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, true))
 | 
			
		||||
                  return false;
 | 
			
		||||
          }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            err="The " + pMasqueradingVector[2] + " column cannot be null";
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(const Json::LogicError &e)
 | 
			
		||||
    {
 | 
			
		||||
      err = e.what();
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
bool Tokens::validateJsonForUpdate(const Json::Value &pJson, std::string &err)
 | 
			
		||||
{
 | 
			
		||||
    if(pJson.isMember("id"))
 | 
			
		||||
    {
 | 
			
		||||
        if(!validJsonOfField(0, "id", pJson["id"], err, false))
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        err = "The value of primary key must be set in the json object for update";
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if(pJson.isMember("owner_id"))
 | 
			
		||||
    {
 | 
			
		||||
        if(!validJsonOfField(1, "owner_id", pJson["owner_id"], err, false))
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
    if(pJson.isMember("exp"))
 | 
			
		||||
    {
 | 
			
		||||
        if(!validJsonOfField(2, "exp", pJson["exp"], err, false))
 | 
			
		||||
            return false;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
bool Tokens::validateMasqueradedJsonForUpdate(const Json::Value &pJson,
 | 
			
		||||
                                              const std::vector<std::string> &pMasqueradingVector,
 | 
			
		||||
                                              std::string &err)
 | 
			
		||||
{
 | 
			
		||||
    if(pMasqueradingVector.size() != 3)
 | 
			
		||||
    {
 | 
			
		||||
        err = "Bad masquerading vector";
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
      if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
 | 
			
		||||
      {
 | 
			
		||||
          if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, false))
 | 
			
		||||
              return false;
 | 
			
		||||
      }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        err = "The value of primary key must be set in the json object for update";
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
      if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
 | 
			
		||||
      {
 | 
			
		||||
          if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, false))
 | 
			
		||||
              return false;
 | 
			
		||||
      }
 | 
			
		||||
      if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
 | 
			
		||||
      {
 | 
			
		||||
          if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, false))
 | 
			
		||||
              return false;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(const Json::LogicError &e)
 | 
			
		||||
    {
 | 
			
		||||
      err = e.what();
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
bool Tokens::validJsonOfField(size_t index,
 | 
			
		||||
                              const std::string &fieldName,
 | 
			
		||||
                              const Json::Value &pJson,
 | 
			
		||||
                              std::string &err,
 | 
			
		||||
                              bool isForCreation)
 | 
			
		||||
{
 | 
			
		||||
    switch(index)
 | 
			
		||||
    {
 | 
			
		||||
        case 0:
 | 
			
		||||
            if(pJson.isNull())
 | 
			
		||||
            {
 | 
			
		||||
                err="The " + fieldName + " column cannot be null";
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if(isForCreation)
 | 
			
		||||
            {
 | 
			
		||||
                err="The automatic primary key cannot be set";
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if(!pJson.isUInt64())
 | 
			
		||||
            {
 | 
			
		||||
                err="Type error in the "+fieldName+" field";
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case 1:
 | 
			
		||||
            if(pJson.isNull())
 | 
			
		||||
            {
 | 
			
		||||
                err="The " + fieldName + " column cannot be null";
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if(!pJson.isUInt64())
 | 
			
		||||
            {
 | 
			
		||||
                err="Type error in the "+fieldName+" field";
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case 2:
 | 
			
		||||
            if(pJson.isNull())
 | 
			
		||||
            {
 | 
			
		||||
                err="The " + fieldName + " column cannot be null";
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if(!pJson.isUInt64())
 | 
			
		||||
            {
 | 
			
		||||
                err="Type error in the "+fieldName+" field";
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            err="Internal error in the server";
 | 
			
		||||
            return false;
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										211
									
								
								backend/model/Tokens.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										211
									
								
								backend/model/Tokens.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,211 @@
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 *  Tokens.h
 | 
			
		||||
 *  DO NOT EDIT. This file is generated by drogon_ctl
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "drogon/orm/Result.h"
 | 
			
		||||
#include "drogon/orm/Row.h"
 | 
			
		||||
#include "drogon/orm/Field.h"
 | 
			
		||||
#include "drogon/orm/SqlBinder.h"
 | 
			
		||||
#include "drogon/orm/Mapper.h"
 | 
			
		||||
#ifdef __cpp_impl_coroutine
 | 
			
		||||
#include <drogon/orm/CoroMapper.h>
 | 
			
		||||
#endif
 | 
			
		||||
#include "trantor/utils/Date.h"
 | 
			
		||||
#include "trantor/utils/Logger.h"
 | 
			
		||||
#include "json/json.h"
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <tuple>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
namespace drogon
 | 
			
		||||
{
 | 
			
		||||
namespace orm
 | 
			
		||||
{
 | 
			
		||||
class DbClient;
 | 
			
		||||
using DbClientPtr = std::shared_ptr<DbClient>;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
namespace drogon_model
 | 
			
		||||
{
 | 
			
		||||
namespace sqlite3
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class Tokens
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    struct Cols
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string _id;
 | 
			
		||||
        static const std::string _owner_id;
 | 
			
		||||
        static const std::string _exp;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const static int primaryKeyNumber;
 | 
			
		||||
    const static std::string tableName;
 | 
			
		||||
    const static bool hasPrimaryKey;
 | 
			
		||||
    const static std::string primaryKeyName;
 | 
			
		||||
    using PrimaryKeyType = uint64_t;
 | 
			
		||||
    const PrimaryKeyType &getPrimaryKey() const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param r One row of records in the SQL query result.
 | 
			
		||||
     * @param indexOffset Set the offset to -1 to access all columns by column names,
 | 
			
		||||
     * otherwise access all columns by offsets.
 | 
			
		||||
     * @note If the SQL is not a style of 'select * from table_name ...' (select all
 | 
			
		||||
     * columns by an asterisk), please set the offset to -1.
 | 
			
		||||
     */
 | 
			
		||||
    explicit Tokens(const drogon::orm::Row &r, const ssize_t indexOffset = 0) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param pJson The json object to construct a new instance.
 | 
			
		||||
     */
 | 
			
		||||
    explicit Tokens(const Json::Value &pJson) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param pJson The json object to construct a new instance.
 | 
			
		||||
     * @param pMasqueradingVector The aliases of table columns.
 | 
			
		||||
     */
 | 
			
		||||
    Tokens(const Json::Value &pJson, const std::vector<std::string> &pMasqueradingVector) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    Tokens() = default;
 | 
			
		||||
 | 
			
		||||
    void updateByJson(const Json::Value &pJson) noexcept(false);
 | 
			
		||||
    void updateByMasqueradedJson(const Json::Value &pJson,
 | 
			
		||||
                                 const std::vector<std::string> &pMasqueradingVector) noexcept(false);
 | 
			
		||||
    static bool validateJsonForCreation(const Json::Value &pJson, std::string &err);
 | 
			
		||||
    static bool validateMasqueradedJsonForCreation(const Json::Value &,
 | 
			
		||||
                                                const std::vector<std::string> &pMasqueradingVector,
 | 
			
		||||
                                                    std::string &err);
 | 
			
		||||
    static bool validateJsonForUpdate(const Json::Value &pJson, std::string &err);
 | 
			
		||||
    static bool validateMasqueradedJsonForUpdate(const Json::Value &,
 | 
			
		||||
                                          const std::vector<std::string> &pMasqueradingVector,
 | 
			
		||||
                                          std::string &err);
 | 
			
		||||
    static bool validJsonOfField(size_t index,
 | 
			
		||||
                          const std::string &fieldName,
 | 
			
		||||
                          const Json::Value &pJson,
 | 
			
		||||
                          std::string &err,
 | 
			
		||||
                          bool isForCreation);
 | 
			
		||||
 | 
			
		||||
    /**  For column id  */
 | 
			
		||||
    ///Get the value of the column id, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfId() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getId() const noexcept;
 | 
			
		||||
    ///Set the value of the column id
 | 
			
		||||
    void setId(const uint64_t &pId) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column owner_id  */
 | 
			
		||||
    ///Get the value of the column owner_id, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfOwnerId() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getOwnerId() const noexcept;
 | 
			
		||||
    ///Set the value of the column owner_id
 | 
			
		||||
    void setOwnerId(const uint64_t &pOwnerId) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column exp  */
 | 
			
		||||
    ///Get the value of the column exp, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfExp() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getExp() const noexcept;
 | 
			
		||||
    ///Set the value of the column exp
 | 
			
		||||
    void setExp(const uint64_t &pExp) noexcept;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    static size_t getColumnNumber() noexcept {  return 3;  }
 | 
			
		||||
    static const std::string &getColumnName(size_t index) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    Json::Value toJson() const;
 | 
			
		||||
    Json::Value toMasqueradedJson(const std::vector<std::string> &pMasqueradingVector) const;
 | 
			
		||||
    /// Relationship interfaces
 | 
			
		||||
  private:
 | 
			
		||||
    friend drogon::orm::Mapper<Tokens>;
 | 
			
		||||
#ifdef __cpp_impl_coroutine
 | 
			
		||||
    friend drogon::orm::CoroMapper<Tokens>;
 | 
			
		||||
#endif
 | 
			
		||||
    static const std::vector<std::string> &insertColumns() noexcept;
 | 
			
		||||
    void outputArgs(drogon::orm::internal::SqlBinder &binder) const;
 | 
			
		||||
    const std::vector<std::string> updateColumns() const;
 | 
			
		||||
    void updateArgs(drogon::orm::internal::SqlBinder &binder) const;
 | 
			
		||||
    ///For mysql or sqlite3
 | 
			
		||||
    void updateId(const uint64_t id);
 | 
			
		||||
    std::shared_ptr<uint64_t> id_;
 | 
			
		||||
    std::shared_ptr<uint64_t> ownerId_;
 | 
			
		||||
    std::shared_ptr<uint64_t> exp_;
 | 
			
		||||
    struct MetaData
 | 
			
		||||
    {
 | 
			
		||||
        const std::string colName_;
 | 
			
		||||
        const std::string colType_;
 | 
			
		||||
        const std::string colDatabaseType_;
 | 
			
		||||
        const ssize_t colLength_;
 | 
			
		||||
        const bool isAutoVal_;
 | 
			
		||||
        const bool isPrimaryKey_;
 | 
			
		||||
        const bool notNull_;
 | 
			
		||||
    };
 | 
			
		||||
    static const std::vector<MetaData> metaData_;
 | 
			
		||||
    bool dirtyFlag_[3]={ false };
 | 
			
		||||
  public:
 | 
			
		||||
    static const std::string &sqlForFindingByPrimaryKey()
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string sql="select * from " + tableName + " where id = ?";
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static const std::string &sqlForDeletingByPrimaryKey()
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string sql="delete from " + tableName + " where id = ?";
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
    std::string sqlForInserting(bool &needSelection) const
 | 
			
		||||
    {
 | 
			
		||||
        std::string sql="insert into " + tableName + " (";
 | 
			
		||||
        size_t parametersCount = 0;
 | 
			
		||||
        needSelection = false;
 | 
			
		||||
        if(dirtyFlag_[1])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "owner_id,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[2])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "exp,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(parametersCount > 0)
 | 
			
		||||
        {
 | 
			
		||||
            sql[sql.length()-1]=')';
 | 
			
		||||
            sql += " values (";
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            sql += ") values (";
 | 
			
		||||
 | 
			
		||||
        if(dirtyFlag_[1])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[2])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(parametersCount > 0)
 | 
			
		||||
        {
 | 
			
		||||
            sql.resize(sql.length() - 1);
 | 
			
		||||
        }
 | 
			
		||||
        sql.append(1, ')');
 | 
			
		||||
        LOG_TRACE << sql;
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
} // namespace sqlite3
 | 
			
		||||
} // namespace drogon_model
 | 
			
		||||
							
								
								
									
										1762
									
								
								backend/model/User.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1762
									
								
								backend/model/User.cc
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										361
									
								
								backend/model/User.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										361
									
								
								backend/model/User.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,361 @@
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 *  User.h
 | 
			
		||||
 *  DO NOT EDIT. This file is generated by drogon_ctl
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "drogon/orm/Result.h"
 | 
			
		||||
#include "drogon/orm/Row.h"
 | 
			
		||||
#include "drogon/orm/Field.h"
 | 
			
		||||
#include "drogon/orm/SqlBinder.h"
 | 
			
		||||
#include "drogon/orm/Mapper.h"
 | 
			
		||||
#ifdef __cpp_impl_coroutine
 | 
			
		||||
#include <drogon/orm/CoroMapper.h>
 | 
			
		||||
#endif
 | 
			
		||||
#include "trantor/utils/Date.h"
 | 
			
		||||
#include "trantor/utils/Logger.h"
 | 
			
		||||
#include "json/json.h"
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <tuple>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
namespace drogon
 | 
			
		||||
{
 | 
			
		||||
namespace orm
 | 
			
		||||
{
 | 
			
		||||
class DbClient;
 | 
			
		||||
using DbClientPtr = std::shared_ptr<DbClient>;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
namespace drogon_model
 | 
			
		||||
{
 | 
			
		||||
namespace sqlite3
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class User
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    struct Cols
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string _id;
 | 
			
		||||
        static const std::string _gitlab;
 | 
			
		||||
        static const std::string _name;
 | 
			
		||||
        static const std::string _password;
 | 
			
		||||
        static const std::string _role;
 | 
			
		||||
        static const std::string _root_id;
 | 
			
		||||
        static const std::string _tfa_type;
 | 
			
		||||
        static const std::string _tfa_secret;
 | 
			
		||||
        static const std::string _gitlab_at;
 | 
			
		||||
        static const std::string _gitlab_rt;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const static int primaryKeyNumber;
 | 
			
		||||
    const static std::string tableName;
 | 
			
		||||
    const static bool hasPrimaryKey;
 | 
			
		||||
    const static std::string primaryKeyName;
 | 
			
		||||
    using PrimaryKeyType = uint64_t;
 | 
			
		||||
    const PrimaryKeyType &getPrimaryKey() const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param r One row of records in the SQL query result.
 | 
			
		||||
     * @param indexOffset Set the offset to -1 to access all columns by column names,
 | 
			
		||||
     * otherwise access all columns by offsets.
 | 
			
		||||
     * @note If the SQL is not a style of 'select * from table_name ...' (select all
 | 
			
		||||
     * columns by an asterisk), please set the offset to -1.
 | 
			
		||||
     */
 | 
			
		||||
    explicit User(const drogon::orm::Row &r, const ssize_t indexOffset = 0) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param pJson The json object to construct a new instance.
 | 
			
		||||
     */
 | 
			
		||||
    explicit User(const Json::Value &pJson) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief constructor
 | 
			
		||||
     * @param pJson The json object to construct a new instance.
 | 
			
		||||
     * @param pMasqueradingVector The aliases of table columns.
 | 
			
		||||
     */
 | 
			
		||||
    User(const Json::Value &pJson, const std::vector<std::string> &pMasqueradingVector) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    User() = default;
 | 
			
		||||
 | 
			
		||||
    void updateByJson(const Json::Value &pJson) noexcept(false);
 | 
			
		||||
    void updateByMasqueradedJson(const Json::Value &pJson,
 | 
			
		||||
                                 const std::vector<std::string> &pMasqueradingVector) noexcept(false);
 | 
			
		||||
    static bool validateJsonForCreation(const Json::Value &pJson, std::string &err);
 | 
			
		||||
    static bool validateMasqueradedJsonForCreation(const Json::Value &,
 | 
			
		||||
                                                const std::vector<std::string> &pMasqueradingVector,
 | 
			
		||||
                                                    std::string &err);
 | 
			
		||||
    static bool validateJsonForUpdate(const Json::Value &pJson, std::string &err);
 | 
			
		||||
    static bool validateMasqueradedJsonForUpdate(const Json::Value &,
 | 
			
		||||
                                          const std::vector<std::string> &pMasqueradingVector,
 | 
			
		||||
                                          std::string &err);
 | 
			
		||||
    static bool validJsonOfField(size_t index,
 | 
			
		||||
                          const std::string &fieldName,
 | 
			
		||||
                          const Json::Value &pJson,
 | 
			
		||||
                          std::string &err,
 | 
			
		||||
                          bool isForCreation);
 | 
			
		||||
 | 
			
		||||
    /**  For column id  */
 | 
			
		||||
    ///Get the value of the column id, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfId() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getId() const noexcept;
 | 
			
		||||
    ///Set the value of the column id
 | 
			
		||||
    void setId(const uint64_t &pId) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column gitlab  */
 | 
			
		||||
    ///Get the value of the column gitlab, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfGitlab() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getGitlab() const noexcept;
 | 
			
		||||
    ///Set the value of the column gitlab
 | 
			
		||||
    void setGitlab(const uint64_t &pGitlab) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column name  */
 | 
			
		||||
    ///Get the value of the column name, returns the default value if the column is null
 | 
			
		||||
    const std::string &getValueOfName() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<std::string> &getName() const noexcept;
 | 
			
		||||
    ///Set the value of the column name
 | 
			
		||||
    void setName(const std::string &pName) noexcept;
 | 
			
		||||
    void setName(std::string &&pName) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column password  */
 | 
			
		||||
    ///Get the value of the column password, returns the default value if the column is null
 | 
			
		||||
    const std::string &getValueOfPassword() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<std::string> &getPassword() const noexcept;
 | 
			
		||||
    ///Set the value of the column password
 | 
			
		||||
    void setPassword(const std::string &pPassword) noexcept;
 | 
			
		||||
    void setPassword(std::string &&pPassword) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column role  */
 | 
			
		||||
    ///Get the value of the column role, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfRole() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getRole() const noexcept;
 | 
			
		||||
    ///Set the value of the column role
 | 
			
		||||
    void setRole(const uint64_t &pRole) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column root_id  */
 | 
			
		||||
    ///Get the value of the column root_id, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfRootId() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getRootId() const noexcept;
 | 
			
		||||
    ///Set the value of the column root_id
 | 
			
		||||
    void setRootId(const uint64_t &pRootId) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column tfa_type  */
 | 
			
		||||
    ///Get the value of the column tfa_type, returns the default value if the column is null
 | 
			
		||||
    const uint64_t &getValueOfTfaType() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<uint64_t> &getTfaType() const noexcept;
 | 
			
		||||
    ///Set the value of the column tfa_type
 | 
			
		||||
    void setTfaType(const uint64_t &pTfaType) noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column tfa_secret  */
 | 
			
		||||
    ///Get the value of the column tfa_secret, returns the default value if the column is null
 | 
			
		||||
    const std::vector<char> &getValueOfTfaSecret() const noexcept;
 | 
			
		||||
    ///Return the column value by std::string with binary data
 | 
			
		||||
    std::string getValueOfTfaSecretAsString() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<std::vector<char>> &getTfaSecret() const noexcept;
 | 
			
		||||
    ///Set the value of the column tfa_secret
 | 
			
		||||
    void setTfaSecret(const std::vector<char> &pTfaSecret) noexcept;
 | 
			
		||||
    void setTfaSecret(const std::string &pTfaSecret) noexcept;
 | 
			
		||||
    void setTfaSecretToNull() noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column gitlab_at  */
 | 
			
		||||
    ///Get the value of the column gitlab_at, returns the default value if the column is null
 | 
			
		||||
    const std::string &getValueOfGitlabAt() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<std::string> &getGitlabAt() const noexcept;
 | 
			
		||||
    ///Set the value of the column gitlab_at
 | 
			
		||||
    void setGitlabAt(const std::string &pGitlabAt) noexcept;
 | 
			
		||||
    void setGitlabAt(std::string &&pGitlabAt) noexcept;
 | 
			
		||||
    void setGitlabAtToNull() noexcept;
 | 
			
		||||
 | 
			
		||||
    /**  For column gitlab_rt  */
 | 
			
		||||
    ///Get the value of the column gitlab_rt, returns the default value if the column is null
 | 
			
		||||
    const std::string &getValueOfGitlabRt() const noexcept;
 | 
			
		||||
    ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
 | 
			
		||||
    const std::shared_ptr<std::string> &getGitlabRt() const noexcept;
 | 
			
		||||
    ///Set the value of the column gitlab_rt
 | 
			
		||||
    void setGitlabRt(const std::string &pGitlabRt) noexcept;
 | 
			
		||||
    void setGitlabRt(std::string &&pGitlabRt) noexcept;
 | 
			
		||||
    void setGitlabRtToNull() noexcept;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    static size_t getColumnNumber() noexcept {  return 10;  }
 | 
			
		||||
    static const std::string &getColumnName(size_t index) noexcept(false);
 | 
			
		||||
 | 
			
		||||
    Json::Value toJson() const;
 | 
			
		||||
    Json::Value toMasqueradedJson(const std::vector<std::string> &pMasqueradingVector) const;
 | 
			
		||||
    /// Relationship interfaces
 | 
			
		||||
  private:
 | 
			
		||||
    friend drogon::orm::Mapper<User>;
 | 
			
		||||
#ifdef __cpp_impl_coroutine
 | 
			
		||||
    friend drogon::orm::CoroMapper<User>;
 | 
			
		||||
#endif
 | 
			
		||||
    static const std::vector<std::string> &insertColumns() noexcept;
 | 
			
		||||
    void outputArgs(drogon::orm::internal::SqlBinder &binder) const;
 | 
			
		||||
    const std::vector<std::string> updateColumns() const;
 | 
			
		||||
    void updateArgs(drogon::orm::internal::SqlBinder &binder) const;
 | 
			
		||||
    ///For mysql or sqlite3
 | 
			
		||||
    void updateId(const uint64_t id);
 | 
			
		||||
    std::shared_ptr<uint64_t> id_;
 | 
			
		||||
    std::shared_ptr<uint64_t> gitlab_;
 | 
			
		||||
    std::shared_ptr<std::string> name_;
 | 
			
		||||
    std::shared_ptr<std::string> password_;
 | 
			
		||||
    std::shared_ptr<uint64_t> role_;
 | 
			
		||||
    std::shared_ptr<uint64_t> rootId_;
 | 
			
		||||
    std::shared_ptr<uint64_t> tfaType_;
 | 
			
		||||
    std::shared_ptr<std::vector<char>> tfaSecret_;
 | 
			
		||||
    std::shared_ptr<std::string> gitlabAt_;
 | 
			
		||||
    std::shared_ptr<std::string> gitlabRt_;
 | 
			
		||||
    struct MetaData
 | 
			
		||||
    {
 | 
			
		||||
        const std::string colName_;
 | 
			
		||||
        const std::string colType_;
 | 
			
		||||
        const std::string colDatabaseType_;
 | 
			
		||||
        const ssize_t colLength_;
 | 
			
		||||
        const bool isAutoVal_;
 | 
			
		||||
        const bool isPrimaryKey_;
 | 
			
		||||
        const bool notNull_;
 | 
			
		||||
    };
 | 
			
		||||
    static const std::vector<MetaData> metaData_;
 | 
			
		||||
    bool dirtyFlag_[10]={ false };
 | 
			
		||||
  public:
 | 
			
		||||
    static const std::string &sqlForFindingByPrimaryKey()
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string sql="select * from " + tableName + " where id = ?";
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static const std::string &sqlForDeletingByPrimaryKey()
 | 
			
		||||
    {
 | 
			
		||||
        static const std::string sql="delete from " + tableName + " where id = ?";
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
    std::string sqlForInserting(bool &needSelection) const
 | 
			
		||||
    {
 | 
			
		||||
        std::string sql="insert into " + tableName + " (";
 | 
			
		||||
        size_t parametersCount = 0;
 | 
			
		||||
        needSelection = false;
 | 
			
		||||
        if(dirtyFlag_[1])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "gitlab,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[2])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "name,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[3])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "password,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[4])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "role,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[5])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "root_id,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[6])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "tfa_type,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[7])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "tfa_secret,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[8])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "gitlab_at,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[9])
 | 
			
		||||
        {
 | 
			
		||||
            sql += "gitlab_rt,";
 | 
			
		||||
            ++parametersCount;
 | 
			
		||||
        }
 | 
			
		||||
        if(parametersCount > 0)
 | 
			
		||||
        {
 | 
			
		||||
            sql[sql.length()-1]=')';
 | 
			
		||||
            sql += " values (";
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            sql += ") values (";
 | 
			
		||||
 | 
			
		||||
        if(dirtyFlag_[1])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[2])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[3])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[4])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[5])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[6])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[7])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[8])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(dirtyFlag_[9])
 | 
			
		||||
        {
 | 
			
		||||
            sql.append("?,");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        if(parametersCount > 0)
 | 
			
		||||
        {
 | 
			
		||||
            sql.resize(sql.length() - 1);
 | 
			
		||||
        }
 | 
			
		||||
        sql.append(1, ')');
 | 
			
		||||
        LOG_TRACE << sql;
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
} // namespace sqlite3
 | 
			
		||||
} // namespace drogon_model
 | 
			
		||||
							
								
								
									
										5
									
								
								backend/model/model.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								backend/model/model.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
  "rdbms":"sqlite3",
 | 
			
		||||
  "filename":"run/sqlite.db",
 | 
			
		||||
  "tables":[]
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user