Skip to content

Commit

Permalink
Fix database updates
Browse files Browse the repository at this point in the history
  • Loading branch information
milesha committed Nov 23, 2024
1 parent 25941cb commit bcf8b0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jakarta.persistence.*;
import java.time.OffsetDateTime;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.lang.NonNull;
Expand All @@ -14,12 +14,12 @@
@Getter
@Setter
@ToString(callSuper = true)
@RequiredArgsConstructor
@NoArgsConstructor
public class Message {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NonNull
@Column(name = "sent_at")
private OffsetDateTime sentAt = OffsetDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,25 @@ public List<MessageDTO> getMessagesBySessionId(Long sessionId) {
}

public MessageDTO sendMessage(String content, Long sessionId) {
Optional<Session> session = sessionRepository.findById(sessionId);
Optional<Session> session = sessionRepository.findById(sessionId);
if (session.isEmpty()) {
return null;
}

Message userMessage = new Message(MessageSender.USER, content, session.get());

Message userMessage = new Message();
userMessage.setSender(MessageSender.USER);
userMessage.setContent(content);
userMessage.setSession(session.get());

// String systemResponse = generateResponse(sessionId, content);

// Message systemMessage = new Message(OffsetDateTime.now(), MessageSender.SYSTEM, systemResponse, session);
// Message systemMessage = new Message(OffsetDateTime.now(),
// MessageSender.SYSTEM, systemResponse, session);
// messageRepository.saveAndFlush(systemMessage);

// return new MessageDTO(systemMessage.getId(), systemMessage.getSentAt(), systemMessage.getSender(),
// systemMessage.getContent(), systemMessage.getSession().getId());
// return new MessageDTO(systemMessage.getId(), systemMessage.getSentAt(),
// systemMessage.getSender(),
// systemMessage.getContent(), systemMessage.getSession().getId());
return MessageDTO.fromMessage(messageRepository.save(userMessage));
}

Expand Down

0 comments on commit bcf8b0a

Please sign in to comment.