forked from mtusi2026/mtusi2026lab2
some changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.vnp.demo.models;
|
package com.vnp.demo.models;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
@@ -25,7 +26,7 @@ public class User {
|
|||||||
private String passwordHash;
|
private String passwordHash;
|
||||||
|
|
||||||
@Column(name = "created_at", nullable = false)
|
@Column(name = "created_at", nullable = false)
|
||||||
private Instant createdAt = Instant.now();
|
private Instant createdAt = Instant.now().truncatedTo(ChronoUnit.MICROS);
|
||||||
|
|
||||||
protected User() {
|
protected User() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,7 @@ public class UserService {
|
|||||||
return transactionTemplate.execute(status -> {
|
return transactionTemplate.execute(status -> {
|
||||||
|
|
||||||
if (userRepository.existsByUsername(username)) {
|
if (userRepository.existsByUsername(username)) {
|
||||||
throw BusinessException.conflict(
|
throw BusinessException.conflict("Username already exists");
|
||||||
"Username already exists"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = new User(
|
User user = new User(
|
||||||
@@ -62,8 +60,7 @@ public class UserService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (DataIntegrityViolationException ex) {
|
} catch (DataIntegrityViolationException ex) {
|
||||||
// Корректно для нарушения уникальности username.
|
|
||||||
// Другие ограничения БД не следует маскировать как конфликт имени.
|
|
||||||
throw BusinessException.conflict(
|
throw BusinessException.conflict(
|
||||||
"Username already exists"
|
"Username already exists"
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{"username":"redis_test_1284294868","display_name":"Redis Test","password":"Password123!"}
|
{"username":"redis_test_1284294868","display_name":"Redis Test","password":"Password123!"}
|
||||||
Reference in New Issue
Block a user