From 39be80c18c84db735505b467a80798d5e1a1b8f6 Mon Sep 17 00:00:00 2001 From: DarkMatter015 Date: Sun, 15 Feb 2026 17:42:24 -0300 Subject: [PATCH 1/2] feat: create chat_sessions and chat_messages tables migration --- .../db/migration/V13__create_chat_history.sql | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/resources/db/migration/V13__create_chat_history.sql diff --git a/src/main/resources/db/migration/V13__create_chat_history.sql b/src/main/resources/db/migration/V13__create_chat_history.sql new file mode 100644 index 0000000..a201660 --- /dev/null +++ b/src/main/resources/db/migration/V13__create_chat_history.sql @@ -0,0 +1,23 @@ +CREATE TABLE chat_sessions +( + id UUID PRIMARY KEY, + user_id BIGINT NOT NULL, + title VARCHAR(255), + created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE chat_messages +( + id BIGSERIAL PRIMARY KEY, + session_id UUID NOT NULL, + role VARCHAR(20) NOT NULL, + content TEXT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_chat_session + FOREIGN KEY (session_id) + REFERENCES chat_sessions (id) + ON DELETE CASCADE +); + +CREATE INDEX idx_chat_messages_session ON chat_messages (session_id); +CREATE INDEX idx_chat_sessions_user ON chat_sessions (user_id); \ No newline at end of file From 480cceb543a3a16e41eeea15fc0882b9a7dc24b1 Mon Sep 17 00:00:00 2001 From: DarkMatter015 Date: Sun, 22 Feb 2026 16:16:58 -0300 Subject: [PATCH 2/2] feat: added expiresIn attribute in JWT response --- .../security/dto/auth/AuthenticationResponseDTO.java | 1 + .../infra/security/filter/JWTAuthenticationFilter.java | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/br/edu/utfpr/pb/ecommerce/server_ecommerce/infra/security/dto/auth/AuthenticationResponseDTO.java b/src/main/java/br/edu/utfpr/pb/ecommerce/server_ecommerce/infra/security/dto/auth/AuthenticationResponseDTO.java index 5fc2ef1..c020087 100644 --- a/src/main/java/br/edu/utfpr/pb/ecommerce/server_ecommerce/infra/security/dto/auth/AuthenticationResponseDTO.java +++ b/src/main/java/br/edu/utfpr/pb/ecommerce/server_ecommerce/infra/security/dto/auth/AuthenticationResponseDTO.java @@ -14,5 +14,6 @@ public class AuthenticationResponseDTO { private String token; private UserResponseDTO user; + private Long expiresIn; } diff --git a/src/main/java/br/edu/utfpr/pb/ecommerce/server_ecommerce/infra/security/filter/JWTAuthenticationFilter.java b/src/main/java/br/edu/utfpr/pb/ecommerce/server_ecommerce/infra/security/filter/JWTAuthenticationFilter.java index 891dbdf..ed52c7a 100644 --- a/src/main/java/br/edu/utfpr/pb/ecommerce/server_ecommerce/infra/security/filter/JWTAuthenticationFilter.java +++ b/src/main/java/br/edu/utfpr/pb/ecommerce/server_ecommerce/infra/security/filter/JWTAuthenticationFilter.java @@ -24,8 +24,8 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import java.io.IOException; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.stream.Collectors; @@ -84,7 +84,7 @@ protected void successfulAuthentication(HttpServletRequest request, .withSubject(user.getId().toString()) //a data de validade do token é a data atual mais o valor armazenado na constante EXPIRATION_TIME, nesse caso 1 dia .withExpiresAt( - new Date(System.currentTimeMillis() + jwtProperties.getExpirationTime()) + getExpirationDate() ) .withClaim("roles", user.getAuthorities().stream() .map(GrantedAuthority::getAuthority) @@ -95,9 +95,12 @@ protected void successfulAuthentication(HttpServletRequest request, response.setCharacterEncoding("UTF-8"); response.getWriter().write( objectMapper.writeValueAsString( - new AuthenticationResponseDTO(token, new UserResponseDTO(user)) + new AuthenticationResponseDTO(token, new UserResponseDTO(user), getExpirationDate().toEpochMilli()) ) ); } + private Instant getExpirationDate() { + return Instant.now().plusMillis(jwtProperties.getExpirationTime()); + } } \ No newline at end of file