mirror of
https://github.com/svek95/WST_Labs.git
synced 2026-05-18 02:51:45 +03:00
Add Lab6
This commit is contained in:
@@ -3,6 +3,7 @@ package Lab6;
|
||||
//import Lab3.Exception.CarServiceFault;
|
||||
//import Lab3.Exception.WrongValueExcept;
|
||||
import Lab6.Exception.WrongValueException;
|
||||
import Lab6.Exception.WrongIDException;
|
||||
import Lab4.common.Car;
|
||||
import Lab5.CarsDAO;
|
||||
|
||||
@@ -57,15 +58,19 @@ public class CarExceptionsResource {
|
||||
return String.valueOf(carDao.updateDB(id, name, model, country, dateOfSales, power));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Delete
|
||||
|
||||
@Path("/delete/ID")
|
||||
@DELETE
|
||||
public String deleteCars(@QueryParam("id") Integer id) {
|
||||
public String deleteCars(@QueryParam("id") Integer id) throws WrongIDException {
|
||||
|
||||
if (carDao.findID(id)){
|
||||
return carDao.deleteDB(id).getStringValue();
|
||||
} else {
|
||||
throw new WrongIDException(id, "delete");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package Lab6.Exception;
|
||||
|
||||
public class WrongIDException extends Exception {
|
||||
|
||||
private final static String TEMPLATE_OF_MESSAGE = "Error operation Car id is not found";
|
||||
|
||||
public WrongIDException(Integer id, String command ){
|
||||
super(String.format(TEMPLATE_OF_MESSAGE, id, command));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user