use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class UserAuthorFollowV1Api method post.
@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
Long userId = AccessTokenFilter.getAccessToken().getUserId();
UserAuthorData userAuthorData = UserAuthorDataUtil.saveUserAuthorFollow(userId, request.authorId, request.following ? UserFollowState.FOLLOWING : UserFollowState.UNFOLLOWED);
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);
}
use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class TagsApi method addTags.
@Post
public GenericResponse addTags(PostRequest request) throws InsufficientAccessException {
// Security Hack
AccessToken accessToken = AccessTokenFilter.getAccessToken();
if (accessToken.getUserId() != 5073076857339904L) {
Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "AccessToken : " + accessToken.getId());
Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "User Id : " + accessToken.getUserId());
throw new InsufficientAccessException();
}
Gson gson = new Gson();
// Creating TagData object.
TagData tagData = gson.fromJson(gson.toJson(request), TagData.class);
tagData = TagDataUtil.saveTag(tagData);
return new GenericResponse();
}
use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class VoteApi method post.
@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
VoteData voteData = VoteDataUtil.saveVoteData(AccessTokenFilter.getAccessToken().getUserId(), request.parentType, request.parentId, request.type);
if (voteData.getReferenceType() == ReferenceType.PRATILIPI) {
Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", voteData.getReferenceId()).addParam("updateReviewsDoc", "true");
TaskQueueFactory.getPratilipiTaskQueue().add(task);
}
return new GenericResponse();
}
use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class UserV1Api method post.
@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
UserData userData = request.userId == null ? new UserData(AccessTokenFilter.getAccessToken().getUserId()) : new UserData(request.userId.equals(0L) ? null : request.userId);
if (request.hasName) {
String firstName = request.name.trim();
String lastName = null;
if (firstName.lastIndexOf(' ') != -1) {
lastName = firstName.substring(firstName.lastIndexOf(' ') + 1);
firstName = firstName.substring(0, firstName.lastIndexOf(' '));
}
userData.setFirstName(firstName);
userData.setLastName(lastName);
}
if (request.hasEmail)
userData.setEmail(request.email);
if (request.hasPhone)
userData.setPhone(request.phone);
if (request.hasLanguage)
userData.setLanguage(request.language);
// Save UserData
userData = UserDataUtil.saveUserData(userData);
// New User (added by AEE)
if (request.userId != null && request.userId.equals(0L)) {
// Create Author profile for the User
Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language == null ? UxModeFilter.getFilterLanguage() : request.language);
userData.setAuthor(new AuthorData(authorId));
userData.setProfilePageUrl("/author/" + authorId);
// Send welcome mail to the user
Task task = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", request.language == null ? UxModeFilter.getDisplayLanguage().toString() : request.language.toString()).addParam("sendWelcomeMail", "true");
TaskQueueFactory.getUserTaskQueue().add(task);
}
// Send verification mail if user updates his email and state is REGISTERED
if (request.hasEmail && userData.getState() == UserState.REGISTERED) {
Task task = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", (userData.getLanguage() == null ? Language.ENGLISH : userData.getLanguage()).toString()).addParam("sendEmailVerificationMail", "true");
TaskQueueFactory.getUserTaskQueue().add(task);
}
// Process Author data
Task task = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", userData.getAuthor().getId().toString()).addParam("processData", "true");
TaskQueueFactory.getAuthorTaskQueue().add(task);
return new Response(userData);
}
use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class PratilipiTagsUpdateApi method updatePratilipiTags.
@Post
public PostResponse updatePratilipiTags(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
List<Long> tagIds = request.getTagIds();
List<String> suggestedTags = request.getSuggestedTags();
PratilipiType pratilipiType = request.getPratilipiType();
Long pratilipiId = request.getPratilipiId();
Logger.getLogger(PratilipiTagsUpdateApi.class.getSimpleName()).log(Level.INFO, "TagIds : " + tagIds);
Logger.getLogger(PratilipiTagsUpdateApi.class.getSimpleName()).log(Level.INFO, "SuggestedTags : " + suggestedTags);
if (tagIds == null && suggestedTags == null)
throw new UnexpectedServerException("Both tagIds and suggestedTags cannot be null");
boolean isUpdated = PratilipiDataUtil.updatePratilipiTags(pratilipiId, pratilipiType, tagIds, suggestedTags);
return new PostResponse(isUpdated);
}
Aggregations