public Result listarAlumnos() { Result res; List<Alumno> alumnos = Alumno.findAll(); if (ControllerHelper.acceptsJson(request())) { res = ok(Json.toJson(alumnos)); } else if (ControllerHelper.acceptsXml(request())) { res = ok(views.xml.alumnos.render(alumnos)); } else { res = badRequest(ControllerHelper.errorJson(1, "unsupported_format", null)); } return res; }
// {"id":"12345678", "nombre":"aaaa", "apellido1":"bbbb", "apellido2":"ccccc"} public Result getAlumno(String id) { Result res; Alumno alumno = Alumno.find.byId(id); if (alumno == null) { res = notFound(); } else { if (ControllerHelper.acceptsJson(request())) { res = ok(Json.toJson(alumno)); } else if (ControllerHelper.acceptsXml(request())) { res = ok(views.xml.alumno.render(alumno)); } else { res = badRequest(ControllerHelper.errorJson(1, "unsupported_format", null)); } } return res; }
public Result crearAlumno() { Form<Alumno> form = Form.form(Alumno.class).bindFromRequest(); if (form.hasErrors()) { return badRequest(ControllerHelper.errorJson(2, "invalid_alumno", form.errorsAsJson())); } Alumno alumno = form.get(); alumno.save(); return created(); }
public Result actualizarAlumno(String id) { Alumno alumno = Alumno.find.byId(id); if (alumno == null) { return notFound(); } Form<Alumno> form = Form.form(Alumno.class).bindFromRequest(); if (form.hasErrors()) { return badRequest(ControllerHelper.errorJson(1, "invalid_alumno", form.errorsAsJson())); } Result res; if (alumno.changeData(form.get())) { alumno.save(); res = ok(); } else { res = status(NOT_MODIFIED); } return res; }