File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed
oracle-of-bacon-backend/src/main/java/com/serli/oracle/of/bacon Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,10 @@ public APIEndPoint() {
2222 }
2323
2424 @ Get ("bacon-to?actor=:actorName" )
25- // TODO change return type
25+ // change return type
2626 public String getConnectionsToKevinBacon (String actorName ) {
27+ redisRepository .saveSearch (actorName );
28+
2729 return "[\n " +
2830 "{\n " +
2931 "\" data\" : {\n " +
@@ -76,10 +78,6 @@ public List<String> getActorSuggestion(String searchQuery) throws IOException {
7678
7779 @ Get ("last-searches" )
7880 public List <String > last10Searches () {
79- return Arrays .asList ("Peckinpah, Sam" ,
80- "Robbins, Tim (I)" ,
81- "Freeman, Morgan (I)" ,
82- "De Niro, Robert" ,
83- "Pacino, Al (I)" );
81+ return redisRepository .getLastTenSearches ();
8482 }
8583}
Original file line number Diff line number Diff line change 44
55import redis .clients .jedis .Jedis ;
66
7+ import java .util .Arrays ;
8+
79public class RedisRepository {
810 private final Jedis jedis ;
11+ private final static String KEY = "SearchHistory" ;
912
1013 public RedisRepository () {
1114 this .jedis = new Jedis ("localhost" );
1215 }
13-
16+ public void saveSearch (String query ) {
17+ jedis .lpush (KEY , query );
18+ jedis .ltrim (KEY , 0 , 9 );
19+ }
1420 public List <String > getLastTenSearches () {
15- // TODO
16- return null ;
21+ String [] last10 = jedis . lrange ( KEY , 0 , - 1 ). toArray ( new String [ 0 ]);
22+ return Arrays . asList ( last10 ) ;
1723 }
1824}
You can’t perform that action at this time.
0 commit comments