Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit title minor fix #51

Merged
merged 3 commits into from
May 13, 2024
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 @@ -101,16 +101,11 @@ public ResponseEntity<List<DiscussionResponse>> continueConversation(
@PutMapping("/api/v1/conversation/{id}")
public ResponseEntity<ConversationResponseCompact> editConversation(
@PathVariable UUID id, @RequestBody ConversationTitleRequest conversationTitleRequest) throws Exception {
Conversation conversationOld =
Conversation conversation =
conversationService.getByID(id).orElseThrow(() -> new ConversationNotFoundException(id));
Conversation conversationNew =
conversationService.editTitle(conversationOld, conversationTitleRequest.getTitle());

// TODO find why save does not return discussions
// TEMP Solution
conversationNew.setDiscussions(conversationOld.getDiscussions());
conversation = conversationService.editTitle(conversation, conversationTitleRequest.getTitle());

return ResponseEntity.status(HttpStatus.OK).body(conversationApiMapper.mapCompact(conversationNew));
return ResponseEntity.status(HttpStatus.OK).body(conversationApiMapper.mapCompact(conversation));
}

@ApiResponses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.llm_service.llm_service.persistance.repositories.conversation.ConversationPersistenceManager;
import com.llm_service.llm_service.persistance.repositories.discussion.DiscussionPersistenceManager;
import com.llm_service.llm_service.service.user.UserContext;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -111,7 +112,23 @@ public Conversation editTitle(Conversation conversation, String title) throws Un
if (user.isEmpty()) {
throw new UnAuthorizedException();
}
Conversation savedConversation = saveEditedTitle(conversation, title, user);

return getConversation(conversation, savedConversation.getTitle());
}

private Conversation getConversation(Conversation conversation, String title) {
conversation = Conversation.builder()
.id(conversation.getId())
.discussions(conversation.getDiscussions())
.title(title)
.createdOn(conversation.getCreatedOn())
.lastUpdatedOn(Instant.now())
.build();
return conversation;
}

private Conversation saveEditedTitle(Conversation conversation, String title, Optional<User> user) {
return conversationPersistenceManager.save(
conversation.toBuilder().title(title).build(), user.get());
}
Expand Down