mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
added rest methods for updating positions
This commit is contained in:
@@ -51,6 +51,13 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
||||
return category;
|
||||
}
|
||||
|
||||
public List<FeedCategory> findByParent(User user, FeedCategory parent) {
|
||||
EasyCriteria<FeedCategory> criteria = createCriteria();
|
||||
criteria.andEquals(FeedCategory_.user.getName(), user);
|
||||
criteria.andEquals(FeedCategory_.parent.getName(), parent);
|
||||
return criteria.getResultList();
|
||||
}
|
||||
|
||||
public List<FeedCategory> findAllChildrenCategories(User user,
|
||||
FeedCategory parent) {
|
||||
List<FeedCategory> list = Lists.newArrayList();
|
||||
@@ -77,4 +84,5 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
||||
}
|
||||
return isChild;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ public class CategoryModificationRequest implements Serializable {
|
||||
@ApiProperty(value = "new parent category id")
|
||||
private String parentId;
|
||||
|
||||
@ApiProperty(value = "new display position, null if not changed")
|
||||
private Integer position;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -48,4 +51,12 @@ public class CategoryModificationRequest implements Serializable {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ public class FeedModificationRequest implements Serializable {
|
||||
@ApiProperty(value = "new parent category id")
|
||||
private String categoryId;
|
||||
|
||||
@ApiProperty(value = "new display position, null if not changed")
|
||||
private Integer position;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -48,4 +51,12 @@ public class FeedModificationRequest implements Serializable {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -266,6 +266,31 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
Long.valueOf(req.getParentId()));
|
||||
}
|
||||
category.setParent(parent);
|
||||
|
||||
if (req.getPosition() != null) {
|
||||
List<FeedCategory> categories = feedCategoryDAO.findByParent(
|
||||
getUser(), parent);
|
||||
int existingIndex = -1;
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
if (ObjectUtils.equals(categories.get(i).getId(),
|
||||
category.getId())) {
|
||||
existingIndex = i;
|
||||
}
|
||||
}
|
||||
if (existingIndex != -1) {
|
||||
categories.remove(existingIndex);
|
||||
}
|
||||
|
||||
categories.add(Math.min(req.getPosition(), categories.size()),
|
||||
category);
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
categories.get(i).setPosition(i);
|
||||
}
|
||||
feedCategoryDAO.update(categories);
|
||||
} else {
|
||||
feedCategoryDAO.update(category);
|
||||
}
|
||||
|
||||
feedCategoryDAO.update(category);
|
||||
|
||||
return Response.ok(Status.OK).build();
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -327,7 +328,29 @@ public class FeedREST extends AbstractResourceREST {
|
||||
Long.valueOf(req.getCategoryId()));
|
||||
}
|
||||
subscription.setCategory(parent);
|
||||
feedSubscriptionDAO.update(subscription);
|
||||
|
||||
if (req.getPosition() != null) {
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(
|
||||
getUser(), parent);
|
||||
int existingIndex = -1;
|
||||
for (int i = 0; i < subs.size(); i++) {
|
||||
if (ObjectUtils.equals(subs.get(i).getId(),
|
||||
subscription.getId())) {
|
||||
existingIndex = i;
|
||||
}
|
||||
}
|
||||
if (existingIndex != -1) {
|
||||
subs.remove(existingIndex);
|
||||
}
|
||||
|
||||
subs.add(Math.min(req.getPosition(), subs.size()), subscription);
|
||||
for (int i = 0; i < subs.size(); i++) {
|
||||
subs.get(i).setPosition(i);
|
||||
}
|
||||
feedSubscriptionDAO.update(subs);
|
||||
} else {
|
||||
feedSubscriptionDAO.update(subscription);
|
||||
}
|
||||
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user