From 33676cf1653f2053f57a9e0ecd5c8bda6c64d986 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 22 Dec 2022 16:22:52 +0300 Subject: User info updates fix --- src/main/java/com/juick/service/UserServiceImpl.java | 4 ++-- src/main/resources/db/specific/h2/V1.22__schema.sql | 4 ++-- src/test/java/com/juick/server/tests/ServerTests.java | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index 4158561c..b5581b76 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -390,7 +390,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { return user; } - @Transactional @Override public boolean updateUserInfo(final User info) { try { @@ -401,7 +400,8 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { info.getCountry(), info.getUrl(), info.getDescription()) > 0; - } catch (DataIntegrityViolationException e) { + } catch (Exception e) { + // pgjdbc 42.x do not use SQLException return getJdbcTemplate().update("UPDATE usersinfo SET fullname = ?, country = ?, url = ?, descr = ? WHERE user_id = ?", info.getFullName(), info.getCountry(), diff --git a/src/main/resources/db/specific/h2/V1.22__schema.sql b/src/main/resources/db/specific/h2/V1.22__schema.sql index 83ff7054..2ded0e53 100644 --- a/src/main/resources/db/specific/h2/V1.22__schema.sql +++ b/src/main/resources/db/specific/h2/V1.22__schema.sql @@ -291,8 +291,8 @@ ALTER TABLE "PUBLIC"."USERS_SUBSCR" ADD CONSTRAINT "PUBLIC"."CONSTRAINT_BB" PRIM CREATE MEMORY TABLE "PUBLIC"."USERSINFO"( "USER_ID" INTEGER NOT NULL, "JID" CHARACTER(32) DEFAULT NULL, - "FULLNAME" CHARACTER(32) DEFAULT NULL, - "COUNTRY" CHARACTER(32) DEFAULT NULL, + "FULLNAME" VARCHAR(32) DEFAULT NULL, + "COUNTRY" VARCHAR(32) DEFAULT NULL, "URL" CHARACTER(64) DEFAULT NULL, "GENDER" CHARACTER(32) DEFAULT NULL, "BDAY" CHARACTER(10) DEFAULT NULL, diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 38eace7c..6eae82f3 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -2774,4 +2774,18 @@ public class ServerTests { redirectedUrl("https://juick.com/vt/") ); } + @Test + public void userInfoUpdateTest() { + assertThat(ugnich.getFullName(), equalTo(null)); + var fullUgnichName = "Anton Ugnich"; + ugnich.setFullName(fullUgnichName); + userService.updateUserInfo(ugnich); + var info = userService.getUserInfo(ugnich); + assertThat(info.getName(), equalTo(ugnichName)); + assertThat(info.getFullName(), equalTo(fullUgnichName)); + ugnich.setDescription("Test"); + userService.updateUserInfo(ugnich); + var descr = userService.getUserInfo(ugnich); + assertThat(descr.getDescription(), equalTo("Test")); + } } -- cgit v1.2.3