Skip to content

Commit

Permalink
Merge pull request #116 from 666pulse/icp
Browse files Browse the repository at this point in the history
update create icp canister project
  • Loading branch information
abing258 authored Mar 12, 2024
2 parents b7eb86f + b48f43f commit 7cda934
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/db/icp_canister.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (

type IcpCanister struct {
Id int `json:"id"`
FkUserId uint `json:"fkUserId"`
ProjectId string `json:"projectId"`
CanisterId string `json:"canisterId"`
CanisterName string `json:"canisterName"`
Expand Down
18 changes: 15 additions & 3 deletions pkg/service/workflow_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,26 +784,38 @@ func (w *WorkflowService) syncInternetComputerDeploy(projectId uuid.UUID, workfl

var icpCanister db.IcpCanister

// 使用First查询满足条件的第一条数据
// 使用 First 查询满足条件的第一条数据
if err := w.db.Model(db.IcpCanister{}).Where("project_id = ? and canister_id = ?", projectId.String(), canisterId).First(&icpCanister).Error; err != nil {
if err == gorm.ErrRecordNotFound {
fmt.Println("数据不存在")
icpCanister.CanisterId = canisterId
icpCanister.CreateTime = sql.NullTime{Time: time.Now(), Valid: true}
icpCanister.ProjectId = projectId.String()
} else {
fmt.Println("查询数据时发生错误:", err)
fmt.Println("查询数据时发生错误", err)
continue
}
}

var project db.Project
if err := w.db.Model(db.Project{}).Where("id = ?", projectId.String()).First(&project).Error; err != nil {
if err == gorm.ErrRecordNotFound {
fmt.Println("project 数据不存在")
} else {
fmt.Println("查询数据时发生错误:", err)
continue
}
} else {
icpCanister.FkUserId = uint(project.UserId)
}

icpCanister.CanisterName = deploy.Name
icpCanister.Status = db.Running
icpCanister.Contract = strings.Join([]string{deployPackage.Name, deployPackage.Version}, "_#")
icpCanister.Cycles = sql.NullString{Valid: false}
icpCanister.UpdateTime = sql.NullTime{Time: time.Now(), Valid: true}
if err := w.db.Save(&icpCanister).Error; err != nil {
fmt.Println("保存数据时发生错误:", err)
fmt.Println("保存数据时发生错误", err)
continue
}

Expand Down

0 comments on commit 7cda934

Please sign in to comment.