Search in sources :

Example 16 with RequestBody

use of com.tvd12.ezyhttp.server.core.annotation.RequestBody in project ezyfox-examples by tvd12.

the class GoogleService method getAccessToken.

@SuppressWarnings("unchecked")
@Override
public String getAccessToken(String code) {
    Map<String, Object> requestBody = EzyMapBuilder.mapBuilder().put("client_id", clientId).put("client_secret", clientSecret).put("redirect_uri", redirectUri).put("code", code).put("grant_type", "authorization_code").build();
    PostRequest request = new PostRequest().setURL(getTokenUri).setEntity(RequestEntity.builder().contentType(ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED).body(requestBody).build()).setResponseType(Map.class);
    try {
        Map<String, Object> response = httpClientProxy.call(request, DEFAULT_GOOGLE_AUTH_TIMEOUT);
        return (String) response.get("access_token");
    } catch (Exception e) {
        logger.info("get google access token error", e);
        return null;
    }
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest)

Example 17 with RequestBody

use of com.tvd12.ezyhttp.server.core.annotation.RequestBody in project ezyfox-examples by tvd12.

the class RegisterController method registerPost.

@DoPost("/register")
public Redirect registerPost(@RequestBody RegisterRequest request) {
    final User user = new User(request.getUsername(), request.getPassword(), request.getBirthOfDate(), LocalDate.now(), LocalDateTime.now());
    userService.addUser(user);
    return Redirect.to("/user/" + request.getUsername());
}
Also used : User(org.youngmonkeys.example.ezyhttp.thymeleaf.entity.User) DoPost(com.tvd12.ezyhttp.server.core.annotation.DoPost)

Example 18 with RequestBody

use of com.tvd12.ezyhttp.server.core.annotation.RequestBody in project ezyfox-examples by tvd12.

the class UserController method userSavePost.

@DoPost("/user/save")
public Object userSavePost(@UserId long userId, @RequestBody UpdateUserRequest request) {
    User user = userService.getUserById(userId);
    if (user == null) {
        throw new UserNotFoundException("user with id: " + userId + " not found");
    }
    user.setEmail(request.getEmail());
    user.setFullName(request.getFirstName() + " " + request.getLastName());
    user.setFirstName(request.getFirstName());
    user.setLastName(request.getLastName());
    user.setStatus(UserStatus.UPDATED);
    user.setPassword(EzySHA256.cryptUtfToLowercase(request.getPassword()));
    userService.saveUser(user);
    return Redirect.builder().uri("/home").build();
}
Also used : UserNotFoundException(org.youngmonkeys.example.ezyhttp.login.exception.UserNotFoundException) User(org.youngmonkeys.example.ezyhttp.login.entity.User) DoPost(com.tvd12.ezyhttp.server.core.annotation.DoPost)

Aggregations

DoPost (com.tvd12.ezyhttp.server.core.annotation.DoPost)6 HttpBadRequestException (com.tvd12.ezyhttp.core.exception.HttpBadRequestException)4 Author (com.tvd12.example.spring_boot_redis.entity.Author)2 Category (com.tvd12.example.spring_boot_redis.entity.Category)2 HttpBadRequestException (com.tvd12.example.spring_boot_redis.exception.HttpBadRequestException)2 Author (com.tvd12.ezydata.example.mongo.entity.Author)2 Category (com.tvd12.ezydata.example.mongo.entity.Category)2 Author (com.tvd12.ezydata.example.redis.entity.Author)2 Category (com.tvd12.ezydata.example.redis.entity.Category)2 EzyRedisAtomicLong (com.tvd12.ezydata.redis.EzyRedisAtomicLong)2 PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)2 lombok.val (lombok.val)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 Book (com.tvd12.example.spring_boot_redis.entity.Book)1 BookNameAndAuthorId (com.tvd12.example.spring_boot_redis.entity.BookNameAndAuthorId)1 RedisAtomicLong (com.tvd12.example.spring_boot_redis.repository.RedisAtomicLong)1 AddAuthorData (com.tvd12.ezydata.example.jpa.data.AddAuthorData)1 AddBookData (com.tvd12.ezydata.example.jpa.data.AddBookData)1 AddCategoryData (com.tvd12.ezydata.example.jpa.data.AddCategoryData)1 AuthorData (com.tvd12.ezydata.example.jpa.data.AuthorData)1