mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 09:42:08 +10:00
send comments functionality
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package org.diylc.plugins.cloud.model;
|
||||
|
||||
public class CommentEntity {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CommentEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int id;
|
||||
private int userId;
|
||||
private int parentId;
|
||||
private String username;
|
||||
private String comment;
|
||||
private String postedAt;
|
||||
@@ -16,12 +20,12 @@ public class CommentEntity {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
public int getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
public void setParentId(int parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@@ -40,12 +44,12 @@ public class CommentEntity {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
public String getPostedAt() {
|
||||
return postedAt;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.postedAt = date;
|
||||
public void setPostedAt(String postedAt) {
|
||||
this.postedAt = postedAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,9 +57,9 @@ public class CommentEntity {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((comment == null) ? 0 : comment.hashCode());
|
||||
result = prime * result + ((postedAt == null) ? 0 : postedAt.hashCode());
|
||||
result = prime * result + id;
|
||||
result = prime * result + userId;
|
||||
result = prime * result + parentId;
|
||||
result = prime * result + ((postedAt == null) ? 0 : postedAt.hashCode());
|
||||
result = prime * result + ((username == null) ? 0 : username.hashCode());
|
||||
return result;
|
||||
}
|
||||
@@ -74,15 +78,15 @@ public class CommentEntity {
|
||||
return false;
|
||||
} else if (!comment.equals(other.comment))
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (parentId != other.parentId)
|
||||
return false;
|
||||
if (postedAt == null) {
|
||||
if (other.postedAt != null)
|
||||
return false;
|
||||
} else if (!postedAt.equals(other.postedAt))
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (userId != other.userId)
|
||||
return false;
|
||||
if (username == null) {
|
||||
if (other.username != null)
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.diylc.plugins.cloud.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommentTree {
|
||||
|
||||
private CommentEntity rootComment;
|
||||
private List<CommentEntity> replies;
|
||||
|
||||
public CommentTree(CommentEntity rootComment) {
|
||||
this.rootComment = rootComment;
|
||||
this.replies = new ArrayList<CommentEntity>();
|
||||
}
|
||||
|
||||
public CommentEntity getRootComment() {
|
||||
return rootComment;
|
||||
}
|
||||
|
||||
public List<CommentEntity> getReplies() {
|
||||
return replies;
|
||||
}
|
||||
}
|
||||
@@ -124,6 +124,20 @@ public interface IServiceAPI {
|
||||
@ParamName("diylcVersion") String diylcVersion, @ParamName("keywords") String keywords,
|
||||
@ParamName("thumbnail") File thumbnail, @ParamName("project") File project);
|
||||
|
||||
/**
|
||||
* Posts a comment to the specified project.
|
||||
*
|
||||
* @param username
|
||||
* @param token
|
||||
* @param machineId
|
||||
* @param projectId
|
||||
* @param comment
|
||||
* @return
|
||||
*/
|
||||
String postComment(@ParamName("username") String username, @ParamName("token") String token,
|
||||
@ParamName("machineId") String machineId, @ParamName("projectId") Integer projectId,
|
||||
@ParamName("comment") String comment);
|
||||
|
||||
/**
|
||||
* @return a {@link List} of available categories.
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ public class UserEntity implements Serializable {
|
||||
private String website;
|
||||
private String bio;
|
||||
|
||||
public UserEntity(String userName, String email, String website, String bio) {
|
||||
public UserEntity(String username, String email, String website, String bio) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
|
||||
@@ -152,7 +152,22 @@ public class CloudPresenter {
|
||||
} catch (Exception e) {
|
||||
throw new CloudException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void postComment(int projectId, String comment) throws CloudException {
|
||||
String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
|
||||
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null);
|
||||
|
||||
if (username == null || token == null)
|
||||
throw new CloudException("Login failed. Please try to login again.");
|
||||
|
||||
try {
|
||||
String res = service.postComment(username, token, getMachineId(), projectId, comment);
|
||||
if (!res.equals(SUCCESS))
|
||||
throw new CloudException(res);
|
||||
} catch (Exception e) {
|
||||
throw new CloudException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void createUserAccount(String username, String password, String email, String website, String bio)
|
||||
@@ -185,6 +200,10 @@ public class CloudPresenter {
|
||||
throw new CloudException("Unexpected server response received for category list: " + res.getClass().getName());
|
||||
}
|
||||
|
||||
public String getCurrentUsername() {
|
||||
return ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
|
||||
}
|
||||
|
||||
public void updatePassword(String oldPassword, String newPassword) throws CloudException {
|
||||
String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
|
||||
|
||||
@@ -255,7 +274,7 @@ public class CloudPresenter {
|
||||
}
|
||||
}
|
||||
|
||||
public List<CommentEntity> GetComments(int projectId) throws CloudException {
|
||||
public List<CommentEntity> getComments(int projectId) throws CloudException {
|
||||
try {
|
||||
Object res = service.getComments(projectId);
|
||||
if (res == null)
|
||||
@@ -273,6 +292,7 @@ public class CloudPresenter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getMachineId() {
|
||||
if (machineId == null) {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.diylc.utils;
|
||||
|
||||
public class Pair<A, B> {
|
||||
|
||||
private A first;
|
||||
private B second;
|
||||
|
||||
public Pair(A first, B second) {
|
||||
super();
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public A getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public B getSecond() {
|
||||
return second;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user