BudgetController.java:
package com.weathGuardian.controller;

import com.weathGuardian.models.Budget;
import com.weathGuardian.Service.BudgetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/budgets")
public class BudgetController {

    private final BudgetService budgetService;

    @Autowired
    public BudgetController(BudgetService budgetService) {
        this.budgetService = budgetService;
    }

    @PostMapping
    public ResponseEntity<Budget> createBudget(@RequestBody Budget budget) {
        budgetService.createBudget(budget);
        return new ResponseEntity<>(budget, HttpStatus.CREATED);
    }

    @GetMapping("/{id}")
    public ResponseEntity<Budget> getBudgetById(@PathVariable Long id) {
        Budget budget = budgetService.getBudgetById(id);
        if (budget != null) {
            return new ResponseEntity<>(budget, HttpStatus.OK);
        } else {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    }

    @GetMapping
    public ResponseEntity<List<Budget>> getAllBudgets() {
        List<Budget> budgets = budgetService.getAllBudgets();
        return new ResponseEntity<>(budgets, HttpStatus.OK);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteBudget(@PathVariable Long id) {
        budgetService.deleteBudget(id);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
}
TransactionController.java:
package com.weathGuardian.controller;

import com.weathGuardian.models.Transaction;
import com.weathGuardian.models.User;
import com.weathGuardian.Service.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/dashboard")
public class TransactionController {

    private final TransactionService transactionService;

    @Autowired
    public TransactionController(TransactionService transactionService) {
        this.transactionService = transactionService;
    }

    @GetMapping
    public String dashboard(Model model) {
        User currentUser = getCurrentUser();
        List<Transaction> transactions = transactionService.getAllTransactions();
        String budgetStatus = calculateBudgetStatus();
        String remainingBudget = calculateRemainingBudget();
        List<SavingsGoal> savingsGoals = getSavingsGoals();

        model.addAttribute("currentUser", currentUser);
        model.addAttribute("transactions", transactions);
        model.addAttribute("budgetStatus", budgetStatus);
        model.addAttribute("remainingBudget", remainingBudget);
        model.addAttribute("savingsGoals", savingsGoals);

        return "dashboard"; // Corresponds to dashboard.html in templates directory
    }

    @PostMapping("/update-savings-goal")
    public String updateSavingsGoal(@RequestParam("goalName") String goalName,
                                    @RequestParam("amount") double amount,
                                    Model model) {
        // Logic to update savings goal - you can integrate this with your existing service
        // For demonstration, let's assume updating a mock savings goal
        SavingsGoal updatedGoal = new SavingsGoal(goalName, amount);
        model.addAttribute("updatedGoal", updatedGoal);

        // Refresh dashboard with updated data
        return "redirect:/dashboard";
    }

    // Replace with actual logic to get current user
    private User getCurrentUser() {
        return new User(); // Example return
    }

    // Example methods to calculate budget status and remaining budget
    private String calculateBudgetStatus() {
        return "Good"; // Example return
    }

    private String calculateRemainingBudget() {
        return "$1000"; // Example return
    }

    // Example method to get savings goals
    private List<SavingsGoal> getSavingsGoals() {
        List<SavingsGoal> goals = new ArrayList<>();
        goals.add(new SavingsGoal("Goal 1", 500));
        goals.add(new SavingsGoal("Goal 2", 1000));
        return goals;
    }

    // Static inner class for mock savings goal
    private static class SavingsGoal {
        private String goalName;
        private double amount;

        public SavingsGoal(String goalName, double amount) {
            this.goalName = goalName;
            this.amount = amount;
        }

        public String getGoalName() {
            return goalName;
        }

        public void setGoalName(String goalName) {
            this.goalName = goalName;
        }

        public double getAmount() {
            return amount;
        }

        public void setAmount(double amount) {
            this.amount = amount;
        }
    }
}
UserController.java:
package com.weathGuardian.controller;

import com.weathGuardian.models.User;
import com.weathGuardian.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/users")
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping
    public ResponseEntity<User> createUser(@RequestBody User user) {
        try {
            User createdUser = userService.saveUser(user);
            return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
        } catch (Exception e) {
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @GetMapping("/{id}")
    public ResponseEntity<User> getUserById(@PathVariable Long id) {
        try {
            Optional<User> user = userService.getUserById(id);
            return user.map(ResponseEntity::ok)
                    .orElse(ResponseEntity.notFound().build());
        } catch (Exception e) {
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @GetMapping
    public ResponseEntity<List<User>> getAllUsers() {
        try {
            List<User> users = userService.getAllUsers();
            return new ResponseEntity<>(users, HttpStatus.OK);
        } catch (Exception e) {
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}