Skip to content

Commit

Permalink
Merge pull request #341 from yuminn-k/fix/340-class-signup-nickname-save
Browse files Browse the repository at this point in the history
クラス加入時のニックネーム保存問題修正
  • Loading branch information
yuminn-k authored Sep 23, 2024
2 parents 6771075 + e65b852 commit a056df6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion models/class_board.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ClassBoard struct {
CreatedAt time.Time `gorm:"not null;"`
UpdatedAt time.Time `gorm:"not null;"`
IsAnnounced bool `gorm:"not null;default:false"`
CID uint `gorm:"column:cid;not null;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
CID uint `gorm:"column:cid;not null;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
UID uint `gorm:"column:uid;not null"` // User ID
Class Class `gorm:"foreignKey:CID;constraint:OnDelete:CASCADE"`
User User `gorm:"foreignKey:UID"`
Expand Down
2 changes: 1 addition & 1 deletion models/class_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type ClassCode struct {
ID uint `gorm:"primaryKey;size:255;autoIncrement"`
Code string `gorm:"size:10;not null"`
Secret *string `gorm:"size:20"`
CID uint `gorm:"column:cid;not null;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
CID uint `gorm:"column:cid;not null;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
UID uint `gorm:"column:uid;not null"` // User ID
Class Class `gorm:"foreignKey:CID;constraint:OnDelete:CASCADE"`
User User `gorm:"foreignKey:UID"`
Expand Down
12 changes: 9 additions & 3 deletions repositories/class_user_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,16 @@ func (r *classUserRepository) RoleExists(uid uint, cid uint) (bool, error) {
}

func (r *classUserRepository) CreateUserRole(uid uint, cid uint, role string) error {
var user models.User
if err := r.db.First(&user, uid).Error; err != nil {
return err
}

newUserRole := models.ClassUser{
UID: uid,
CID: cid,
Role: role,
UID: uid,
CID: cid,
Role: role,
Nickname: user.Name,
}
return r.db.Create(&newUserRole).Error
}

0 comments on commit a056df6

Please sign in to comment.