loot tracker service: expose method to delete loot records
This commit is contained in:
@@ -31,9 +31,11 @@ import java.util.Collection;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import net.runelite.http.api.loottracker.LootRecord;
|
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.AuthFilter;
|
||||||
import net.runelite.http.service.account.beans.SessionEntry;
|
import net.runelite.http.service.account.beans.SessionEntry;
|
||||||
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.RequestBody;
|
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.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
@@ -76,4 +78,18 @@ public class LootTrackerController
|
|||||||
|
|
||||||
return service.get(e.getUser(), count);
|
return service.get(e.getUser(), count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping
|
||||||
|
public void deleteLoot(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
@RequestParam(required = false) LootRecordType type, @RequestParam(required = false) String eventId) throws IOException
|
||||||
|
{
|
||||||
|
SessionEntry e = auth.handle(request, response);
|
||||||
|
if (e == null)
|
||||||
|
{
|
||||||
|
response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
service.delete(e.getUser(), type, eventId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,7 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.http.api.loottracker.GameItem;
|
import net.runelite.http.api.loottracker.GameItem;
|
||||||
import net.runelite.http.api.loottracker.LootRecord;
|
import net.runelite.http.api.loottracker.LootRecord;
|
||||||
|
import net.runelite.http.api.loottracker.LootRecordType;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
@@ -68,6 +69,9 @@ public class LootTrackerService
|
|||||||
|
|
||||||
private static final String SELECT_LOOT_QUERY = "SELECT killId,time,type,eventId,itemId,itemQuantity FROM kills JOIN drops ON drops.killId = kills.id WHERE accountId = :accountId ORDER BY TIME DESC LIMIT :limit";
|
private static final String SELECT_LOOT_QUERY = "SELECT killId,time,type,eventId,itemId,itemQuantity FROM kills JOIN drops ON drops.killId = kills.id WHERE accountId = :accountId ORDER BY TIME DESC LIMIT :limit";
|
||||||
|
|
||||||
|
private static final String DELETE_LOOT_ACCOUNT = "DELETE FROM kills WHERE accountId = :accountId";
|
||||||
|
private static final String DELETE_LOOT_ACCOUNT_TYPE = "DELETE FROM kills WHERE accountId = :accountId AND type = :type AND eventId = :eventId";
|
||||||
|
|
||||||
private final Sql2o sql2o;
|
private final Sql2o sql2o;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -160,6 +164,27 @@ public class LootTrackerService
|
|||||||
return lootRecords;
|
return lootRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete(int accountId, LootRecordType type, String eventId)
|
||||||
|
{
|
||||||
|
try (Connection con = sql2o.open())
|
||||||
|
{
|
||||||
|
if (eventId == null && type == null)
|
||||||
|
{
|
||||||
|
con.createQuery(DELETE_LOOT_ACCOUNT)
|
||||||
|
.addParameter("accountId", accountId)
|
||||||
|
.executeUpdate();
|
||||||
|
}
|
||||||
|
else if (eventId != null && type != null)
|
||||||
|
{
|
||||||
|
con.createQuery(DELETE_LOOT_ACCOUNT_TYPE)
|
||||||
|
.addParameter("accountId", accountId)
|
||||||
|
.addParameter("type", type)
|
||||||
|
.addParameter("eventId", eventId)
|
||||||
|
.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 15 * 60 * 1000)
|
@Scheduled(fixedDelay = 15 * 60 * 1000)
|
||||||
public void expire()
|
public void expire()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user