http service: return item names in price lookup
This commit is contained in:
@@ -72,6 +72,7 @@ public class ItemController
|
|||||||
{
|
{
|
||||||
Item item = new Item();
|
Item item = new Item();
|
||||||
item.setId(priceEntry.getItem()); // fake item
|
item.setId(priceEntry.getItem()); // fake item
|
||||||
|
item.setName(priceEntry.getName());
|
||||||
|
|
||||||
ItemPrice itemPrice = new ItemPrice();
|
ItemPrice itemPrice = new ItemPrice();
|
||||||
itemPrice.setItem(item);
|
itemPrice.setItem(item);
|
||||||
@@ -211,6 +212,7 @@ public class ItemController
|
|||||||
{
|
{
|
||||||
Item item = new Item();
|
Item item = new Item();
|
||||||
item.setId(priceEntry.getItem()); // fake item
|
item.setId(priceEntry.getItem()); // fake item
|
||||||
|
item.setName(priceEntry.getName());
|
||||||
|
|
||||||
ItemPrice itemPrice = new ItemPrice();
|
ItemPrice itemPrice = new ItemPrice();
|
||||||
itemPrice.setItem(item);
|
itemPrice.setItem(item);
|
||||||
|
|||||||
@@ -124,14 +124,14 @@ public class ItemService
|
|||||||
{
|
{
|
||||||
if (time != null)
|
if (time != null)
|
||||||
{
|
{
|
||||||
return con.createQuery("select item, price, time, fetched_time from prices where item = :item and time <= :time order by time desc limit 1")
|
return con.createQuery("select item, name, price, time, fetched_time from prices t1 join items t2 on t1.item=t2.id where item = :item and time <= :time order by time desc limit 1")
|
||||||
.addParameter("item", itemId)
|
.addParameter("item", itemId)
|
||||||
.addParameter("time", time.toString())
|
.addParameter("time", time.toString())
|
||||||
.executeAndFetchFirst(PriceEntry.class);
|
.executeAndFetchFirst(PriceEntry.class);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return con.createQuery("select item, price, time, fetched_time from prices where item = :item order by time desc limit 1")
|
return con.createQuery("select item, name, price, time, fetched_time from prices t1 join items t2 on t1.item=t2.id where item = :item order by time desc limit 1")
|
||||||
.addParameter("item", itemId)
|
.addParameter("item", itemId)
|
||||||
.executeAndFetchFirst(PriceEntry.class);
|
.executeAndFetchFirst(PriceEntry.class);
|
||||||
}
|
}
|
||||||
@@ -295,9 +295,10 @@ public class ItemService
|
|||||||
{
|
{
|
||||||
try (Connection con = sql2o.beginTransaction())
|
try (Connection con = sql2o.beginTransaction())
|
||||||
{
|
{
|
||||||
Query query = con.createQuery("select t2.item, t2.time, prices.price, prices.fetched_time from (select t1.item as item, max(t1.time) as time from prices t1 group by item) t2 join prices on t2.item=prices.item and t2.time=prices.time");
|
Query query = con.createQuery("select t2.item, t3.name, t2.time, prices.price, prices.fetched_time from (select t1.item as item, max(t1.time) as time from prices t1 group by item) t2 " +
|
||||||
List<PriceEntry> entries = query.executeAndFetch(PriceEntry.class);
|
" join prices on t2.item=prices.item and t2.time=prices.time" +
|
||||||
return entries;
|
" join items t3 on t2.item=t3.id");
|
||||||
|
return query.executeAndFetch(PriceEntry.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,10 @@ import java.time.Instant;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class PriceEntry
|
class PriceEntry
|
||||||
{
|
{
|
||||||
private int item;
|
private int item;
|
||||||
|
private String name;
|
||||||
private int price;
|
private int price;
|
||||||
private Instant time;
|
private Instant time;
|
||||||
private Instant fetched_time;
|
private Instant fetched_time;
|
||||||
|
|||||||
Reference in New Issue
Block a user