Skip to content
Merged
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,29 @@
package org.example.projektarendehantering.application.service;

import lombok.RequiredArgsConstructor;
import org.example.projektarendehantering.infrastructure.persistence.CaseRepository;
import org.example.projektarendehantering.infrastructure.persistence.EmployeeRepository;
import org.example.projektarendehantering.infrastructure.persistence.PatientRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class PublicStatsService {

private final CaseRepository caseRepository;
private final PatientRepository patientRepository;
private final EmployeeRepository employeeRepository;

@Transactional(readOnly = true)
public Map<String, Long> getPublicStats() {
Map<String, Long> stats = new HashMap<>();
stats.put("totalCases", caseRepository.count());
stats.put("totalPatients", patientRepository.count());
stats.put("totalEmployees", employeeRepository.count());
return stats;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.example.projektarendehantering.application.service.CaseService;
import org.example.projektarendehantering.application.service.EmployeeService;
import org.example.projektarendehantering.application.service.PatientService;
import org.example.projektarendehantering.application.service.PublicStatsService;
import org.example.projektarendehantering.infrastructure.security.SecurityActorAdapter;
import org.example.projektarendehantering.presentation.dto.CaseAssignmentDTO;
import org.example.projektarendehantering.presentation.dto.CaseDTO;
Expand Down Expand Up @@ -31,12 +32,14 @@ public class UiController {
private final CaseService caseService;
private final PatientService patientService;
private final EmployeeService employeeService;
private final PublicStatsService publicStatsService;
private final SecurityActorAdapter securityActorAdapter;

public UiController(CaseService caseService, PatientService patientService, EmployeeService employeeService, SecurityActorAdapter securityActorAdapter) {
public UiController(CaseService caseService, PatientService patientService, EmployeeService employeeService, PublicStatsService publicStatsService, SecurityActorAdapter securityActorAdapter) {
this.caseService = caseService;
this.patientService = patientService;
this.employeeService = employeeService;
this.publicStatsService = publicStatsService;
this.securityActorAdapter = securityActorAdapter;
}

Expand All @@ -47,7 +50,8 @@ public String addNote(@PathVariable UUID caseId, @RequestParam("content") String
}

@GetMapping("/")
public String landing() {
public String landing(Model model) {
model.addAttribute("stats", publicStatsService.getPublicStats());
return "landing";
}

Expand Down
Loading