Skip to content

Commit

Permalink
Searching by tags works properly + adding tags is now possible for al…
Browse files Browse the repository at this point in the history
…l types, not just books
  • Loading branch information
HoolaBoola committed Dec 7, 2020
1 parent 044b02b commit 4583e5b
Show file tree
Hide file tree
Showing 6 changed files with 356 additions and 58 deletions.
99 changes: 77 additions & 22 deletions src/main/java/recommendation_library/RecommendationApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/
package recommendation_library;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -105,24 +109,36 @@ public boolean timeStampAlreadyExists(String videoTitle, String time) {

public List<String> listBooks() {
List<BookRecommendation> list = service.getAllBookRecommendations();

return listBooks(list);
}

public List<String> listBooks(List<BookRecommendation> list) {
List<String> recommendationStrings = new ArrayList<>();
int i = 1;

for (BookRecommendation r : list) {
recommendationStrings.add(System.lineSeparator() + "Book " + i++ + System.lineSeparator()
+ "Author: " + r.getAuthor() + System.lineSeparator()
+ "Title: " + r.getTitle() + System.lineSeparator()
+ "Description: " + r.getDescription() + System.lineSeparator()
+ "ISBN: " + r.getIsbn() + System.lineSeparator()
+ "Page count: " + r.getPageCount() + System.lineSeparator()
+ "Added: " + r.getAddDate());
+ "Author: " + r.getAuthor() + System.lineSeparator()
+ "Title: " + r.getTitle() + System.lineSeparator()
+ "Description: " + r.getDescription() + System.lineSeparator()
+ "ISBN: " + r.getIsbn() + System.lineSeparator()
+ "Page count: " + r.getPageCount() + System.lineSeparator()
+ "Added: " + r.getAddDate());
System.out.println(i);

}

return recommendationStrings;
}

public List<String> listVideos() {
List<VideoRecommendation> list = service.getAllVideoRecommendations();

return listVideos(list);
}

public List<String> listVideos(List<VideoRecommendation> list) {
List<String> recommendationStrings = new ArrayList<>();
int i = 1;

Expand All @@ -136,11 +152,11 @@ public List<String> listVideos() {

List<String> timeStampStrings = listTimestampsForVideo(r.getTitle());
recommendationStrings.add(System.lineSeparator() + "Video " + i++ + System.lineSeparator()
+ "Title: " + r.getTitle() + System.lineSeparator()
+ "URL: " + r.getUrl() + System.lineSeparator()
+ "Timestamps: " + System.lineSeparator() + timeStampStrings + System.lineSeparator()
+ "Description: " + r.getDescription() + System.lineSeparator()
+ "Added: " + r.getAddDate());
+ "Title: " + r.getTitle() + System.lineSeparator()
+ "URL: " + r.getUrl() + System.lineSeparator()
+ "Timestamps: " + System.lineSeparator() + timeStampStrings + System.lineSeparator()
+ "Description: " + r.getDescription() + System.lineSeparator()
+ "Added: " + r.getAddDate());
}
return recommendationStrings;
}
Expand All @@ -157,38 +173,48 @@ public List<String> listTimestampsForVideo(String videotitle) {

public List<String> listBlogs() {
List<BlogRecommendation> list = service.getAllBlogRecommendations();

return listBlogs(list);
}

public List<String> listBlogs(List<BlogRecommendation> list) {
List<String> recommendationStrings = new ArrayList<>();
int i = 1;

for (BlogRecommendation r : list) {
recommendationStrings.add(System.lineSeparator() + "Blog " + i++ + System.lineSeparator()
+ "Author: " + r.getAuthor() + System.lineSeparator()
+ "Title: " + r.getTitle() + System.lineSeparator()
+ "Description: " + r.getDescription() + System.lineSeparator()
+ "URL: " + r.getUrl() + System.lineSeparator()
+ "Added: " + r.getAddDate());
+ "Author: " + r.getAuthor() + System.lineSeparator()
+ "Title: " + r.getTitle() + System.lineSeparator()
+ "Description: " + r.getDescription() + System.lineSeparator()
+ "URL: " + r.getUrl() + System.lineSeparator()
+ "Added: " + r.getAddDate());
}

return recommendationStrings;
}

public List<String> listPodcasts() {
List<PodcastRecommendation> list = service.getAllPodcastRecommendations();
return listPodcasts(list);
}

public List<String> listPodcasts(List<PodcastRecommendation> list) {
List<String> recommendationStrings = new ArrayList<>();
int i = 1;

for (PodcastRecommendation r : list) {
recommendationStrings.add(System.lineSeparator() + "Podcast " + i++ + System.lineSeparator()
+ "Podcast name: " + r.getPodcastName() + System.lineSeparator()
+ "Author: " + r.getAuthor() + System.lineSeparator()
+ "Title: " + r.getTitle() + System.lineSeparator()
+ "Description: " + r.getDescription() + System.lineSeparator()
+ "Added: " + r.getAddDate());
+ "Podcast name: " + r.getPodcastName() + System.lineSeparator()
+ "Author: " + r.getAuthor() + System.lineSeparator()
+ "Title: " + r.getTitle() + System.lineSeparator()
+ "Description: " + r.getDescription() + System.lineSeparator()
+ "Added: " + r.getAddDate());
}

return recommendationStrings;
}


public List<String> listVideoTitles() {
List<VideoRecommendation> videoRecommendationList = service.getAllVideoRecommendations();
List<String> videoTitleList = new ArrayList<>();
Expand Down Expand Up @@ -311,4 +337,33 @@ public boolean deletePodcast(String titleToDelete) {
return this.service.deletePodcastRecommendation(titleToDelete);
}

public List<Recommendation> getRecommendationsWithTag(String tag) {
ArrayList<Recommendation> list = new ArrayList<>();

list.addAll(getBooksWithTag(tag));
list.addAll(getVideosWithTag(tag));
list.addAll(getPodcastsWithTag(tag));
list.addAll(getBlogsWithTag(tag));
return list;
}

public List<BookRecommendation> getBooksWithTag(String tag) {
return service.getBooksWithTag(tag);
}

public List<VideoRecommendation> getVideosWithTag(String tag) {

return service.getVideosWithTag(tag);
}

public List<PodcastRecommendation> getPodcastsWithTag(String tag) {

return service.getPodcastsWithTag(tag);
}

public List<BlogRecommendation> getBlogsWithTag(String tag) {

return service.getBlogsWithTag(tag);
}

}
53 changes: 51 additions & 2 deletions src/main/java/recommendation_library/UserInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.*;

import recommendation_library.domain.Recommendation;
import recommendation_library.io.IO;
import recommendation_library.dao.RecommendationDao;
import recommendation_library.domain.BookRecommendation;
Expand Down Expand Up @@ -46,7 +47,11 @@ public UserInterface(IO io, RecommendationApp app) {
*/
public void run() {
while (true) {
io.print("");
this.io.print("[1] Add recommendation, [2] List recommendations, [3] Edit recommendation, [4] Delete recommendation, [5] Exit");
io.print("[10] Search recommendations by tag");
io.print("");

String input = io.nextLine();
if(validateInput(input)) {
int numericInput = Integer.valueOf(input);
Expand Down Expand Up @@ -96,6 +101,9 @@ public void checkInput(int input) {
case 5:
listTags();
break;
case 10:
searchByTag();
break;
default:
io.print("Unknown command");
}
Expand Down Expand Up @@ -324,7 +332,10 @@ public void addPodcast() {
}

public void list() {
io.print("");
this.io.print("[1] List all recommendations, [2] List books, [3] List videos, [4] List blogs, [5] List podcasts, [6] List tags");
io.print("");

String input = String.valueOf(io.nextLine());

switch(input) {
Expand Down Expand Up @@ -394,6 +405,44 @@ public void listTags() {
}
}

public void searchByTag() {

io.print("Which tag do you want to search?");
String tag = io.nextLine();

searchTagsWithType(tag);
}

public void searchTagsWithType(String tag) {
io.print("");
io.print("[1] List all recommendations, [2] List books, [3] List videos, [4] List blogs, [5] List podcasts");
io.print("");
String type = io.nextLine();
List<String> recommendations = new ArrayList<>();
switch (type) {
case "1":
recommendations = recommendationApp.listBooks(recommendationApp.getBooksWithTag(tag));
recommendations.addAll(recommendationApp.listVideos(recommendationApp.getVideosWithTag(tag)));
recommendations.addAll(recommendationApp.listBlogs(recommendationApp.getBlogsWithTag(tag)));
recommendations.addAll(recommendationApp.listPodcasts(recommendationApp.getPodcastsWithTag(tag)));
break;
case "2":
recommendations = recommendationApp.listBooks(recommendationApp.getBooksWithTag(tag));
break;
case "3":
recommendations = recommendationApp.listVideos(recommendationApp.getVideosWithTag(tag));
break;
case "4":
recommendations = recommendationApp.listBlogs(recommendationApp.getBlogsWithTag(tag));
break;
case "5":
recommendations = recommendationApp.listPodcasts(recommendationApp.getPodcastsWithTag(tag));
break;
}

recommendations.forEach(io::print);
}

/**
* list all recommendations contained within the library
*/
Expand Down Expand Up @@ -600,6 +649,7 @@ public void editBlog() {
this.io.print("Recommendation with the given title doesn't exist! Try again: ");
}
}

public void editPodcast() {
List<String> stringFieldNames = Arrays.asList("1", "2", "3", "4");

Expand Down Expand Up @@ -650,8 +700,7 @@ public void editPodcast() {
this.io.print("Recommendation with the given title doesn't exist! Try again: ");
}
}



public void deleteBook() {
this.io.print("Enter the title of the recommendation you wish to delete:\nTitles in your library:");
List<String> allBookTitles = recommendationApp.listBookTitles();
Expand Down
Loading

0 comments on commit 4583e5b

Please sign in to comment.