Search in sources :

Example 16 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class UserLoginFacebookApi method post.

@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    UserData userData = UserDataUtil.loginFacebookUser(request.fbUserAccessToken, UserDataUtil.getUserSignUpSource(true, false));
    List<Task> taskList = new LinkedList<>();
    Task fbValidationTask = TaskQueueFactory.newTask().setUrl("/user/facebook/validation").addParam("accessToken", AccessTokenFilter.getAccessToken().getId()).addParam("fbUserAccessToken", request.fbUserAccessToken);
    taskList.add(fbValidationTask);
    if (new Date().getTime() - userData.getSignUpDate().getTime() <= 60000) {
        Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language == null ? UxModeFilter.getFilterLanguage() : request.language);
        // Fetching updated UserData
        userData = UserDataUtil.getCurrentUser();
        if (userData.getEmail() != null) {
            // Send welcome mail to the user
            Task welcomeMailTask = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", (request.language == null ? (UxModeFilter.getDisplayLanguage() == null ? Language.ENGLISH : UxModeFilter.getDisplayLanguage()) : request.language).toString()).addParam("sendWelcomeMail", "true");
            taskList.add(welcomeMailTask);
        }
        // Process Author data
        Task task = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", authorId.toString()).addParam("processData", "true");
        TaskQueueFactory.getAuthorTaskQueue().add(task);
    }
    TaskQueueFactory.getUserTaskQueue().addAll(taskList);
    return new UserV1Api.Response(userData, UserLoginFacebookApi.class);
}
Also used : Task(com.pratilipi.taskqueue.Task) UserData(com.pratilipi.data.client.UserData) LinkedList(java.util.LinkedList) Date(java.util.Date) Post(com.pratilipi.api.annotation.Post)

Example 17 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class UserLoginGoogleApi method post.

@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    UserData userData = UserDataUtil.loginGoogleUser(request.googleIdToken, UserDataUtil.getUserSignUpSource(false, true));
    if (new Date().getTime() - userData.getSignUpDate().getTime() <= 60000) {
        Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language == null ? UxModeFilter.getFilterLanguage() : request.language);
        // Fetching updated UserData
        userData = UserDataUtil.getCurrentUser();
        // Send welcome mail to the user
        Task welcomeMailTask = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", (request.language == null ? (UxModeFilter.getDisplayLanguage() == null ? Language.ENGLISH : UxModeFilter.getDisplayLanguage()) : request.language).toString()).addParam("sendWelcomeMail", "true");
        TaskQueueFactory.getUserTaskQueue().add(welcomeMailTask);
        // Process Author data
        Task task = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", authorId.toString()).addParam("processData", "true");
        TaskQueueFactory.getAuthorTaskQueue().add(task);
    }
    return new UserV1Api.Response(userData, UserLoginGoogleApi.class);
}
Also used : Task(com.pratilipi.taskqueue.Task) UserData(com.pratilipi.data.client.UserData) Date(java.util.Date) Post(com.pratilipi.api.annotation.Post)

Example 18 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class UserPasswordUpdateApi method post.

@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
    UserData userData;
    if (request.getEmail() != null && request.getVerificationToken() != null) {
        // Verifying email
        UserDataUtil.verifyUserEmail(request.getEmail(), request.getVerificationToken());
        // Updating password
        UserDataUtil.updateUserPassword(request.getEmail(), request.getVerificationToken(), request.getNewPassword());
        // Logging-in the user
        userData = UserDataUtil.loginUser(request.getEmail(), request.getVerificationToken());
    } else if (request.getPassword() != null) {
        // Updating password
        UserDataUtil.updateUserPassword(request.getPassword(), request.getNewPassword());
        userData = UserDataUtil.getCurrentUser();
    } else {
        throw new InvalidArgumentException(GenericRequest.ERR_INSUFFICIENT_ARGS);
    }
    return new UserV1Api.Response(userData, UserPasswordUpdateApi.class);
}
Also used : InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) UserData(com.pratilipi.data.client.UserData) Post(com.pratilipi.api.annotation.Post)

Example 19 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class UserPratilipiReviewApi method post.

@Post
public UserPratilipiApi.Response post(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
    UserPratilipiData userPratilipiData = UserPratilipiDataUtil.saveUserPratilipiReview(AccessTokenFilter.getAccessToken().getUserId(), request.pratilipiId, request.rating, request.review, request.reviewState);
    Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", request.pratilipiId.toString()).addParam("updateReviewsDoc", "true").addParam("updateUserPratilipiStats", "true");
    TaskQueueFactory.getPratilipiTaskQueue().add(task);
    return new UserPratilipiApi.Response(userPratilipiData, UserPratilipiReviewApi.class);
}
Also used : Task(com.pratilipi.taskqueue.Task) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) Post(com.pratilipi.api.annotation.Post)

Example 20 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class UserAuthorFollowV2Api method post.

@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
    Long userId = AccessTokenFilter.getAccessToken().getUserId();
    UserAuthorData userAuthorData = UserAuthorDataUtil.saveUserAuthorFollow(userId, request.authorId, request.state);
    Task task_1 = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", request.authorId.toString()).addParam("updateUserAuthorStats", "true");
    Task task_2 = TaskQueueFactory.newTask().setUrl("/user/process").addParam("userId", userId.toString()).addParam("updateFollowsDoc", "true").addParam("updateUserAuthorStats", "true");
    TaskQueueFactory.getUserAuthorTaskQueue().addAll(task_1, task_2);
    return new Response(userAuthorData);
}
Also used : Task(com.pratilipi.taskqueue.Task) UserAuthorData(com.pratilipi.data.client.UserAuthorData) Post(com.pratilipi.api.annotation.Post)

Aggregations

Post (com.pratilipi.api.annotation.Post)32 GenericResponse (com.pratilipi.api.shared.GenericResponse)22 Task (com.pratilipi.taskqueue.Task)15 DataAccessor (com.pratilipi.data.DataAccessor)6 UserData (com.pratilipi.data.client.UserData)6 Gson (com.google.gson.Gson)5 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)5 BlobEntry (com.pratilipi.data.type.BlobEntry)5 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)3 Author (com.pratilipi.data.type.Author)3 Page (com.pratilipi.data.type.Page)3 Pratilipi (com.pratilipi.data.type.Pratilipi)3 Date (java.util.Date)3 JsonObject (com.google.gson.JsonObject)2 GenericFileDownloadResponse (com.pratilipi.api.shared.GenericFileDownloadResponse)2 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)2 AuthorData (com.pratilipi.data.client.AuthorData)2 UserAuthorData (com.pratilipi.data.client.UserAuthorData)2 AccessToken (com.pratilipi.data.type.AccessToken)2 ArrayList (java.util.ArrayList)2