some changes

This commit is contained in:
2026-10-13 15:48:24 +03:00
parent 983ee548e0
commit 2debb1d20c
3 changed files with 5 additions and 7 deletions
@@ -1,6 +1,7 @@
package com.vnp.demo.models;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.UUID;
import jakarta.persistence.Column;
@@ -25,7 +26,7 @@ public class User {
private String passwordHash;
@Column(name = "created_at", nullable = false)
private Instant createdAt = Instant.now();
private Instant createdAt = Instant.now().truncatedTo(ChronoUnit.MICROS);
protected User() {
}
@@ -45,9 +45,7 @@ public class UserService {
return transactionTemplate.execute(status -> {
if (userRepository.existsByUsername(username)) {
throw BusinessException.conflict(
"Username already exists"
);
throw BusinessException.conflict("Username already exists");
}
User user = new User(
@@ -62,8 +60,7 @@ public class UserService {
});
} catch (DataIntegrityViolationException ex) {
// Корректно для нарушения уникальности username.
// Другие ограничения БД не следует маскировать как конфликт имени.
throw BusinessException.conflict(
"Username already exists"
);