diff --git a/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerController.java b/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerController.java index baa01065e3..945dffb68b 100644 --- a/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerController.java +++ b/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerController.java @@ -31,9 +31,11 @@ import java.util.Collection; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; 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 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.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -76,4 +78,18 @@ public class LootTrackerController 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); + } } \ No newline at end of file diff --git a/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerService.java b/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerService.java index e89b498ef5..c5f396add2 100644 --- a/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerService.java +++ b/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerService.java @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.List; import net.runelite.http.api.loottracker.GameItem; 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.Qualifier; 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 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; @Autowired @@ -160,6 +164,27 @@ public class LootTrackerService 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) public void expire() {