Skip to content

Commit

Permalink
add delete api (#27)
Browse files Browse the repository at this point in the history
* add delete api

make orphan removal true

make code spotless

* BE: apply spotless changes.

---------

Co-authored-by: Mgrdich <mgotm13@gmail.com>
  • Loading branch information
Yerish26 and Mgrdich authored May 10, 2024
1 parent bc1bed7 commit f51f340
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public ResponseEntity<List<DiscussionResponse>> continueConversation(
.body(discussions.stream().map(conversationApiMapper::map).toList());
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteConversation(@PathVariable UUID id) throws ConversationNotFoundException {
conversationService.getByID(id).orElseThrow(() -> new ConversationNotFoundException(id));
conversationService.delete(id);
return ResponseEntity.status(HttpStatus.OK).body(null);
}

@ExceptionHandler(ConversationNotFoundException.class)
public ResponseEntity<String> handleConversationNotFoundException(
ConversationNotFoundException conversationNotFoundException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Table(name = "conversation")
@Data
public class ConversationEntity extends BaseEntity {
@OneToMany(mappedBy = "conversation")
@OneToMany(mappedBy = "conversation", orphanRemoval = true)
private List<DiscussionEntity> discussions;

@Column(name = "title")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public List<Discussion> askLLMQuestion(UUID id, ConversationRequest conversation
return newDiscussions;
}

public void delete(UUID id) {
conversationPersistenceManager.delete(id);
}

private String getPrediction(String text) {
return llmService.generate(text).toString();
}
Expand Down

0 comments on commit f51f340

Please sign in to comment.