package org.endeavourhealth.messagingapi.endpoints;

import org.endeavourhealth.common.security.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.*;
import java.util.UUID;

@Path("/")
public class Audit {

	@POST
	@Consumes(MediaType.TEXT_PLAIN)
	@Produces(MediaType.TEXT_PLAIN)
	@Path("/Audit")
	public Response postMessage(@Context SecurityContext sc, @Context HttpHeaders headers, String body) {
		String application = headers.getHeaderString("application");
		String level = headers.getHeaderString("level");
		Logger logger = LoggerFactory.getLogger(application);
		UUID userUuid = SecurityUtils.getCurrentUserId(sc);

		switch (level.toUpperCase()) {
			case "DEBUG":
				logger.debug(body);
				break;
			case "ERROR":
				logger.error(body);
				break;
			case "INFO":
				logger.info(body);
				break;
			case "TRACE":
				logger.trace(body);
				break;
			case "WARN":
				logger.warn(body);
				break;
			default:
				logger.debug(body);
		}

		return Response.ok().build();
	}
}

@@ -839,24 +839,34 @@
 r.debug(body
+, userUuid
 );%0A%09%09%09%09break
@@ -901,24 +901,34 @@
 r.error(body
+, userUuid
 );%0A%09%09%09%09break
@@ -961,24 +961,34 @@
 er.info(body
+, userUuid
 );%0A%09%09%09%09break
@@ -1023,24 +1023,34 @@
 r.trace(body
+, userUuid
 );%0A%09%09%09%09break
@@ -1083,24 +1083,34 @@
 er.warn(body
+, userUuid
 );%0A%09%09%09%09break
@@ -1144,16 +1144,26 @@
 bug(body
+, userUuid
 );%0A%09%09%7D%0A%0A

Include calling (keycloak) user uuid