From 49853a102b74333594a0940067cfcbf4820d20f3 Mon Sep 17 00:00:00 2001 From: c2038058 <gillj8@cardiff.ac.uk> Date: Fri, 10 Dec 2021 12:31:24 +0000 Subject: [PATCH] UpdateKeyInfo fully logged --- .../clientproject/services/UpdateKeyInfo.java | 19 +++++++++++++++++-- .../restControllers/UpdateKeyInformation.java | 2 +- src/main/resources/database/schema.sql | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/clientproject/services/UpdateKeyInfo.java b/src/main/java/com/example/clientproject/services/UpdateKeyInfo.java index 6903dc9..fe28be7 100644 --- a/src/main/java/com/example/clientproject/services/UpdateKeyInfo.java +++ b/src/main/java/com/example/clientproject/services/UpdateKeyInfo.java @@ -2,16 +2,24 @@ package com.example.clientproject.services; import com.example.clientproject.data.shops.Shops; import com.example.clientproject.data.shops.ShopsRepo; +import com.example.clientproject.service.LoggingService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpSession; + @Service public class UpdateKeyInfo { - @Autowired ShopsRepo shopsRepo; + LoggingService loggingService; + + public UpdateKeyInfo(ShopsRepo shopsRepo, LoggingService loggingService) { + this.shopsRepo = shopsRepo; + this.loggingService = loggingService; + } - public void updateInfo(KeyInfoDTO kiDTO){ + public void updateInfo(KeyInfoDTO kiDTO, HttpSession session){ Shops shop = shopsRepo.getById((long) kiDTO.getShopId()); shop.setShopName(kiDTO.getShopName()); @@ -25,6 +33,13 @@ public class UpdateKeyInfo { } shopsRepo.save(shop); + // Log the change + loggingService.logEvent( + "Shop Updated", + session, + "Shop updated with Shop Id: " + kiDTO.getShopId() + + " in UpdateKeyInfo.updateInfo()" + ); } } diff --git a/src/main/java/com/example/clientproject/web/restControllers/UpdateKeyInformation.java b/src/main/java/com/example/clientproject/web/restControllers/UpdateKeyInformation.java index e975033..b8d4401 100644 --- a/src/main/java/com/example/clientproject/web/restControllers/UpdateKeyInformation.java +++ b/src/main/java/com/example/clientproject/web/restControllers/UpdateKeyInformation.java @@ -28,7 +28,7 @@ public class UpdateKeyInformation { return "BAD SESSION"; } try{ - updateInfo.updateInfo(new KeyInfoDTO(keyInformationForm)); + updateInfo.updateInfo(new KeyInfoDTO(keyInformationForm), session); return "OK"; }catch (Exception e){ e.printStackTrace(); diff --git a/src/main/resources/database/schema.sql b/src/main/resources/database/schema.sql index e04c378..6cdf1a5 100644 --- a/src/main/resources/database/schema.sql +++ b/src/main/resources/database/schema.sql @@ -351,3 +351,4 @@ INSERT INTO Events (Event_Name) VALUES ('New Social'); INSERT INTO Events (Event_Name) VALUES ('New User Permission'); INSERT INTO Events (Event_Name) VALUES ('Stamp Board Updated'); INSERT INTO Events (Event_Name) VALUES ('Reward Deleted'); +INSERT INTO Events (Event_Name) VALUES ('Shop Updated'); \ No newline at end of file -- GitLab