Skip to content

Commit

Permalink
add exception classes, and DAO layer (#5)
Browse files Browse the repository at this point in the history
make spotless

add exception handler

make spotless

resolve modelParameter
  • Loading branch information
Yerish26 authored May 7, 2024
1 parent e3055ba commit 5f58508
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.llm_service.llm_service.controller.conversation;

import com.llm_service.llm_service.exception.conversation.ConversationNotFound;
import com.llm_service.llm_service.exception.conversation.ConversationNotFoundException;
import com.llm_service.llm_service.model.Conversation;
import com.llm_service.llm_service.service.ConversationService;
import java.util.UUID;
Expand All @@ -17,7 +17,8 @@ public class ConversationController {
private final ConversationService conversationService;

@GetMapping("/{id}")
public ResponseEntity<Conversation> getConversationById(@PathVariable UUID id) throws ConversationNotFound {
public ResponseEntity<Conversation> getConversationById(@PathVariable UUID id)
throws ConversationNotFoundException {
Conversation conversation = conversationService.getByID(id);

return ResponseEntity.status(HttpStatus.OK).body(conversation);
Expand All @@ -32,9 +33,16 @@ public ResponseEntity<Conversation> createConversation() {

@PutMapping("/{id}/continue")
public ResponseEntity<Conversation> continueConversation(
@PathVariable UUID id, @RequestBody ConversationRequest conversationRequest) throws ConversationNotFound {
@PathVariable UUID id, @RequestBody ConversationRequest conversationRequest)
throws ConversationNotFoundException {
Conversation conversation = conversationService.update(id, conversationRequest);

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

@ExceptionHandler(ConversationNotFoundException.class)
public ResponseEntity<String> handleConversationNotFoundException(
ConversationNotFoundException conversationNotFoundException) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(conversationNotFoundException.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.llm_service.llm_service.controller.conversation;

import com.llm_service.llm_service.model.Conversation;
import org.mapstruct.Mapper;

@Mapper(componentModel = "spring")
public interface ConversationControllerMapper {
ConversationResponse map(Conversation conversation);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.llm_service.llm_service.controller.conversation;

import java.util.UUID;
import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
Expand All @@ -8,5 +9,6 @@
@Builder
@Jacksonized
public class ConversationResponse {
UUID id;
String text;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.llm_service.llm_service.exception.conversation;

import java.util.UUID;

public class ConversationAlreadyExistsException extends Exception {
public ConversationAlreadyExistsException(UUID id) {
super("Conversation with id " + id + " already exists");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.llm_service.llm_service.exception.conversation;

import java.util.UUID;

public class ConversationNotFoundException extends Exception {
public ConversationNotFoundException(UUID id) {
super("Conversation with id " + id + " is not found");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.llm_service.llm_service.exception.user;

import java.util.UUID;

public class UserAlreadyExistsException extends Exception {
public UserAlreadyExistsException(UUID id) {
super("User with id " + id + " already exists");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.llm_service.llm_service.exception.user;

import java.util.UUID;

public class UserNotFoundException extends Exception {
public UserNotFoundException(UUID id) {
super("User with id " + id + " is not found");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.llm_service.llm_service.service;

import com.llm_service.llm_service.controller.conversation.ConversationRequest;
import com.llm_service.llm_service.exception.conversation.ConversationNotFound;
import com.llm_service.llm_service.exception.conversation.ConversationNotFoundException;
import com.llm_service.llm_service.model.Conversation;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,11 +16,11 @@ public Conversation start() {
return null;
}

public Conversation getByID(UUID id) throws ConversationNotFound {
public Conversation getByID(UUID id) throws ConversationNotFoundException {
return null;
}

public Conversation update(UUID id, ConversationRequest conversationRequest) throws ConversationNotFound {
public Conversation update(UUID id, ConversationRequest conversationRequest) throws ConversationNotFoundException {
return Conversation.builder()
.id(id)
.text(getPrediction(id, conversationRequest.getText()))
Expand Down

0 comments on commit 5f58508

Please sign in to comment.