Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public class AuthenticationResponseDTO {

private String token;
private UserResponseDTO user;
private Long expiresIn;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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)
Expand All @@ -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());
}
}
23 changes: 23 additions & 0 deletions src/main/resources/db/migration/V13__create_chat_history.sql
Original file line number Diff line number Diff line change
@@ -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);
Loading