John-sCC / jcc_backend

Eat up!
1 stars 0 forks source link

Finally made backend for undo and redo! #47

Open DasMoge124 opened 5 months ago

DasMoge124 commented 5 months ago

Made the backend version of Undo/Redo 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 + '\'' +
            '}';
}

} 55 changes: 55 additions & 0 deletions55
src/main/java/com/nighthawk/spring_portfolio/mvc/classPeriod/UndoRedo.java Original file line number Original file line 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 undoStack; private Stack redoStack; private Queue 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;
}

}