Skip to content

Commit

Permalink
[fix] Fixed group added process.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Jul 22, 2021
1 parent 8d39b7f commit 6484683
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/api/core/group/v0/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Add(c *gin.Context) {
log.Println("Error: " + err.Error())
}

result, err := dbGroup.Create(&core.Group{
groupData := core.Group{
Agree: &[]bool{*input.Agree}[0],
StripeCustomerID: &cus.ID,
Question: input.Question,
Expand All @@ -91,7 +91,9 @@ func Add(c *gin.Context) {
Open: &[]bool{false}[0],
Pass: &[]bool{false}[0],
AddAllow: &[]bool{true}[0],
})
}

_, err = dbGroup.Create(&groupData)
if err != nil {
c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()})
return
Expand All @@ -107,8 +109,8 @@ func Add(c *gin.Context) {

notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true})

if err = dbUser.Update(user.UpdateGID, &core.User{Model: gorm.Model{ID: userResult.User.ID}, GroupID: &result.Model.ID}); err != nil {
log.Println(dbGroup.Delete(&core.Group{Model: gorm.Model{ID: result.ID}}))
if err = dbUser.Update(user.UpdateGID, &core.User{Model: gorm.Model{ID: userResult.User.ID}, GroupID: &groupData.ID}); err != nil {
log.Println(dbGroup.Delete(&core.Group{Model: gorm.Model{ID: groupData.ID}}))
c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()})
} else {
c.JSON(http.StatusOK, common.Result{})
Expand Down

0 comments on commit 6484683

Please sign in to comment.