From 814da2d8df9d7d4208c9500ec3aeceb212c2c411 Mon Sep 17 00:00:00 2001 From: nicol Date: Sun, 10 Sep 2023 21:20:13 +0200 Subject: [PATCH] update redis --- src/main/java/org/beta/RedisDAO.java | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/beta/RedisDAO.java b/src/main/java/org/beta/RedisDAO.java index 37752d4a0..80fcb6f8d 100644 --- a/src/main/java/org/beta/RedisDAO.java +++ b/src/main/java/org/beta/RedisDAO.java @@ -26,6 +26,7 @@ import org.magic.api.interfaces.MTGSerializable; import org.magic.api.interfaces.abstracts.extra.AbstractKeyValueDao; import org.magic.services.TechnicalServiceManager; +import org.magic.services.tools.CryptoUtils; import org.magic.services.tools.IDGenerator; import org.magic.services.tools.POMReader; import io.lettuce.core.RedisClient; @@ -193,7 +194,7 @@ public List listDecks() throws SQLException { return ret; } - + @Override public void deleteDeck(MagicDeck d) throws SQLException { syncCommands.del(key(d)); @@ -497,7 +498,7 @@ public List listCollectionFromCards(MagicCard mc) throws SQLExc for(var collection : listCollections()) { - if(listCardsFromCollection(collection).stream().anyMatch(card->card.getId().equals(mc.getId()))) + if(listCardsFromCollection(collection).stream().anyMatch(card->IDGenerator.generate(card).equals(IDGenerator.generate(mc)))) c.add(collection); } return c; @@ -506,14 +507,22 @@ public List listCollectionFromCards(MagicCard mc) throws SQLExc @Override public List listStocks(MagicCard mc, MagicCollection col, boolean editionStrict) throws SQLException { - // TODO Auto-generated method stub - return new ArrayList<>(); + + if(editionStrict) + return listStocks().stream().filter(mcs->mcs.getMagicCollection().getName().equals(col.getName())).filter(mcs->mcs.getProduct().getId().equals(mc.getId())).toList(); + else + return listStocks().stream().filter(mcs->mcs.getMagicCollection().getName().equals(col.getName())).filter(mcs->mcs.getProduct().getName().equals(mc.getName())).toList(); } @Override public Contact getContactByLogin(String email, String password) throws SQLException { - // TODO Auto-generated method stub - return null; + var opt = listContacts().stream().filter(c->c.getEmail().equals(email) && c.getPassword().equals(IDGenerator.generateSha256(password))).findFirst(); + + if(opt.isPresent()) + return opt.get(); + + throw new SQLException("No result Found"); + } @Override @@ -532,7 +541,7 @@ public boolean enableContact(String token) throws SQLException { @Override public List listAnnounces(int max, STATUS stat) throws SQLException { - return new ArrayList<>(); + return new ArrayList<>(); }