Skip to content
Snippets Groups Projects
Commit baa36d72 authored by Rafi's avatar Rafi
Browse files

Refactored updates so when changes are made to the database, a message will be...

Refactored updates so when changes are made to the database, a message will be broadcast to update there local copy with the specific change rather than send the entire list of staff or schedule.
parent a70341f3
No related branches found
No related tags found
1 merge request!6Changed update implementation for employees so rather than sending the whole...
...@@ -62,27 +62,30 @@ public class UserThread extends Thread { ...@@ -62,27 +62,30 @@ public class UserThread extends Thread {
break; break;
case "editShift": case "editShift":
try { try {
rafisWeirdClass.schedule.editShift(Integer.parseInt(args[1]), args[2], args[3], args[4]); String editedShift = rafisWeirdClass.schedule.editShift(Integer.parseInt(args[1]), args[2], args[3], args[4]);
serverMessage = rafisWeirdClass.schedule.allShifts(); if (!editedShift.isEmpty()) {
server.broadcast(serverMessage); server.broadcast("editShift/" + editedShift);
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
System.out.println("Client Message Error: " + clientMessage); System.out.println("Client Message Error: " + clientMessage);
} }
break; break;
case "addShift": case "addShift":
try { try {
rafisWeirdClass.schedule.addShift(Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]), Integer.parseInt(args[4])); String newShift = rafisWeirdClass.schedule.addShift(Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]), Integer.parseInt(args[4]));
serverMessage = rafisWeirdClass.schedule.allShifts(); if (!newShift.isEmpty()){
server.broadcast(serverMessage); server.broadcast("addShift/" + newShift);
}
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
System.out.println("Error: Formatting exception while adding shift"); System.out.println("Error: Formatting exception while adding shift");
} }
break; break;
case "removeShift": case "removeShift":
try { try {
rafisWeirdClass.schedule.removeShiftByID(args[1]); int shiftID = Integer.parseInt(args[1]);
serverMessage = rafisWeirdClass.schedule.allShifts(); if (shiftID == rafisWeirdClass.schedule.removeShiftByID(shiftID)) {
server.broadcast(serverMessage); server.broadcast("removeShift/" + shiftID);
}
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
System.out.println("Error: Formatting exception while removing shift"); System.out.println("Error: Formatting exception while removing shift");
} }
......
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