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

UserFavouriteDeleter fully logged

parent 49853a10
Branches
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;
import com.example.clientproject.service.LoggingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
@Service
public class UserFavouriteDeleter {
@Autowired
JdbcTemplate jdbc;
LoggingService loggingService;
public UserFavouriteDeleter(JdbcTemplate jdbc, LoggingService loggingService) {
this.jdbc = jdbc;
this.loggingService = loggingService;
}
/**
* Takes a userfavourite DTO and removes it from the database.
* @param usfDTO
* @param usfDTO - usfDTO
* @param session - session
*/
public void delete(UserFavouriteDTO usfDTO){
public void delete(UserFavouriteDTO usfDTO, HttpSession session){
String query = "DELETE FROM User_Shop_Links WHERE (Shop_Id = " +
String query = "DELETE FROM mydb.User_Shop_Links WHERE (Shop_Id = " +
usfDTO.getShopId() +" AND User_Id = " +
usfDTO.getUserId() +")";
//System.out.println(query);
jdbc.execute(query);
// Log the change
loggingService.logEvent(
"UserShopLink Deleted",
session,
"UserShopLink deleted with Shop Id: " + usfDTO.getShopId() +
" and User Id: " + usfDTO.getUserId() +
" in UserFavouriteDeleter.delete()"
);
}
}
......@@ -25,11 +25,6 @@ public class BusinessFavouriter {
}
/**
*
* @param submitted form, contains a UserID and ShopID
* @return ERROR or OK depending on whether it any errors are thrown.
*/
@PostMapping("/favouriteBusiness")
public String favouriteBusiness(UserFavouriteForm uff, HttpSession session){
UserFavouriteDTO ufDTO;
......@@ -40,7 +35,7 @@ public class BusinessFavouriter {
}
try{
if(toggleFavourite.alreadyInDb(ufDTO)){
deleteFavourite.delete(ufDTO);
deleteFavourite.delete(ufDTO, session);
}else{
saveFavourite.save(ufDTO);
}
......
......@@ -351,4 +351,5 @@ 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
INSERT INTO Events (Event_Name) VALUES ('Shop Updated');
INSERT INTO Events (Event_Name) VALUES ('UserShopLink Deleted');
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment