ge controller: publish trade data to redis
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.service.ge;
|
package net.runelite.http.service.ge;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -33,6 +34,7 @@ import net.runelite.http.api.RuneLiteAPI;
|
|||||||
import net.runelite.http.api.ge.GrandExchangeTrade;
|
import net.runelite.http.api.ge.GrandExchangeTrade;
|
||||||
import net.runelite.http.service.account.AuthFilter;
|
import net.runelite.http.service.account.AuthFilter;
|
||||||
import net.runelite.http.service.account.beans.SessionEntry;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -41,19 +43,24 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/ge")
|
@RequestMapping("/ge")
|
||||||
public class GrandExchangeController
|
public class GrandExchangeController
|
||||||
{
|
{
|
||||||
|
private static final Gson GSON = RuneLiteAPI.GSON;
|
||||||
|
|
||||||
private final GrandExchangeService grandExchangeService;
|
private final GrandExchangeService grandExchangeService;
|
||||||
private final AuthFilter authFilter;
|
private final AuthFilter authFilter;
|
||||||
|
private final RedisPool redisPool;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public GrandExchangeController(GrandExchangeService grandExchangeService, AuthFilter authFilter)
|
public GrandExchangeController(GrandExchangeService grandExchangeService, AuthFilter authFilter, RedisPool redisPool)
|
||||||
{
|
{
|
||||||
this.grandExchangeService = grandExchangeService;
|
this.grandExchangeService = grandExchangeService;
|
||||||
this.authFilter = authFilter;
|
this.authFilter = authFilter;
|
||||||
|
this.redisPool = redisPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@@ -76,6 +83,23 @@ public class GrandExchangeController
|
|||||||
{
|
{
|
||||||
grandExchangeService.add(userId, grandExchangeTrade);
|
grandExchangeService.add(userId, grandExchangeTrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Trade trade = new Trade();
|
||||||
|
trade.setBuy(grandExchangeTrade.isBuy());
|
||||||
|
trade.setCancel(grandExchangeTrade.isCancel());
|
||||||
|
trade.setItemId(grandExchangeTrade.getItemId());
|
||||||
|
trade.setQuantity(grandExchangeTrade.getQuantity());
|
||||||
|
trade.setPrice(grandExchangeTrade.getPrice());
|
||||||
|
trade.setOffer(grandExchangeTrade.getOffer());
|
||||||
|
trade.setTime((int) (System.currentTimeMillis() / 1000L));
|
||||||
|
trade.setMachineId(request.getHeader(RuneLiteAPI.RUNELITE_MACHINEID));
|
||||||
|
trade.setUserId(userId);
|
||||||
|
trade.setIp(request.getHeader("X-Forwarded-For"));
|
||||||
|
String json = GSON.toJson(trade);
|
||||||
|
try (Jedis jedis = redisPool.getResource())
|
||||||
|
{
|
||||||
|
jedis.publish("ge", json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Adam <Adam@sigterm.info>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.http.service.ge;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
class Trade
|
||||||
|
{
|
||||||
|
private boolean buy;
|
||||||
|
private boolean cancel;
|
||||||
|
private int itemId;
|
||||||
|
private int quantity;
|
||||||
|
private int price;
|
||||||
|
private int offer;
|
||||||
|
private int time;
|
||||||
|
private String machineId;
|
||||||
|
private Integer userId;
|
||||||
|
private String ip;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user