use of com.tvd12.ezyhttp.client.request.Request in project java-examples by tvd12.
the class BookController method addBook.
@PostMapping("/book/add")
public BookResponse addBook(@RequestBody AddBookRequest request) {
BookNameAndAuthorId bookNameAndAuthorId = new BookNameAndAuthorId(request.getBookName(), request.getAuthorId());
Long existedBookId = bookIdByNameAndAuthorIdRepository.findById(bookNameAndAuthorId).orElse(null);
if (existedBookId != null) {
throw new HttpBadRequestException("author: " + request.getAuthorId() + " has already registered book: " + request.getBookName());
}
Author author = authorRepository.findById(request.getAuthorId()).orElseThrow(() -> new HttpBadRequestException("author: " + request.getAuthorId() + " not found"));
Category category = categoryRepository.findById(request.getCategoryId()).orElseThrow(() -> new HttpBadRequestException("category: " + request.getCategoryId() + " not found"));
Long bookId = idGentor.incrementAndGet("book");
Book book = requestToEntityConverter.toBookEntity(request, bookId);
bookRepository.save(book);
bookIdByNameAndAuthorIdRepository.put(bookNameAndAuthorId, bookId);
return entityToResponseConverter.toBookResponse(book, author, category);
}
use of com.tvd12.ezyhttp.client.request.Request in project java-examples by tvd12.
the class CategoryController method addCategory.
@PostMapping("/add")
public Category addCategory(@RequestBody AddCategoryRequest request) {
Long existedCategoryId = categoryIdByNameRepository.findById(request.getCategoryName()).orElse(null);
if (existedCategoryId != null) {
throw new HttpBadRequestException("category named: " + request.getCategoryName() + " existed");
}
Category category = new Category(idGentor.incrementAndGet("category"), request.getCategoryName());
categoryRepository.save(category);
categoryIdByNameRepository.put(category.getName(), category.getId());
return category;
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.
the class EzyPingController method handle.
@Override
public void handle(EzyServerContext ctx, EzyPingRequest request) {
EzyResponse response = EzyPongResponse.getInstance();
EzySession session = request.getSession();
ctx.send(response, session, false);
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.
the class EzyPluginInfoController method handle.
@Override
public void handle(EzyServerContext ctx, EzyPluginInfoRequest request) {
EzyUser user = request.getUser();
EzySession session = request.getSession();
EzyPluginInfoParams params = request.getParams();
EzyZoneContext zoneCtx = ctx.getZoneContext(user.getZoneId());
EzyPluginContext pluginCtx = zoneCtx.getPluginContext(params.getPluginName());
if (pluginCtx != null) {
EzyPluginSetting setting = pluginCtx.getPlugin().getSetting();
EzyResponse response = newPluginInfoResponse(setting);
ctx.send(response, session, false);
}
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.
the class EzyHandshakeController method handle.
@SuppressWarnings("AbbreviationAsWordInName")
@Override
public void handle(EzyServerContext ctx, EzyHandShakeRequest request) {
EzySession session = request.getSession();
EzyHandshakeParams params = request.getParams();
EzyHandshakeEvent event = newHandshakeEvent(session, params);
ctx.handleEvent(EzyEventType.CLIENT_HANDSHAKE, event);
handleSocketSSL(ctx, event);
updateSession(session, event);
EzyResponse response = newHandShakeResponse(session, event);
ctx.send(response, session, false);
event.release();
}
Aggregations