コード例 #1
0
  // R GET
  @GET
  @Path("/{id}")
  @Produces(MediaType.APPLICATION_JSON)
  @ApiOperation(
      value = "Find Employee by ID",
      notes = "Finds an employee with its id in the database")
  @ApiResponses(
      value = {
        @ApiResponse(code = 200, message = "Success"),
        @ApiResponse(code = 404, message = "Not Found"),
        @ApiResponse(code = 500, message = "Internal Server Error")
      })
  public Employee get(@PathParam("id") int empId) {
    Employee emp;

    try {
      EmployeeDAO edao = new EmployeeDAO();
      emp = edao.getOne(empId);
      if (emp == null) {
        throw new WebApplicationException(Status.NOT_FOUND);
      }
    } catch (AppException e) {
      e.printStackTrace();
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }

    return emp;
  }
コード例 #2
0
 // C POST
 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 @ApiOperation(value = "Create", notes = "Creates an employee")
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Success"),
       @ApiResponse(code = 500, message = "Internal Server Error")
     })
 public Employee create(Employee emp) {
   try {
     EmployeeDAO edao = new EmployeeDAO();
     emp = edao.createOne(emp);
   } catch (AppException e) {
     e.printStackTrace();
     throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
   }
   return emp;
 }
コード例 #3
0
 // D DELETE
 @DELETE
 @Path("/{id}")
 @Produces(MediaType.APPLICATION_JSON)
 @ApiOperation(value = "Delete", notes = "Deletes an employee")
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Success"),
       @ApiResponse(code = 404, message = "Not Found"),
       @ApiResponse(code = 500, message = "Internal Server Error")
     })
 public void delete(@PathParam("id") int empId) {
   try {
     EmployeeDAO edao = new EmployeeDAO();
     edao.deleteOne(empId);
   } catch (AppException e) {
     e.printStackTrace();
     throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
   }
 }
コード例 #4
0
 // R GET ALL
 @GET
 @Path("/all")
 @Produces(MediaType.APPLICATION_JSON)
 @ApiOperation(value = "Find All Employees", notes = "Finds all employees in the database")
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Success"),
       @ApiResponse(code = 500, message = "Internal Server Error")
     })
 public List<Employee> getAll() {
   List<Employee> employees = null;
   try {
     EmployeeDAO dao = new EmployeeDAO();
     employees = dao.getAllEmployees();
   } catch (AppException e) {
     e.printStackTrace();
     throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
   }
   return employees;
 }