fix category creation

This commit is contained in:
Athou
2013-04-19 09:04:10 +02:00
parent 6fdd07f810
commit 136a45641f
2 changed files with 46 additions and 4 deletions

View File

@@ -0,0 +1,40 @@
package com.commafeed.frontend.model.request;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.wordnik.swagger.annotations.ApiClass;
import com.wordnik.swagger.annotations.ApiProperty;
@SuppressWarnings("serial")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@ApiClass("Add Category Request")
public class AddCategoryRequest implements Serializable {
@ApiProperty(value = "name", required = true)
private String name;
@ApiProperty(value = "parent category id, if any")
private String parentId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
}

View File

@@ -26,6 +26,7 @@ import com.commafeed.frontend.model.Category;
import com.commafeed.frontend.model.Entries;
import com.commafeed.frontend.model.Entry;
import com.commafeed.frontend.model.Subscription;
import com.commafeed.frontend.model.request.AddCategoryRequest;
import com.commafeed.frontend.model.request.CollapseRequest;
import com.commafeed.frontend.model.request.IDRequest;
import com.commafeed.frontend.model.request.MarkRequest;
@@ -116,13 +117,14 @@ public class CategoryREST extends AbstractResourceREST {
@POST
@ApiOperation(value = "Add a category", notes = "Add a new feed category")
public Response addCategory(
@ApiParam(value = "new name", required = true) @QueryParam("name") String name,
@ApiParam(value = "parent category id, if any") @QueryParam("parentId") String parentId) {
Preconditions.checkNotNull(name);
@ApiParam(required = true) AddCategoryRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getName());
FeedCategory cat = new FeedCategory();
cat.setName(name);
cat.setName(req.getName());
cat.setUser(getUser());
String parentId = req.getParentId();
if (parentId != null && !ALL.equals(parentId)) {
FeedCategory parent = new FeedCategory();
parent.setId(Long.valueOf(parentId));