Added house host to api
Signed-off-by: James Munson <jmunson@openpoll.io>
This commit is contained in:
@@ -26,6 +26,7 @@ package net.runelite.http.service.chat;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import com.google.common.base.Strings;
|
||||
import net.runelite.http.api.chat.House;
|
||||
import net.runelite.http.service.util.exception.NotFoundException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -65,4 +66,43 @@ public class ChatController
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
@PostMapping("/hosts")
|
||||
public void submitHost(@RequestParam int world, @RequestParam String location, @RequestParam String owner,
|
||||
@RequestParam boolean guildedAltar, @RequestParam boolean occultAltar,
|
||||
@RequestParam boolean spiritTree, @RequestParam boolean fairyRing,
|
||||
@RequestParam boolean wildernessObelisk, @RequestParam boolean repairStand,
|
||||
@RequestParam boolean combatDummy,
|
||||
@RequestParam(required = false, defaultValue = "false") boolean remove)
|
||||
{
|
||||
if (!location.equals("Rimmington") && !location.equals("Yanille"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
House house = new House();
|
||||
house.setOwner(owner);
|
||||
house.setGuildedAltarPresent(guildedAltar);
|
||||
house.setOccultAltarPresent(occultAltar);
|
||||
house.setSpiritTreePresent(spiritTree);
|
||||
house.setFairyRingPresent(fairyRing);
|
||||
house.setWildernessObeliskPresent(wildernessObelisk);
|
||||
house.setRepairStandPresent(repairStand);
|
||||
house.setCombatDummyPresent(combatDummy);
|
||||
|
||||
if (remove)
|
||||
{
|
||||
chatService.removeHost(world, location, house);
|
||||
}
|
||||
else
|
||||
{
|
||||
chatService.addHost(world, location, house);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/hosts")
|
||||
public House[] getHosts(@RequestParam int world, @RequestParam String location)
|
||||
{
|
||||
return chatService.getHosts(world, location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,10 @@
|
||||
package net.runelite.http.service.chat;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import net.runelite.http.api.chat.ChatClient;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.http.api.chat.House;
|
||||
import net.runelite.http.service.util.redis.RedisPool;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -68,4 +71,50 @@ public class ChatService
|
||||
jedis.setex("layout." + name, (int) EXPIRE.getSeconds(), layout);
|
||||
}
|
||||
}
|
||||
|
||||
public void addHost(int world, String location, House house)
|
||||
{
|
||||
String houseJSON = house.toString();
|
||||
|
||||
String key = "hosts.w" + Integer.toString(world) + "." + location;
|
||||
|
||||
try (Jedis jedis = jedisPool.getResource())
|
||||
{
|
||||
jedis.rpush(key, houseJSON);
|
||||
}
|
||||
}
|
||||
|
||||
public House[] getHosts(int world, String location)
|
||||
{
|
||||
List<String> json;
|
||||
String key = "hosts.w" + Integer.toString(world) + "." + location;
|
||||
|
||||
try (Jedis jedis = jedisPool.getResource())
|
||||
{
|
||||
json = jedis.lrange(key, 0, 25);
|
||||
}
|
||||
|
||||
if (json.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
House[] hosts = new House[json.size()];
|
||||
for (int i = 0; i < json.size(); i++)
|
||||
{
|
||||
hosts[i] = RuneLiteAPI.GSON.fromJson(json.get(i), House.class);
|
||||
}
|
||||
return hosts;
|
||||
}
|
||||
|
||||
public void removeHost(int world, String location, House house)
|
||||
{
|
||||
String json = house.toString();
|
||||
String key = "hosts.w" + Integer.toString(world) + "." + location;
|
||||
|
||||
try (Jedis jedis = jedisPool.getResource())
|
||||
{
|
||||
jedis.lrem(key, 0, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user