fix: BossRoom soft delete → hard delete + 프로필 자동 생성
- BossRoom 삭제 시 Unscoped() hard delete로 변경하여 unique index 충돌 방지 - GetProfile에서 프로필 없으면 기본값으로 자동 생성 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -208,8 +208,9 @@ func (r *Repository) ResetRoomSlot(sessionName string) error {
|
||||
|
||||
// DeleteRoomBySessionName removes BossRoom records for a given session name.
|
||||
// Used during ResetRoom to prevent duplicate session_name conflicts on next entry.
|
||||
// Unscoped to perform hard delete — soft delete would leave the unique index occupied.
|
||||
func (r *Repository) DeleteRoomBySessionName(sessionName string) error {
|
||||
return r.db.Where("session_name = ?", sessionName).Delete(&BossRoom{}).Error
|
||||
return r.db.Unscoped().Where("session_name = ?", sessionName).Delete(&BossRoom{}).Error
|
||||
}
|
||||
|
||||
// ResetStaleSlots clears instanceID for slots with stale heartbeats
|
||||
|
||||
@@ -56,12 +56,16 @@ func (s *Service) CreateProfile(userID uint) error {
|
||||
return s.repo.Create(profile)
|
||||
}
|
||||
|
||||
// GetProfile JWT 인증된 유저의 프로필을 조회한다.
|
||||
// GetProfile JWT 인증된 유저의 프로필을 조회한다. 없으면 자동 생성.
|
||||
func (s *Service) GetProfile(userID uint) (*PlayerProfile, error) {
|
||||
profile, err := s.repo.FindByUserID(userID)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, fmt.Errorf("프로필이 존재하지 않습니다")
|
||||
profile = &PlayerProfile{UserID: userID}
|
||||
if createErr := s.repo.Create(profile); createErr != nil {
|
||||
return nil, fmt.Errorf("프로필 자동 생성에 실패했습니다: %w", createErr)
|
||||
}
|
||||
return profile, nil
|
||||
}
|
||||
return nil, fmt.Errorf("프로필 조회에 실패했습니다")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user