diff --git a/src/main/java/fr/geoffrey/medical_training_tracker/controller/AnimalController.java b/src/main/java/fr/geoffrey/medical_training_tracker/controller/AnimalController.java index 0b8ee95..a1e5f57 100644 --- a/src/main/java/fr/geoffrey/medical_training_tracker/controller/AnimalController.java +++ b/src/main/java/fr/geoffrey/medical_training_tracker/controller/AnimalController.java @@ -176,6 +176,30 @@ public class AnimalController { return ret; } + @RequestMapping(value = IndexController.URL_ANIMAL_EDIT_CARE, method = RequestMethod.POST) + public String doPostEditCare(final ModelMap pModel, HttpSession httpSession, + @PathVariable(value = "animal_id") final int animalId, + @PathVariable(value = "care_id") final int careId, + @RequestParam(name = "name", required = true) String name, + @RequestParam(name = "description", required = false, defaultValue = "") String description) { + + String ret; + if (LoginController.isUserAlreadyAuth(httpSession)) { + Authentication authentication = (Authentication) httpSession.getAttribute(IndexController.SESSION_ATTRIBUTE_AUTHENTICATION); + Object oUserDetails = authentication.getPrincipal(); + if (oUserDetails instanceof UserDetails) { + UserDetails userDetails = (UserDetails) oUserDetails; + + serviceAnimal.updateCare(careId, animalId, userDetails.getUsername(), name, description); + } + ret = IndexController.URL_REDIRECT + IndexController.URL_ANIMAL_CARES_AND_BEHAVIORS_LIST.replaceAll("\\{animal_id\\}", animalId + ""); + } else { + ret = IndexController.URL_REDIRECT + IndexController.URL_LOGIN; + } + + return ret; + } + @RequestMapping(value = IndexController.URL_ANIMAL_CARES_DELETE, method = RequestMethod.POST) public String doPostDeleteCare(final ModelMap pModel, HttpSession httpSession, @PathVariable(value = "animal_id") final int animalId, @@ -223,6 +247,30 @@ public class AnimalController { return ret; } + @RequestMapping(value = IndexController.URL_ANIMAL_EDIT_CONSENT_BEHAVIOR, method = RequestMethod.POST) + public String doPostEditAnimal(final ModelMap pModel, HttpSession httpSession, + @PathVariable(value = "animal_id") final int animalId, + @PathVariable(value = "consent_behavior_id") final int consentBehaviorId, + @RequestParam(name = "name", required = true) String name, + @RequestParam(name = "description", required = false, defaultValue = "") String description) { + + String ret; + if (LoginController.isUserAlreadyAuth(httpSession)) { + Authentication authentication = (Authentication) httpSession.getAttribute(IndexController.SESSION_ATTRIBUTE_AUTHENTICATION); + Object oUserDetails = authentication.getPrincipal(); + if (oUserDetails instanceof UserDetails) { + UserDetails userDetails = (UserDetails) oUserDetails; + + serviceAnimal.updateConsentBehavior(consentBehaviorId, animalId, userDetails.getUsername(), name, description); + } + ret = IndexController.URL_REDIRECT + IndexController.URL_ANIMAL_CARES_AND_BEHAVIORS_LIST.replaceAll("\\{animal_id\\}", animalId + ""); + } else { + ret = IndexController.URL_REDIRECT + IndexController.URL_LOGIN; + } + + return ret; + } + @RequestMapping(value = IndexController.URL_ANIMAL_CONSENT_BEHAVIOR_DELETE, method = RequestMethod.POST) public String doPostDeleteConsentBehavior(final ModelMap pModel, HttpSession httpSession, @PathVariable(value = "animal_id") final int animalId, diff --git a/src/main/java/fr/geoffrey/medical_training_tracker/controller/IndexController.java b/src/main/java/fr/geoffrey/medical_training_tracker/controller/IndexController.java index 52733e7..a630cb4 100644 --- a/src/main/java/fr/geoffrey/medical_training_tracker/controller/IndexController.java +++ b/src/main/java/fr/geoffrey/medical_training_tracker/controller/IndexController.java @@ -60,7 +60,9 @@ public class IndexController { public static final String URL_ANIMAL_CONSENT_BEHAVIOR_DELETE = "/animal/{animal_id}/delete/consent_behavior/{consent_behavior_id}"; public static final String URL_ANIMAL_PROGRESSION_DELETE = "/animal/{animal_id}/delete/progression/{progression_id}"; // Edit URL - public static final String URL_ANIMAL_EDIT = "/animal/edit/{animal_id}"; + public static final String URL_ANIMAL_EDIT = "/animal/{animal_id}/edit"; + public static final String URL_ANIMAL_EDIT_CARE = "/animal/{animal_id}/edit/care/{care_id}"; + public static final String URL_ANIMAL_EDIT_CONSENT_BEHAVIOR = "/animal/{animal_id}/edit/consent_behavior/{consent_behavior_id}"; public static final String URL_REDIRECT = "redirect:"; // diff --git a/src/main/java/fr/geoffrey/medical_training_tracker/dao/ICareDao.java b/src/main/java/fr/geoffrey/medical_training_tracker/dao/ICareDao.java index c691a22..1768b1c 100644 --- a/src/main/java/fr/geoffrey/medical_training_tracker/dao/ICareDao.java +++ b/src/main/java/fr/geoffrey/medical_training_tracker/dao/ICareDao.java @@ -16,4 +16,6 @@ public interface ICareDao extends CommonDao { public void addCare(int animalId, String name, String description); public void deleteCare(int careId, int animalId, String owner); public void deleteAllAnimalCares(int animalId, String owner); + + public void updateCare(int careId, int animalId, String owner, String name, String description); } diff --git a/src/main/java/fr/geoffrey/medical_training_tracker/dao/IConsentBehaviorDao.java b/src/main/java/fr/geoffrey/medical_training_tracker/dao/IConsentBehaviorDao.java index be1f33d..8073156 100644 --- a/src/main/java/fr/geoffrey/medical_training_tracker/dao/IConsentBehaviorDao.java +++ b/src/main/java/fr/geoffrey/medical_training_tracker/dao/IConsentBehaviorDao.java @@ -15,4 +15,6 @@ public interface IConsentBehaviorDao extends CommonDao { public void addConsentBehavior(int animalId, String name, String description); public void deleteConsentBehavior(int consentBehaviorId, int animalId, String owner); public void deleteAllAnimalConsentBehavior(int animalId, String owner); + + public void updateConsentBehavior(int consentBehaviorId, int animalId, String owner, String name, String description); } diff --git a/src/main/java/fr/geoffrey/medical_training_tracker/dao/bdd/postgres/CareDao.java b/src/main/java/fr/geoffrey/medical_training_tracker/dao/bdd/postgres/CareDao.java index 19ef467..2b90736 100644 --- a/src/main/java/fr/geoffrey/medical_training_tracker/dao/bdd/postgres/CareDao.java +++ b/src/main/java/fr/geoffrey/medical_training_tracker/dao/bdd/postgres/CareDao.java @@ -254,4 +254,41 @@ public class CareDao extends PostgresSqlDao implements ICareDao { } } } + + @Override + public void updateCare(int careId, int animalId, String owner, String name, String description) { + Connection conn = null; + PreparedStatement statement = null; + try { + conn = mDataSource.getConnection(); + statement = conn.prepareStatement("UPDATE "+TABLE_NAME+" SET name = ?, description = ? WHERE id = ? AND animal = (" + + "SELECT id FROM "+AnimalDao.TABLE_NAME+" WHERE owner = ? AND id = ?)"); + statement.setString(1, name); + statement.setString(2, description); + statement.setInt(3, careId); + statement.setString(4, owner); + statement.setInt(5, animalId); + System.out.println(IndexController.LOG_TAG + " SQL -> " + statement.toString()); + statement.executeUpdate(); + } catch (SQLException ex) { + System.err.println(IndexController.LOG_TAG + " SQLException -> updateCare()"); + System.err.println(ex.getMessage()); + ex.printStackTrace(); + } finally { + if (statement != null) { + try { + statement.close(); + } catch (SQLException ex) { + System.err.println(IndexController.LOG_TAG + " Failed close statement -> updateCare()"); + } + } + if (conn != null) { + try { + conn.close(); + } catch (SQLException ex) { + System.err.println(IndexController.LOG_TAG + " Failed close connection -> updateCare()"); + } + } + } + } } diff --git a/src/main/java/fr/geoffrey/medical_training_tracker/dao/bdd/postgres/ConsentBehaviorDao.java b/src/main/java/fr/geoffrey/medical_training_tracker/dao/bdd/postgres/ConsentBehaviorDao.java index cb8ba4e..350bb7c 100644 --- a/src/main/java/fr/geoffrey/medical_training_tracker/dao/bdd/postgres/ConsentBehaviorDao.java +++ b/src/main/java/fr/geoffrey/medical_training_tracker/dao/bdd/postgres/ConsentBehaviorDao.java @@ -254,4 +254,41 @@ public class ConsentBehaviorDao extends PostgresSqlDao implements IConsentBehavi } } } + + @Override + public void updateConsentBehavior(int consentBehaviorId, int animalId, String owner, String name, String description) { + Connection conn = null; + PreparedStatement statement = null; + try { + conn = mDataSource.getConnection(); + statement = conn.prepareStatement("UPDATE "+TABLE_NAME+" SET name = ?, description = ? WHERE id = ? AND animal = (" + + "SELECT id FROM "+AnimalDao.TABLE_NAME+" WHERE owner = ? AND id = ?)"); + statement.setString(1, name); + statement.setString(2, description); + statement.setInt(3, consentBehaviorId); + statement.setString(4, owner); + statement.setInt(5, animalId); + System.out.println(IndexController.LOG_TAG + " SQL -> " + statement.toString()); + statement.executeUpdate(); + } catch (SQLException ex) { + System.err.println(IndexController.LOG_TAG + " SQLException -> updateConsentBehavior()"); + System.err.println(ex.getMessage()); + ex.printStackTrace(); + } finally { + if (statement != null) { + try { + statement.close(); + } catch (SQLException ex) { + System.err.println(IndexController.LOG_TAG + " Failed close statement -> updateConsentBehavior()"); + } + } + if (conn != null) { + try { + conn.close(); + } catch (SQLException ex) { + System.err.println(IndexController.LOG_TAG + " Failed close connection -> updateConsentBehavior()"); + } + } + } + } } diff --git a/src/main/java/fr/geoffrey/medical_training_tracker/services/IServiceAnimal.java b/src/main/java/fr/geoffrey/medical_training_tracker/services/IServiceAnimal.java index 2603e42..a11b46b 100644 --- a/src/main/java/fr/geoffrey/medical_training_tracker/services/IServiceAnimal.java +++ b/src/main/java/fr/geoffrey/medical_training_tracker/services/IServiceAnimal.java @@ -29,4 +29,7 @@ public interface IServiceAnimal { public void changeAnimalName(int animalId, String owner, String name); + public void updateCare(int careId, int animalId, String owner, String name, String description); + public void updateConsentBehavior(int consentBehaviorId, int animalId, String owner, String name, String description); + } diff --git a/src/main/java/fr/geoffrey/medical_training_tracker/services/ServiceAnimal.java b/src/main/java/fr/geoffrey/medical_training_tracker/services/ServiceAnimal.java index be4fa44..3fe04b9 100644 --- a/src/main/java/fr/geoffrey/medical_training_tracker/services/ServiceAnimal.java +++ b/src/main/java/fr/geoffrey/medical_training_tracker/services/ServiceAnimal.java @@ -155,4 +155,14 @@ public class ServiceAnimal implements IServiceAnimal { public void changeAnimalName(int animalId, String owner, String name) { animalDao.changeName(animalId, owner, name); } + + @Override + public void updateCare(int careId, int animalId, String owner, String name, String description) { + careDao.updateCare(careId, animalId, owner, name, description); + } + + @Override + public void updateConsentBehavior(int consentBehaviorId, int animalId, String owner, String name, String description) { + consentBehaviorDao.updateConsentBehavior(consentBehaviorId, animalId, owner, name, description); + } } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index cd18c5e..e665532 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -93,3 +93,15 @@ animal_list.animal.edit.tooltip=Edit animal_list.edit_animal.modal.label=Animal's name: animal_list.edit_animal.modal.placeholder=New name modal_button.edit=Edit +animal_care_and_behavior.button.edit.tooltip=Edit +animal_list.edit_animal.modal.title=Editing animal's name +animal_care_and_behavior.edit_care.modal.title=Editing care +animal_care_and_behavior.edit_care.modal.name.label=Care name: +animal_care_and_behavior.edit_care.modal.name.placeholder=Care name +animal_care_and_behavior.edit_care.modal.description.label=Care description: +animal_care_and_behavior.edit_care.modal.description.placeholder=Care description (optional) +animal_care_and_behavior.edit_behavior.modal.title=Editing consent behavior +animal_care_and_behavior.edit_behavior.modal.name.label=Consent behavior name: +animal_care_and_behavior.edit_behavior.modal.name.placeholder=Consent behavior name +animal_care_and_behavior.edit_behavior.modal.description.label=Consent behavior description: +animal_care_and_behavior.edit_behavior.modal.description.placeholder=Consent behavior description (optional) diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 16fab5c..f4b512c 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -89,3 +89,15 @@ animal_list.animal.edit.tooltip=Edit animal_list.edit_animal.modal.label=Animal's name: animal_list.edit_animal.modal.placeholder=New name modal_button.edit=Edit +animal_care_and_behavior.button.edit.tooltip=Edit +animal_list.edit_animal.modal.title=Editing animal's name +animal_care_and_behavior.edit_care.modal.title=Editing care +animal_care_and_behavior.edit_care.modal.name.label=Care name: +animal_care_and_behavior.edit_care.modal.name.placeholder=Care name +animal_care_and_behavior.edit_care.modal.description.label=Care description: +animal_care_and_behavior.edit_care.modal.description.placeholder=Care description (optional) +animal_care_and_behavior.edit_behavior.modal.title=Editing consent behavior +animal_care_and_behavior.edit_behavior.modal.name.label=Consent behavior name: +animal_care_and_behavior.edit_behavior.modal.name.placeholder=Consent behavior name +animal_care_and_behavior.edit_behavior.modal.description.label=Consent behavior description: +animal_care_and_behavior.edit_behavior.modal.description.placeholder=Consent behavior description (optional) diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties index 51c4496..53ab14c 100644 --- a/src/main/resources/messages_fr.properties +++ b/src/main/resources/messages_fr.properties @@ -89,3 +89,15 @@ animal_list.animal.edit.tooltip=Modifier animal_list.edit_animal.modal.label=Nom de l'animal : animal_list.edit_animal.modal.placeholder=Nouveau nom modal_button.edit=Modifier +animal_care_and_behavior.button.edit.tooltip=Modifier +animal_list.edit_animal.modal.title=Modifier le nom de l'animal +animal_care_and_behavior.edit_care.modal.title=Modification du soin +animal_care_and_behavior.edit_care.modal.name.label=Nom du soin : +animal_care_and_behavior.edit_care.modal.name.placeholder=Nom du soin +animal_care_and_behavior.edit_care.modal.description.label=Description du soin : +animal_care_and_behavior.edit_care.modal.description.placeholder=Description du soin (optionelle) +animal_care_and_behavior.edit_behavior.modal.title=Modification du comportement de consentement +animal_care_and_behavior.edit_behavior.modal.name.label=Nom du comportement de consentement : +animal_care_and_behavior.edit_behavior.modal.name.placeholder=Nom du comportement de consentement +animal_care_and_behavior.edit_behavior.modal.description.label=Description du comportement de consentment : +animal_care_and_behavior.edit_behavior.modal.description.placeholder=Description du comportement de consentement (optionelle) diff --git a/src/main/webapp/vue/animal_cares_and_behaviors.jsp b/src/main/webapp/vue/animal_cares_and_behaviors.jsp index 56cedcb..25af213 100644 --- a/src/main/webapp/vue/animal_cares_and_behaviors.jsp +++ b/src/main/webapp/vue/animal_cares_and_behaviors.jsp @@ -6,8 +6,10 @@ <%@ page isELIgnored="false" %> + + <%@ include file="base/language.jsp" %> @@ -46,7 +48,7 @@ -
-
+
+
- <%@ include file="base/footer.jsp" %> @@ -134,6 +148,60 @@ + + + + + +