Search in sources :

Example 1 with ClassStudentListResourceLinks

use of com.remswork.project.alice.resource.links.ClassStudentListResourceLinks in project classify-system by anverliedoit.

the class ClassStudentListResource method getStudentById.

@GET
@Path("{studentId}")
public Response getStudentById(@PathParam("classId") long classId, @PathParam("studentId") long id) {
    try {
        ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
        Student student = classService.getStudentById(classId, id);
        student.addLink(resourceLinks.self(classId, id));
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (ClassException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) Message(com.remswork.project.alice.model.support.Message) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Example 2 with ClassStudentListResourceLinks

use of com.remswork.project.alice.resource.links.ClassStudentListResourceLinks in project classify-system by anverliedoit.

the class ClassStudentListResource method getStudentList.

@GET
public Response getStudentList(@PathParam("classId") long classId) {
    try {
        ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
        Set<Student> studentSet = classService.getStudentList(classId);
        for (Student student : studentSet) student.addLink(resourceLinks.self(classId, student.getId()));
        GenericEntity<Set<Student>> entity = new GenericEntity<Set<Student>>(studentSet) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (ClassException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) Set(java.util.Set) Message(com.remswork.project.alice.model.support.Message) GenericEntity(javax.ws.rs.core.GenericEntity) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Example 3 with ClassStudentListResourceLinks

use of com.remswork.project.alice.resource.links.ClassStudentListResourceLinks in project classify-system by anverliedoit.

the class ClassStudentListResource method deleteStudentById.

@DELETE
@Path("{studentId}")
public Response deleteStudentById(@PathParam("classId") long classId, @PathParam("studentId") long id) {
    try {
        ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
        Student student = classService.deleteStudentById(classId, id);
        student.addLink(resourceLinks.self(classId, id));
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (ClassException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) Message(com.remswork.project.alice.model.support.Message) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Example 4 with ClassStudentListResourceLinks

use of com.remswork.project.alice.resource.links.ClassStudentListResourceLinks in project classify-system by anverliedoit.

the class ClassStudentListResource method addStudentById.

@POST
public Response addStudentById(@PathParam("classId") long classId) {
    try {
        ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
        if (studentId == 0)
            throw new ClassDaoException("Query param : studentId is required");
        Student student = classService.addStudentById(classId, studentId);
        student.addLink(resourceLinks.self(classId, studentId));
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (ClassException | ClassDaoException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Message(com.remswork.project.alice.model.support.Message) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Aggregations

ClassException (com.remswork.project.alice.exception.ClassException)4 Student (com.remswork.project.alice.model.Student)4 Message (com.remswork.project.alice.model.support.Message)4 ClassStudentListResourceLinks (com.remswork.project.alice.resource.links.ClassStudentListResourceLinks)4 ClassDaoException (com.remswork.project.alice.dao.exception.ClassDaoException)1 Set (java.util.Set)1 GenericEntity (javax.ws.rs.core.GenericEntity)1