feat(servers): expor contagem por tipo
- adiciona endpoint GET /api/servers/type na controller - implementa serviço para agregar totais por ServersType - inclui método countAllByType no repositóriomaster
parent
d48a2633d0
commit
75add469f7
|
|
@ -11,6 +11,7 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/servers")
|
@RequestMapping("/api/servers")
|
||||||
|
|
@ -39,6 +40,11 @@ public class ServersController {
|
||||||
return ResponseEntity.ok().body(serversService.getByType(type));
|
return ResponseEntity.ok().body(serversService.getByType(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/type")
|
||||||
|
public ResponseEntity<Map<ServersType, Integer>> countAllByType() {
|
||||||
|
return ResponseEntity.ok().body(serversService.countAllByType());
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/application/{application}")
|
@GetMapping("/application/{application}")
|
||||||
public ResponseEntity<List<ServerDTO>> getByApplication(@PathVariable Applications application) {
|
public ResponseEntity<List<ServerDTO>> getByApplication(@PathVariable Applications application) {
|
||||||
return ResponseEntity.ok().body(serversService.getByApplication(application));
|
return ResponseEntity.ok().body(serversService.getByApplication(application));
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,6 @@ public interface ServersRepository extends JpaRepository<Servers, String> {
|
||||||
List<Servers> findByType(ServersType type);
|
List<Servers> findByType(ServersType type);
|
||||||
List<Servers> findByApplication(Applications application);
|
List<Servers> findByApplication(Applications application);
|
||||||
Optional<Servers> findByIpAndPort(String ip, Integer port);
|
Optional<Servers> findByIpAndPort(String ip, Integer port);
|
||||||
|
Integer countAllByType(ServersType type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ import com.hitcommunications.servermanager.repositories.ServersRepository;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
|
@ -48,6 +50,16 @@ public class ServersService {
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<ServersType, Integer> countAllByType() {
|
||||||
|
Map<ServersType, Integer> response = new HashMap<>();
|
||||||
|
|
||||||
|
for(ServersType type : ServersType.values()) {
|
||||||
|
response.put(type, repo.countAllByType(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ServerDTO> getByApplication(Applications application) {
|
public List<ServerDTO> getByApplication(Applications application) {
|
||||||
return repo.findByApplication(application)
|
return repo.findByApplication(application)
|
||||||
.stream()
|
.stream()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue