Search in sources :

Example 96 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-examples by tvd12.

the class BookController method addBook.

@DoPost("/book/add")
public BookResponse addBook(@RequestBody AddBookRequest request) {
    BookNameAndAuthorId bookNameAndAuthorId = new BookNameAndAuthorId(request.getBookName(), request.getAuthorId());
    Long existedBookId = bookIdByNameAndAuthorIdMap.get(bookNameAndAuthorId);
    if (existedBookId != null) {
        throw new HttpBadRequestException("author: " + request.getAuthorId() + " has already registered book: " + request.getBookName());
    }
    Author author = authorMap.get(request.getAuthorId());
    if (author == null) {
        throw new HttpBadRequestException("author: " + request.getAuthorId() + " not found");
    }
    Category category = categoryMap.get(request.getCategoryId());
    if (category == null) {
        throw new HttpBadRequestException("category: " + request.getCategoryId() + " not found");
    }
    val bookId = idGentor.incrementAndGet();
    val book = requestToEntityConverter.toBookEntity(request, bookId);
    bookMap.put(book.getId(), book);
    bookIdByNameAndAuthorIdMap.put(bookNameAndAuthorId, bookId);
    return entityToResponseConverter.toBookResponse(book, author, category);
}
Also used : lombok.val(lombok.val) Category(com.tvd12.ezydata.example.redis.entity.Category) BookNameAndAuthorId(com.tvd12.ezydata.example.redis.entity.BookNameAndAuthorId) EzyRedisAtomicLong(com.tvd12.ezydata.redis.EzyRedisAtomicLong) HttpBadRequestException(com.tvd12.ezyhttp.core.exception.HttpBadRequestException) Author(com.tvd12.ezydata.example.redis.entity.Author)

Example 97 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-examples by tvd12.

the class CategoryController method addCategory.

@DoPost("/add")
public Category addCategory(@RequestBody AddCategoryRequest request) {
    Long existedCategoryId = categoryIdByNameMap.get(request.getCategoryName());
    if (existedCategoryId != null) {
        throw new HttpBadRequestException("category named: " + request.getCategoryName() + " existed");
    }
    Category category = new Category(idGentor.incrementAndGet(), request.getCategoryName());
    categoryMap.put(category.getId(), category);
    categoryIdByNameMap.put(category.getName(), category.getId());
    return category;
}
Also used : Category(com.tvd12.ezydata.example.redis.entity.Category) EzyRedisAtomicLong(com.tvd12.ezydata.redis.EzyRedisAtomicLong) HttpBadRequestException(com.tvd12.ezyhttp.core.exception.HttpBadRequestException) DoPost(com.tvd12.ezyhttp.server.core.annotation.DoPost)

Example 98 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-examples by tvd12.

the class BookController method addBook.

@DoPost("/book/add")
public BookResponse addBook(@RequestBody AddBookRequest request) {
    bookValidator.validate(request);
    final AddBookData addBookData = requestToDataConverter.toData(request);
    final BookData bookData = bookService.addBook(addBookData);
    return dataToResponseConverter.toResponse(bookData);
}
Also used : AddBookData(com.tvd12.ezydata.example.jpa.data.AddBookData) BookData(com.tvd12.ezydata.example.jpa.data.BookData) AddBookData(com.tvd12.ezydata.example.jpa.data.AddBookData)

Example 99 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-examples by tvd12.

the class CategoryController method addCategory.

@DoPost("/add")
public CategoryResponse addCategory(@RequestBody AddCategoryRequest request) {
    categoryValidator.validate(request);
    final AddCategoryData addCategoryData = requestToDataConverter.toData(request);
    final CategoryData categoryData = categoryService.saveCategory(addCategoryData);
    return dataToResponseConverter.toResponse(categoryData);
}
Also used : AddCategoryData(com.tvd12.ezydata.example.jpa.data.AddCategoryData) CategoryData(com.tvd12.ezydata.example.jpa.data.CategoryData) AddCategoryData(com.tvd12.ezydata.example.jpa.data.AddCategoryData)

Example 100 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-examples by tvd12.

the class AuthorController method addAuthor.

@DoPost("/add")
public AuthorResponse addAuthor(@RequestBody AddAuthorRequest request) {
    authorValidator.validate(request);
    final AddAuthorData addAuthorData = requestToDataConverter.toData(request);
    final AuthorData authorData = authorService.saveAuthor(addAuthorData);
    return dataToResponseConverter.toResponse(authorData);
}
Also used : AuthorData(com.tvd12.ezydata.example.jpa.data.AuthorData) AddAuthorData(com.tvd12.ezydata.example.jpa.data.AddAuthorData) AddAuthorData(com.tvd12.ezydata.example.jpa.data.AddAuthorData)

Aggregations

Test (org.testng.annotations.Test)128 HttpServletResponse (javax.servlet.http.HttpServletResponse)48 HttpServletRequest (javax.servlet.http.HttpServletRequest)45 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)37 BeforeTest (org.testng.annotations.BeforeTest)36 BaseTest (com.tvd12.test.base.BaseTest)31 EzyArray (com.tvd12.ezyfox.entity.EzyArray)30 ComponentManager (com.tvd12.ezyhttp.server.core.manager.ComponentManager)29 BlockingServlet (com.tvd12.ezyhttp.server.core.servlet.BlockingServlet)29 ToString (lombok.ToString)29 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)27 ServletOutputStream (javax.servlet.ServletOutputStream)25 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)24 RequestHandlerManager (com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager)24 Cookie (javax.servlet.http.Cookie)24 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)22 RequestCookie (com.tvd12.ezyhttp.server.core.annotation.RequestCookie)22 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)21 HttpClient (com.tvd12.ezyhttp.client.HttpClient)21 PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)21