1. add upload issue comment info function

2. add query issue comment latest info function
3. add query issue comment all info function
This commit is contained in:
sulenn 2021-05-12 22:44:32 +08:00
parent 208dbbeb13
commit b2fb44c544
11 changed files with 319 additions and 8 deletions

View File

@ -8,5 +8,5 @@ var (
RepoCurBalanceDownOverFlow int64 = -1005 // 当前项目总 Token 数低于0
UserBblanceNotEnough int64 = -1006 // 用户余额不足
ContractAddress string = "0x5Bf5c94F6841581047A93477526D9A84c8bfedb6"
ContractAddress string = "0x481D3A1dcD72cD618Ea768b3FbF69D78B46995b0"
)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,7 @@ contract OpenSource {
// the parameters of createTable are tableName,keyField,"vlaueFiled1,vlaueFiled2,vlaueFiled3,..."
tableFactory.createTable(REPO_TABLE, "token_name", "owner,total_supply,cur_supply");
tableFactory.createTable(USER_TABLE, "user", "token_name,balance");
tableFactory.createTable(COMMIT_TABLE, "commit_hash", "repo_id,author,email,time,content,commit_diff");
tableFactory.createTable(COMMIT_TABLE, "commit_hash", "content");
tableFactory.createTable(PUSH_TABLE, "push_id", "push_number,repo_id,reponame,ownername,username,branch,commit_shas,time");
tableFactory.createTable(PULL_REQUEST_TABLE, "pull_request_id", "content");
tableFactory.createTable(PULL_REQUEST_COMMENT_TABLE, "pull_request_comment_id", "content");
@ -591,7 +591,7 @@ contract OpenSource {
}
// select issue comment latest info
function selectIssueInfo(string memory issue_comment_id)
function selectIssueCommentInfo(string memory issue_comment_id)
public
view
returns (string memory, string memory)
@ -607,7 +607,7 @@ contract OpenSource {
}
// select issue comment all info
function selectIssueAllInfo(string memory issue_comment_id)
function selectIssueCommentAllInfo(string memory issue_comment_id)
public
view
returns (string[] memory, string[] memory)

View File

@ -53,6 +53,11 @@ type FiscoBcos struct {
IssueNumber uint64 `json:"issue_number"`
// repo_id, reponame, ownername, action, title, content, created_at, updated_at
// repo issue comment 相关
IssueCommentID string `json:"issue_comment_id"`
IssueCommentNumber uint64 `json:"issue_comment_number"`
// issue_number, repo_id, parent_id, reponame, ownername, username, action, content, created_at, updated_at
// user 相关
Username string `json:"username"` // 用户名
Amount uint64 `json:"amount"` // 转账金额

View File

@ -0,0 +1,28 @@
package structs
type UploadIssueCommentOption struct {
IssueCommentID string `json:"issue_comment_id"`
IssueCommentNumber uint64 `json:"issue_comment_number"`
IssueNumber uint64 `json:"issue_number"`
RepoID string `json:"repo_id"`
ParentID string `json:"parent_id"`
Reponame string `json:"reponame"`
Ownername string `json:"ownername"`
Username string `json:"username"`
Action string `json:"action"`
Content string `json:"content"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
type ResponseIssueComment struct {
UploadIssueCommentOption
Response
}
type ResponseIssueCommentArr struct {
UploadIssueCommentOptionArr
Response
}
type UploadIssueCommentOptionArr []UploadIssueCommentOption

View File

@ -26,6 +26,8 @@ var (
ResPullRequestCommentUploadUnsucc = &Response{Status: 10, Message: "pull request comment upload unsuccessfully!"}
ResIssueUploadSucc = &Response{Status: 0, Message: "issue upload successfully!"}
ResIssueUploadUnsucc = &Response{Status: 10, Message: "issue upload unsuccessfully!"}
ResIssueCommentUploadSucc = &Response{Status: 0, Message: "issue comment upload successfully!"}
ResIssueCommentUploadUnsucc = &Response{Status: 10, Message: "issue comment upload unsuccessfully!"}
ResUserNotExisted = &Response{Status: 100, Message: "user not exist!"}
ResUserAddAmountSucc = &Response{Status: 0, Message: "user adds amount successfully!"}

View File

@ -123,6 +123,27 @@ func HandleAllRoutes(ctx *macaron.Context, opt api.FiscoBcos, logger *log.Logger
repo.SelectIssueLatestInfo(ctx, opt.IssueID, logger)
case "query issue all info":
repo.SelectIssueAllInfo(ctx, opt.IssueID, logger)
case "upload issue comment info":
repo.UploadIssueCommentInfo(ctx,
api.UploadIssueCommentOption{
IssueCommentID: opt.IssueCommentID,
IssueCommentNumber: opt.IssueCommentNumber,
IssueNumber: opt.IssueNumber,
RepoID: opt.RepoID,
ParentID: opt.ParentID,
Reponame: opt.Reponame,
Ownername: opt.Ownername,
Username: opt.Username,
Action: opt.Action,
CreatedAt: opt.CreatedAt,
UpdatedAt: opt.UpdatedAt,
Content: opt.Content,
},
logger)
case "query issue comment latest info":
repo.SelectIssueCommentLatestInfo(ctx, opt.IssueCommentID, logger)
case "query issue comment all info":
repo.SelectIssueCommentAllInfo(ctx, opt.IssueCommentID, logger)
case "query user balance of single repo":
user.SelectUserBalance(ctx, opt.Username, opt.TokenName, logger)
case "query user balance of all repos":

View File

@ -465,3 +465,114 @@ func SelectIssueAllInfo(ctx *macaron.Context, issueID string, logger *log.Logger
UploadIssueOptionArr: uploadIssueOptionArr,
})
}
// 查询 issue Comment 最新数据
func SelectIssueCommentLatestInfo(ctx *macaron.Context, issueCommentID string, logger *log.Logger) {
if issueCommentID == "" {
ctx.JSON(http.StatusOK, api.StringEmpty)
return
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
config := &configs[0]
client, err := client.Dial(config)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
// load the contract
contractAddress := common.HexToAddress(contract.ContractAddress)
instance, err := opensource.NewOpenSource(contractAddress, client)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
_, strJSON, err := openSourceSession.SelectIssueCommentInfo(issueCommentID) // call Insert API
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
fmt.Printf("issueCommentID: %v \n", strJSON)
var uploadIssueCommentOption api.UploadIssueCommentOption
err = json.Unmarshal([]byte(strJSON), &uploadIssueCommentOption)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
ctx.JSON(http.StatusOK, &structs.ResponseIssueComment{
Response: structs.Response{
Status: 0,
Message: "query success!",
},
UploadIssueCommentOption: uploadIssueCommentOption,
})
}
// 查询 issue comment 所有数据
func SelectIssueCommentAllInfo(ctx *macaron.Context, issueCommentID string, logger *log.Logger) {
if issueCommentID == "" {
ctx.JSON(http.StatusOK, api.StringEmpty)
return
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
config := &configs[0]
client, err := client.Dial(config)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
// load the contract
contractAddress := common.HexToAddress(contract.ContractAddress)
instance, err := opensource.NewOpenSource(contractAddress, client)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
_, strJSONArr, err := openSourceSession.SelectIssueCommentAllInfo(issueCommentID) // call Insert API
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
fmt.Printf("pullRequestID: %v \n", strJSONArr)
var uploadIssueCommentOption api.UploadIssueCommentOption
var uploadIssueCommentOptionArr api.UploadIssueCommentOptionArr
for i := 0; i < len(strJSONArr); i++ {
err = json.Unmarshal([]byte(strJSONArr[i]), &uploadIssueCommentOption)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
uploadIssueCommentOptionArr = append(uploadIssueCommentOptionArr, uploadIssueCommentOption)
}
ctx.JSON(http.StatusOK, &structs.ResponseIssueCommentArr{
Response: structs.Response{
Status: 0,
Message: "query success!",
},
UploadIssueCommentOptionArr: uploadIssueCommentOptionArr,
})
}

View File

@ -278,3 +278,54 @@ func UploadIssueInfo(ctx *macaron.Context, opt api.UploadIssueOption, logger *lo
}
ctx.JSON(http.StatusOK, structs.ResIssueUploadUnsucc)
}
// 上传 issue comment 数据
func UploadIssueCommentInfo(ctx *macaron.Context, opt api.UploadIssueCommentOption, logger *log.Logger) {
issueCommentID := opt.IssueCommentID
bytesJson, err := json.Marshal(opt)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
config := &configs[0]
client, err := client.Dial(config)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
// load the contract
contractAddress := common.HexToAddress(contract.ContractAddress)
instance, err := opensource.NewOpenSource(contractAddress, client)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
tx, receipt, err := openSourceSession.AddIssueCommentData(issueCommentID, string(bytesJson)) // call Insert API
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
logger.Printf("tx sent: %s\n", tx.Hash().Hex())
// insertedLines, err := strconv.Atoi(receipt.Output[2:])
code, err := parseOutput(opensource.OpenSourceABI, "addIssueCommentData", receipt)
if err != nil {
logger.Panic("error when transfer string to int: ", err)
}
if code.Int64() > 0 {
logger.Printf("inserted lines: %v\n", code)
ctx.JSON(http.StatusOK, structs.ResIssueCommentUploadSucc)
return
}
ctx.JSON(http.StatusOK, structs.ResIssueCommentUploadUnsucc)
}