Skip to content
Snippets Groups Projects
Commit aa97c86c authored by Joshua Gill's avatar Joshua Gill
Browse files

ShopDeleter fully logged, other classes changed to no longer use autowiring for attributes

parent f968fd4b
No related branches found
No related tags found
2 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!107Issue complete
package com.example.clientproject.services; package com.example.clientproject.services;
import com.example.clientproject.service.LoggingService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
@Service @Service
public class ShopDeleter { public class ShopDeleter {
@Autowired
JdbcTemplate jdbc; JdbcTemplate jdbc;
LoggingService loggingService;
/** /**
* @param shopId - the shopID of the shop that the stored procedure is going to delete * @param shopId - the shopID of the shop that the stored procedure is going to delete
*/ */
public void deleteShop(Integer shopId){ public void deleteShop(Integer shopId, HttpSession session){
String query = "CALL `mydb`.`deleteShop`('" + shopId + "');"; String query = "CALL `mydb`.`deleteShop`('" + shopId + "');";
jdbc.execute(query); jdbc.execute(query);
// Log the change
loggingService.logEvent(
"Deleted Shop",
session,
"Shop deleted with Shop Id: " + shopId +
" in ShopDeleter.deleteShop()"
);
} }
} }
...@@ -195,7 +195,7 @@ public class AdminController { ...@@ -195,7 +195,7 @@ public class AdminController {
} }
if (shopPermissionLevel == 2 || shopPermissionLevel == 3) { if (shopPermissionLevel == 2 || shopPermissionLevel == 3) {
System.out.println("shop is being deleted"); System.out.println("shop is being deleted");
shopDeleter.deleteShop(shopId); shopDeleter.deleteShop(shopId, session);
} }
return "redirect:/settings"; return "redirect:/settings";
} }
......
...@@ -31,7 +31,7 @@ public class DeleteShopTests { ...@@ -31,7 +31,7 @@ public class DeleteShopTests {
//in future make a jdbc service that will do the exact same thing as the stored procedure //in future make a jdbc service that will do the exact same thing as the stored procedure
@Test @Test
public void shouldDeleteAllShopData() throws Exception{ public void shouldDeleteAllShopData() throws Exception{
shopDeleter.deleteShop(12); shopDeleter.deleteShop(12, null);
List<Shops> shopsList = shopsRepo.findAll(); List<Shops> shopsList = shopsRepo.findAll();
assertEquals(11, shopsList.size()); assertEquals(11, shopsList.size());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment