fix migrations

This commit is contained in:
EgorAnti
2026-10-20 14:27:59 +03:00
parent 05fcccb9ed
commit 7565b65997
9 changed files with 43 additions and 9 deletions
@@ -8,6 +8,7 @@ import com.example.mtusi_messenger.exception.ApiExceptions;
import com.example.mtusi_messenger.model.User;
import com.example.mtusi_messenger.repository.UserRepository;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.UUID;
@Service
@@ -23,7 +24,8 @@ public class UserService {
if (users.findByUsername(username).isPresent()) throw ApiExceptions.conflict("Username is already taken");
String passwordHash = passwordEncoder.encode(r.password());
try {
return users.save(new User(UUID.randomUUID(), username, display, Instant.now()), passwordHash);
return users.save(new User(UUID.randomUUID(), username, display,
Instant.now().truncatedTo(ChronoUnit.MICROS)), passwordHash);
} catch (DuplicateKeyException e) {
throw ApiExceptions.conflict("Username is already taken");
}