package org.cru.godtools.api.notifications;

import org.cru.godtools.api.authorization.AuthorizationResource;
import org.cru.godtools.domain.notifications.Device;
import org.cru.godtools.domain.notifications.DeviceService;
import org.jboss.logging.Logger;

import javax.inject.Inject;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import java.util.UUID;

/**
 * Created by matthewfrederick on 12/30/14.
 */
@Path("/notification")
public class NotificationResource
{
	@Inject
	DeviceService deviceService;

	Logger log = Logger.getLogger(AuthorizationResource.class);

	@POST
	@Path("/register")
	public Response registerDevice(String registrationId, @HeaderParam("deviceId") String deviceIdHeader,
								   @QueryParam("deviceId") String deviceIdParam)
	{
		String id = deviceIdHeader == null ? deviceIdParam : deviceIdHeader;

		log.info("Registering device: " + id + " with registrationId: " + registrationId);

		Device device = new Device();
		device.setId(UUID.randomUUID());
		device.setRegistrationId(registrationId);
		device.setDeviceId(id);

		deviceService.insert(device);

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

@@ -360,16 +360,46 @@
 s.Path;%0A
+import javax.ws.rs.PathParam;%0A
 import j
@@ -708,24 +708,32 @@
 @Path(%22/
+%7B
 regist
-e
 r
+ationId%7D
 %22)%0A%09publ
@@ -759,16 +759,44 @@
 rDevice(
+@PathParam(%22registrationId%22)
 String r
@@ -809,16 +809,27 @@
 ationId,
+%0A%09%09%09%09%09%09%09%09  
  @Header
@@ -868,27 +868,16 @@
 dHeader,
-%0A%09%09%09%09%09%09%09%09  
  @QueryP

update endoint (cherry picked from commit be10da9)