finance-analyzer/src/main/java/de/arminwolf/financeanalyzer/controller/UploadController.java

39 lines
1.4 KiB
Java

package de.arminwolf.financeanalyzer.controller;
import de.arminwolf.financeanalyzer.conf.Configuration;
import de.arminwolf.financeanalyzer.service.CacheService;
import de.arminwolf.financeanalyzer.service.FileService;
import de.arminwolf.financeanalyzer.service.ReportService;
import de.arminwolf.financeanalyzer.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;
@Controller
@RequestMapping("/upload")
public class UploadController {
@Autowired
FileService fileService;
@Autowired
CacheService cacheService;
@GetMapping("/")
public String upload(Model model) {
final RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
fileService.getJsonFileName().ifPresent(jsonFileName -> {
cacheService.put("currentJsonFile", jsonFileName);
cacheService.put("configuration", fileService.getConfiguration());
model.addAttribute("foundJsonFile", jsonFileName);
model.addAttribute("accounts", ((Configuration) cacheService.get("configuration")).getBankAccounts());
});
return Constants.INDEX;
}
}