Search in sources :

Example 1 with HttpNotFoundException

use of com.tvd12.ezyhttp.core.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());
}
Also used : HttpNotFoundException(com.tvd12.ezyhttp.core.exception.HttpNotFoundException) Test(org.testng.annotations.Test)

Example 2 with HttpNotFoundException

use of com.tvd12.ezyhttp.core.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);
}
Also used : HttpNotFoundException(com.tvd12.ezyhttp.core.exception.HttpNotFoundException) Category(com.tvd12.ezydata.example.mongo.entity.Category) Book(com.tvd12.ezydata.example.mongo.entity.Book) Author(com.tvd12.ezydata.example.mongo.entity.Author)

Example 3 with HttpNotFoundException

use of com.tvd12.ezyhttp.core.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);
}
Also used : HttpNotFoundException(com.tvd12.ezyhttp.core.exception.HttpNotFoundException) Category(com.tvd12.ezydata.example.redis.entity.Category) Book(com.tvd12.ezydata.example.redis.entity.Book) Author(com.tvd12.ezydata.example.redis.entity.Author)

Example 4 with HttpNotFoundException

use of com.tvd12.ezyhttp.core.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);
}
Also used : HttpNotFoundException(com.tvd12.example.spring_boot_redis.exception.HttpNotFoundException) Category(com.tvd12.example.spring_boot_redis.entity.Category) Book(com.tvd12.example.spring_boot_redis.entity.Book) Author(com.tvd12.example.spring_boot_redis.entity.Author)

Aggregations

HttpNotFoundException (com.tvd12.ezyhttp.core.exception.HttpNotFoundException)3 Author (com.tvd12.example.spring_boot_redis.entity.Author)1 Book (com.tvd12.example.spring_boot_redis.entity.Book)1 Category (com.tvd12.example.spring_boot_redis.entity.Category)1 HttpNotFoundException (com.tvd12.example.spring_boot_redis.exception.HttpNotFoundException)1 Author (com.tvd12.ezydata.example.mongo.entity.Author)1 Book (com.tvd12.ezydata.example.mongo.entity.Book)1 Category (com.tvd12.ezydata.example.mongo.entity.Category)1 Author (com.tvd12.ezydata.example.redis.entity.Author)1 Book (com.tvd12.ezydata.example.redis.entity.Book)1 Category (com.tvd12.ezydata.example.redis.entity.Category)1 Test (org.testng.annotations.Test)1