package ee.esutoniagodesu.web.rest;
import ee.esutoniagodesu.security.AuthoritiesConstants;
import ee.esutoniagodesu.service.AuditEventService;
import org.springframework.boot.actuate.audit.AuditEvent;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import java.time.LocalDateTime;
import java.util.List;
/**
* REST controller for getting the audit events.
*/
@RestController
@RequestMapping("/api/audits")
public class AuditResource {
@Inject
private AuditEventService auditEventService;
@RequestMapping(value = "/all",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@RolesAllowed(AuthoritiesConstants.ADMIN)
public List<AuditEvent> findAll() {
return auditEventService.findAll();
}
@RequestMapping(value = "/byDates",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@RolesAllowed(AuthoritiesConstants.ADMIN)
public List<AuditEvent> byDates(@RequestParam LocalDateTime from,
@RequestParam LocalDateTime to) {
return auditEventService.findByDates(from, to);
}
}