Skip to content

Commit

Permalink
page list category
Browse files Browse the repository at this point in the history
  • Loading branch information
weishiji committed Apr 26, 2017
1 parent fcb029d commit e47f27d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/rest/CategoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Result list(){
public Result create(){
Category category = new Category();
Form<Category> categoryForm = formFactory.form(Category.class).bindFromRequest();

response();
if(categoryForm.hasErrors()){
return badRequest(
categoryForm.errorsAsJson()
Expand Down
18 changes: 18 additions & 0 deletions app/models/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.avaje.ebean.FetchConfig;
import com.avaje.ebean.Model;
import com.avaje.ebean.PagedList;
import javafx.beans.DefaultProperty;
import org.springframework.format.annotation.DateTimeFormat;
import play.data.format.Formats;
Expand Down Expand Up @@ -88,5 +89,22 @@ public List<Category> list(){
.findList();
return category;
}
/**
* Return a paged list of computer
*
* @param page Page to display
* @param pageSize Number of computers per page
* @param sortBy Computer property used for sorting
* @param order Sort order (either or asc or desc)
* @param filter Filter applied on the name column
*/
public static PagedList<Category> page(int page, int pageSize, String sortBy, String order, String filter) {
return
Category.find
.fetch("product_to_category")
.where()
.eq("status",1)
.findPagedList(page, pageSize);
}

}
8 changes: 6 additions & 2 deletions app/utils/ResponseJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import play.api.mvc.ResponseHeader;
import play.http.HttpEntity;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;

Expand All @@ -25,7 +26,7 @@
/**
* Created by lxg on 24/04/2017.
*/
public class ResponseJson{
public class ResponseJson extends Controller{
static String OK_MESSAGE = "Success"; // 200
static String CREATE_MESSAGE = "Create Success"; //201
static String BAD_REQUEST_MESSAGE = "Bad Request"; // 400
Expand Down Expand Up @@ -100,13 +101,16 @@ public static ObjectNode format(JsonNode response, Integer status){
}
/**
* @param response Model Object List
* @param status Http status
* @param status Http status Integer
* */
public static ObjectNode format(List<?> response,Integer status){
ObjectNode result = Json.newObject();
ObjectNode messageResult = format(status);

result.set("message",messageResult.get("message"));
if(response.isEmpty()){
return result;
}
JsonNode jsonNode = Json.toJson(response);
result.set("data", jsonNode);

Expand Down

0 comments on commit e47f27d

Please sign in to comment.