loot controller: publish loot to redis
This commit is contained in:
@@ -26,14 +26,17 @@
|
||||
package net.runelite.http.service.loottracker;
|
||||
|
||||
import com.google.api.client.http.HttpStatusCodes;
|
||||
import com.google.gson.Gson;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.http.api.loottracker.LootAggregate;
|
||||
import net.runelite.http.api.loottracker.LootRecord;
|
||||
import net.runelite.http.service.account.AuthFilter;
|
||||
import net.runelite.http.service.account.beans.SessionEntry;
|
||||
import net.runelite.http.service.util.redis.RedisPool;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -42,14 +45,20 @@ 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 redis.clients.jedis.Jedis;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/loottracker")
|
||||
public class LootTrackerController
|
||||
{
|
||||
private static final Gson GSON = RuneLiteAPI.GSON;
|
||||
|
||||
@Autowired
|
||||
private LootTrackerService service;
|
||||
|
||||
@Autowired
|
||||
private RedisPool redisPool;
|
||||
|
||||
@Autowired
|
||||
private AuthFilter auth;
|
||||
|
||||
@@ -65,6 +74,11 @@ public class LootTrackerController
|
||||
|
||||
service.store(records, e.getUser());
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||
|
||||
try (Jedis jedis = redisPool.getResource())
|
||||
{
|
||||
jedis.publish("drops", GSON.toJson(records));
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
|
||||
@@ -35,6 +35,7 @@ import net.runelite.http.api.loottracker.LootRecord;
|
||||
import net.runelite.http.api.loottracker.LootRecordType;
|
||||
import net.runelite.http.service.account.AuthFilter;
|
||||
import net.runelite.http.service.account.beans.SessionEntry;
|
||||
import net.runelite.http.service.util.redis.RedisPool;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -53,6 +54,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(LootTrackerController.class)
|
||||
@@ -68,11 +70,16 @@ public class LootTrackerControllerTest
|
||||
@MockBean
|
||||
private AuthFilter authFilter;
|
||||
|
||||
@MockBean
|
||||
private RedisPool redisPool;
|
||||
|
||||
@Before
|
||||
public void before() throws IOException
|
||||
{
|
||||
when(authFilter.handle(any(HttpServletRequest.class), any(HttpServletResponse.class)))
|
||||
.thenReturn(mock(SessionEntry.class));
|
||||
|
||||
when(redisPool.getResource()).thenReturn(mock(Jedis.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user