|
17 | 17 | import org.springframework.web.bind.annotation.RequestMapping; |
18 | 18 | import org.springframework.web.bind.annotation.RequestParam; |
19 | 19 | import org.springframework.web.bind.annotation.RestController; |
| 20 | +import com.digitalsanctuary.spring.demo.user.profile.DemoUserProfileRepository; |
20 | 21 | import com.digitalsanctuary.spring.user.persistence.model.PasswordResetToken; |
21 | 22 | import com.digitalsanctuary.spring.user.persistence.model.Role; |
22 | 23 | import com.digitalsanctuary.spring.user.persistence.model.User; |
@@ -47,6 +48,7 @@ public class TestDataController { |
47 | 48 | private final PasswordResetTokenRepository passwordResetTokenRepository; |
48 | 49 | private final RoleRepository roleRepository; |
49 | 50 | private final PasswordEncoder passwordEncoder; |
| 51 | + private final DemoUserProfileRepository demoUserProfileRepository; |
50 | 52 |
|
51 | 53 | /** |
52 | 54 | * Check if a user exists by email. |
@@ -228,9 +230,9 @@ public ResponseEntity<Map<String, Object>> deleteTestUser(@RequestParam String e |
228 | 230 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); |
229 | 231 | } |
230 | 232 |
|
231 | | - // Delete related tokens first to avoid foreign key constraints |
232 | | - // Note: Event registrations and other related entities are not deleted. |
233 | | - // If the user has event registrations, this may fail with foreign key constraint violation. |
| 233 | + // Delete related entities first to avoid foreign key constraints |
| 234 | + demoUserProfileRepository.findById(user.getId()).ifPresent(demoUserProfileRepository::delete); |
| 235 | + |
234 | 236 | VerificationToken verificationToken = verificationTokenRepository.findByUser(user); |
235 | 237 | if (verificationToken != null) { |
236 | 238 | verificationTokenRepository.delete(verificationToken); |
|
0 commit comments