use of models.FeaturedModule in project modules.playframework.org by playframework.
the class FeaturedModules method delete.
public static Result delete() {
Map<String, String[]> postParams = request().body().asFormUrlEncoded();
String[] ids = postParams.get("id");
Result result;
if (ids.length != 1) {
result = badRequest("A featured module must be defined");
} else {
FeaturedModule featuredModule = FeaturedModule.FIND.byId(Long.parseLong(ids[0]));
featuredModule.delete();
ObjectNode node = Json.newObject();
node.put("id", featuredModule.id);
result = ok(node);
}
return result;
}
use of models.FeaturedModule in project modules.playframework.org by playframework.
the class FeaturedModules method addNewFeaturedModule.
public static Result addNewFeaturedModule() {
Result result;
Form<FeaturedModule> form = form(FeaturedModule.class).bindFromRequest();
if (form.hasErrors()) {
result = badRequest(featuredModules.render(currentUser(), FeaturedModule.getAll(), form));
} else {
FeaturedModule featuredModule = form.get();
Ebean.refresh(featuredModule.playModule);
if (StringUtils.isEmpty(featuredModule.description)) {
featuredModule.description = featuredModule.playModule.description;
}
featuredModule.creationDate = new Date();
featuredModule.save();
result = redirect(routes.FeaturedModules.showFeaturedModules());
}
return result;
}
use of models.FeaturedModule in project modules.playframework.org by playframework.
the class FeaturedModules method update.
public static Result update() {
Result result;
Form<FeaturedModule> form = form(FeaturedModule.class).bindFromRequest();
if (form.hasErrors()) {
result = badRequest(form.errorsAsJson());
} else {
FeaturedModule incoming = form.get();
FeaturedModule storedVersion = FeaturedModule.FIND.byId(incoming.id);
storedVersion.description = StringUtils.isEmpty(incoming.description) ? storedVersion.playModule.description : incoming.description;
storedVersion.sticky = incoming.sticky;
storedVersion.save();
// Annoying - converting storedVersion directly to JSON results in a cycle according to Jackson
// Buggered if I can see why though
ObjectNode node = Json.newObject();
node.put("id", storedVersion.id);
node.put("description", storedVersion.description);
node.put("sticky", storedVersion.sticky);
result = ok(node);
}
return result;
}
Aggregations