Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatima #3

Merged
merged 2 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public APIEndPoint() {
}

@Get("bacon-to?actor=:actorName")
// TODO change return type
// change return type
public String getConnectionsToKevinBacon(String actorName) {
redisRepository.saveSearch(actorName);

return "[\n" +
"{\n" +
"\"data\": {\n" +
Expand Down Expand Up @@ -76,10 +78,6 @@ public List<String> getActorSuggestion(String searchQuery) throws IOException {

@Get("last-searches")
public List<String> last10Searches() {
return Arrays.asList("Peckinpah, Sam",
"Robbins, Tim (I)",
"Freeman, Morgan (I)",
"De Niro, Robert",
"Pacino, Al (I)");
return redisRepository.getLastTenSearches();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

import redis.clients.jedis.Jedis;

import java.util.Arrays;

public class RedisRepository {
private final Jedis jedis;
private final static String KEY = "SearchHistory";

public RedisRepository() {
this.jedis = new Jedis("localhost");
}

public void saveSearch(String query) {
jedis.lpush(KEY, query);
jedis.ltrim(KEY, 0, 9);
}
public List<String> getLastTenSearches() {
// TODO
return null;
String[] last10 = jedis.lrange(KEY, 0, -1).toArray(new String[0]);
return Arrays.asList(last10);
}
}