Skip to content

Commit

Permalink
loot controller: publish loot to redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Jan 19, 2020
1 parent 97b4f0d commit 2310349
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,14 +45,20 @@
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;

Expand All @@ -65,6 +74,11 @@ public void storeLootRecord(HttpServletRequest request, HttpServletResponse resp

service.store(records, e.getUser());
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);

try (Jedis jedis = redisPool.getResource())
{
jedis.publish("drops", GSON.toJson(records));
}
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand All @@ -53,6 +54,7 @@
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)
Expand All @@ -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
Expand Down

0 comments on commit 2310349

Please sign in to comment.