use of com.tvd12.example.spring_boot_redis.exception.HttpNotFoundException in project ezyhttp by youngmonkeys.
the class HttpNotFoundExceptionTest method test.
@Test
public void test() {
// given
int code = StatusCodes.NOT_FOUND;
String data = "error";
// when
HttpNotFoundException sut = new HttpNotFoundException(data);
// then
Asserts.assertEquals(code, sut.getCode());
Asserts.assertEquals(data, sut.getData());
}
use of com.tvd12.example.spring_boot_redis.exception.HttpNotFoundException in project ezyfox-examples by tvd12.
the class BookController method getBook.
@DoGet("/books/{bookId}")
public BookResponse getBook(@PathVariable Long bookId) {
Book book = bookRepository.findById(bookId);
if (book == null) {
throw new HttpNotFoundException("not found book with id: " + bookId);
}
Author author = authorRepository.findById(book.getAuthorId());
Category category = categoryRepository.findById(book.getCategoryId());
return entityToResponseConverter.toBookResponse(book, author, category);
}
use of com.tvd12.example.spring_boot_redis.exception.HttpNotFoundException in project ezyfox-examples by tvd12.
the class BookController method getBook.
@DoGet("/books/{bookId}")
public BookResponse getBook(@PathVariable Long bookId) {
Book book = bookMap.get(bookId);
if (book == null) {
throw new HttpNotFoundException("not found book with id: " + bookId);
}
Author author = authorMap.get(book.getAuthorId());
Category category = categoryMap.get(book.getCategoryId());
return entityToResponseConverter.toBookResponse(book, author, category);
}
use of com.tvd12.example.spring_boot_redis.exception.HttpNotFoundException in project java-examples by tvd12.
the class BookController method getBook.
@GetMapping("/books/{bookId}")
public BookResponse getBook(@PathVariable Long bookId) {
Book book = bookRepository.findById(bookId).orElseThrow(() -> new HttpNotFoundException("not found book with id: " + bookId));
Author author = authorRepository.findById(book.getAuthorId()).orElseThrow(() -> new IllegalStateException("maybe someone has change redis"));
Category category = categoryRepository.findById(book.getCategoryId()).orElseThrow(() -> new IllegalStateException("maybe someone has change redis"));
return entityToResponseConverter.toBookResponse(book, author, category);
}
Aggregations