Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.nighthawk.spring_portfolio.mvc.classPeriod;

public class ActionData {
private String type; // Type of action (e.g., ADD_STUDENT, ADD_INSTRUCTOR)
private String id; // ID of the action (e.g., student ID, instructor ID)
private String name; // Name associated with the action (e.g., student name, instructor name)
private String email; // Email associated with the action (e.g., student email, instructor email)

// Constructors, getters, and setters
public ActionData() {
// Default constructor
}

public ActionData(String type, String id, String name, String email) {
this.type = type;
this.id = id;
this.name = name;
this.email = email;
}

// Getters and setters for each field
public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

// toString method for debugging or logging
@Override
public String toString() {
return "ActionData{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", name='" + name + '\'' +
", email='" + email + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.nighthawk.spring_portfolio.mvc.classPeriod;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Stack;
import java.util.LinkedList;
import java.util.Queue;

@RestController
public class UndoRedo {
private Stack<ActionData> undoStack;
private Stack<ActionData> redoStack;
private Queue<ActionData> actionsQueue;

public UndoRedo() {
undoStack = new Stack<>();
redoStack = new Stack<>();
actionsQueue = new LinkedList<>();
}

@PostMapping("/addAction")
public String addAction(@RequestBody ActionData actionData) {
undoStack.push(actionData);
redoStack.clear(); // Clear redo stack on new action
actionsQueue.add(actionData);
return "Action added: " + actionData.getType(); // Example: Assuming ActionData has a getType() method
}

@GetMapping("/undo")
public String undo() {
if (!undoStack.isEmpty()) {
ActionData actionData = undoStack.pop();
redoStack.push(actionData);
return "Undo action: " + actionData.getType();
}
return "No actions to undo";
}

@GetMapping("/redo")
public String redo() {
if (!redoStack.isEmpty()) {
ActionData actionData = redoStack.pop();
undoStack.push(actionData);
return "Redo action: " + actionData.getType();
}
return "No actions to redo";
}

@GetMapping("/getActionsQueue")
public Queue<ActionData> getActionsQueue() {
return actionsQueue;
}
}