Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

クラス加入時のニックネーム保存問題修正 #341

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading