forked from mtusi2026/mtusi2026lab2
some changes
This commit is contained in:
@@ -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"
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user