initial project setup
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.labfusion.controller;
|
||||
|
||||
import com.labfusion.model.DeviceState;
|
||||
import com.labfusion.model.Event;
|
||||
import com.labfusion.repository.DeviceStateRepository;
|
||||
import com.labfusion.repository.EventRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/system")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class SystemController {
|
||||
|
||||
@Autowired
|
||||
private EventRepository eventRepository;
|
||||
|
||||
@Autowired
|
||||
private DeviceStateRepository deviceStateRepository;
|
||||
|
||||
@GetMapping("/events")
|
||||
public ResponseEntity<List<Event>> getEvents(
|
||||
@RequestParam(required = false) String service,
|
||||
@RequestParam(required = false) String eventType,
|
||||
@RequestParam(required = false) Integer hours) {
|
||||
|
||||
List<Event> events;
|
||||
|
||||
if (service != null && hours != null) {
|
||||
LocalDateTime since = LocalDateTime.now().minusHours(hours);
|
||||
events = eventRepository.findRecentEventsByService(service, since);
|
||||
} else if (service != null) {
|
||||
events = eventRepository.findByService(service);
|
||||
} else if (eventType != null) {
|
||||
events = eventRepository.findByEventType(eventType);
|
||||
} else {
|
||||
events = eventRepository.findAll();
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(events);
|
||||
}
|
||||
|
||||
@GetMapping("/device-states")
|
||||
public ResponseEntity<List<DeviceState>> getDeviceStates(
|
||||
@RequestParam(required = false) String entityId,
|
||||
@RequestParam(required = false) String service) {
|
||||
|
||||
List<DeviceState> states;
|
||||
|
||||
if (entityId != null) {
|
||||
states = deviceStateRepository.findByEntityId(entityId);
|
||||
} else if (service != null) {
|
||||
states = deviceStateRepository.findByService(service);
|
||||
} else {
|
||||
states = deviceStateRepository.findAll();
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(states);
|
||||
}
|
||||
|
||||
@GetMapping("/metrics")
|
||||
public ResponseEntity<Object> getSystemMetrics() {
|
||||
// This would integrate with actual system monitoring
|
||||
// For now, return a placeholder response
|
||||
return ResponseEntity.ok().body("System metrics endpoint - to be implemented");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user