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

UserFavouriteTagSaver fully logged

parent ee11b626
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.stereotype.Service; import org.springframework.stereotype.Service;
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 javax.servlet.http.HttpSession;
@Service @Service
public class UserFavouriteTagSaver { public class UserFavouriteTagSaver {
@Autowired
JdbcTemplate jdbc; JdbcTemplate jdbc;
LoggingService loggingService;
public UserFavouriteTagSaver(JdbcTemplate jdbc, LoggingService loggingService) {
this.jdbc = jdbc;
this.loggingService = loggingService;
}
public void saveUserFavTag(int UserID, String TagID){ public void saveUserFavTag(int userID, String tagID, HttpSession session){
String disableFKeyChecks = "SET FOREIGN_KEY_CHECKS=0;"; String disableFKeyChecks = "SET FOREIGN_KEY_CHECKS=0;";
String enableFKeyChecks = "SET FOREIGN_KEY_CHECKS=1;"; String enableFKeyChecks = "SET FOREIGN_KEY_CHECKS=1;";
jdbc.execute(disableFKeyChecks); jdbc.execute(disableFKeyChecks);
String query = "INSERT INTO user_favourite_tags (User_Id, Tag_Id) VALUES ("+ UserID + ","+TagID + ")"; String query = "INSERT INTO mydb.user_favourite_tags (User_Id, Tag_Id) VALUES ("+ userID + ","+tagID + ")";
jdbc.execute(query); jdbc.execute(query);
jdbc.execute(enableFKeyChecks); jdbc.execute(enableFKeyChecks);
// Log the changes
loggingService.logEvent(
"UserFavouriteTag Inserted",
session,
"UserFavouriteTag Inserted with User Id: " + userID +
"and Tag Id: " + tagID +
" in UserFavouriteTagSaver.saveUserFavTag()"
);
} }
} }
...@@ -38,7 +38,7 @@ public class SaveUserFavouriteTagController { ...@@ -38,7 +38,7 @@ public class SaveUserFavouriteTagController {
//System.out.println(TagID_List.size()); //System.out.println(TagID_List.size());
//System.out.println(TagID); //System.out.println(TagID);
int UserID = jwtUtils.getLoggedInUserId(session).get(); int UserID = jwtUtils.getLoggedInUserId(session).get();
FavTagService.saveUserFavTag(UserID,TagID); FavTagService.saveUserFavTag(UserID,TagID, session);
} }
return("redirect:/"); return("redirect:/");
} }
......
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