Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
November-12 committed Oct 17, 2023
1 parent 4561163 commit bd0e5c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 15 additions & 2 deletions controllers/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ func (c *ConsoleController) Edit() {
}
return
}

tenantId, ok := c.Ctx.Input.GetData("tenant_id").(string)
if !ok {
response.SuccessWithMessage(400, "代码逻辑错误", (*context2.Context)(c.Ctx))
return
}

var ConsoleService services.ConsoleService

err = ConsoleService.EditConsole(input.ID, input.Name, input.Data, input.Config, input.Template, input.Code)
err = ConsoleService.EditConsole(input.ID, input.Name, input.Data, input.Config, input.Template, input.Code, tenantId)
if err != nil {
utils.SuccessWithMessage(1000, err.Error(), (*context2.Context)(c.Ctx))
return
Expand All @@ -107,8 +114,14 @@ func (c *ConsoleController) Delete() {
return
}

tenantId, ok := c.Ctx.Input.GetData("tenant_id").(string)
if !ok {
response.SuccessWithMessage(400, "代码逻辑错误", (*context2.Context)(c.Ctx))
return
}

var ConsoleService services.ConsoleService
err = ConsoleService.DeleteConsoleById(input.ID)
err = ConsoleService.DeleteConsoleById(input.ID, tenantId)
if err != nil {
utils.SuccessWithMessage(1000, err.Error(), (*context2.Context)(c.Ctx))
return
Expand Down
8 changes: 4 additions & 4 deletions services/console_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (*ConsoleService) AddConsole(name, createdBy, data, config, template, code,
return result.Error
}

func (*ConsoleService) EditConsole(id, name, data, config, template, code string) error {
func (*ConsoleService) EditConsole(id, name, data, config, template, code, tenant_id string) error {

update := make(map[string]interface{})

Expand All @@ -54,12 +54,12 @@ func (*ConsoleService) EditConsole(id, name, data, config, template, code string
update["code"] = code
}

err := psql.Mydb.Model(&models.Console{}).Where("id = ?", id).Updates(update).Error
err := psql.Mydb.Model(&models.Console{}).Where("id = ? and tenant_id = ? ", id, tenant_id).Updates(update).Error
return err
}

func (*ConsoleService) DeleteConsoleById(id string) error {
err := psql.Mydb.Where("id = ?", id).Delete(&models.Console{}).Error
func (*ConsoleService) DeleteConsoleById(id, tenant_id string) error {
err := psql.Mydb.Where("id = ? and tenant_id = ?", id, tenant_id).Delete(&models.Console{}).Error
return err
}

Expand Down

0 comments on commit bd0e5c9

Please sign in to comment.