Commit 0dde568e authored by Daniel Kim's avatar Daniel Kim
Browse files
parents 57aa0fc8 5e6234bd
......@@ -91,6 +91,14 @@ public class ClientApplication {
System.out.println("Delete person \"" + command.substring(3) + "\"");
deletePerson(command.substring(3));
break;
case "af":
System.out.println("Add to your favourites \"" + command.substring(3) + "\"");
addFavourite(command.substring(3));
break;
case "df":
System.out.println("Delete from your favourites \"" + command.substring(3) + "\"");
deleteFavourite(command.substring(3));
break;
default:
System.out.println("Invalid command. Type \"qt\" to quit.");
break;
......@@ -171,6 +179,76 @@ public class ClientApplication {
}
}
public static void addFavourite(String entity) {
String searchMovieQueryString = "select * from Movies where title like '%s%%'";
try {
Statement st = c.createStatement();
String query = String.format(searchMovieQueryString, entity);
ResultSet rs = st.executeQuery(query);
if (rs.next()) {
String movieID = rs.getString(1);
query = String.format("select * from UsersFavouriteMovies where movieID = '%s' and userID = '%s'", movieID, User);
rs = st.executeQuery(query);
if (rs.next()) {
System.out.println("You have already added this movie to your favourites.");
} else {
query = String.format("insert into UsersFavouriteMovies values ('%s', '%s')", User, movieID);
// System.out.println(query);
st.execute(query);
System.out.println("Movie successfully added to favourites.");
}
} else {
System.out.println("Movie not found.");
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void deleteFavourite(String entity) {
String searchMovieQueryString = "select * from Movies where title like '%s%%'";
try {
Statement st = c.createStatement();
String query = String.format(searchMovieQueryString, entity);
ResultSet rs = st.executeQuery(query);
if (rs.next()) {
String movieID = rs.getString(1);
System.out.println("Are you sure you want to delete this movie from your favourites?");
System.out.println("Type y to confirm. Type any other character to cancel.");
String command = "";
command = input.nextLine();
if (command.equals("y")) {
query = String.format("select * from UsersFavouriteMovies where movieID = '%s' and userID = '%s'", movieID, User);
rs = st.executeQuery(query);
if (!rs.next()) {
System.out.println("This movie is not in your favourites.");
} else {
query = String.format("delete from UsersFavouriteMovies where movieID = '%s' and userID = '%s'", movieID, User);
// System.out.println(query);
st.execute(query);
System.out.println("Movie successfully deleted from favourites.");
}
} else {
System.out.println("Action cancelled.");
}
} else {
System.out.println("Movie not found.");
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void addReview(String entity) {
String searchMovieQueryString = "select * from Movies where title like '%s%%'";
try {
......@@ -286,19 +364,21 @@ public class ClientApplication {
String command = "";
//Available commands for admins and users include search, add review, edit review, delete review, help, switch, quit
//Available commands for admins include add movie, edit movie, delete movie
Command searchCommand = new Command("Search", "se", "se <movie/person>", "Search for a movie or person.");
Command addReviewCommand = new Command("Add Review", "ar", "ar", "Add a review to a movie.");
Command editReviewCommand = new Command("Edit Review", "er", "er", "Edit the selected review on a movie.");
Command deleteReviewCommand = new Command("Delete Review", "dr", "dr", "Delete the selected review from a movie.");
Command searchCommand = new Command("Search", "se", "se <movie/genre/person> <keywords>", "Search for movies by title, genre, or person.");
Command addReviewCommand = new Command("Add Review", "ar", "ar <title>", "Add a review to the selected movie.");
Command editReviewCommand = new Command("Edit Review", "er", "er <title>", "Edit the review on the selected movie.");
Command deleteReviewCommand = new Command("Delete Review", "dr", "dr <title>", "Delete the review from the selected movie.");
Command switchCommand = new Command("Switch", "sw", "sw", "Switch between an admin and user role.");
Command helpCommand = new Command("Help", "hp", "hp", "View the list of currently available commands.");
Command quitCommand = new Command("Quit", "qt", "qt", "Exits the program.");
Command addMovieCommand = new Command("Add Movie", "am", "am", "Add a movie to the database.");
Command editMovieCommand = new Command("Edit Movie", "em", "em", "Edit the selected movie in the database.");
Command deleteMovieCommand = new Command("Delete Movie", "dm", "dm", "Delete the selected movie from the database.");
Command editMovieCommand = new Command("Edit Movie", "em", "em <title>", "Edit the selected movie in the database.");
Command deleteMovieCommand = new Command("Delete Movie", "dm", "dm <title>", "Delete the selected movie from the database.");
Command addPersonCommand = new Command("Add Person", "ap", "ap", "Add a person to the database.");
Command editPersonCommand = new Command("Edit Person", "ep", "ep", "Edit the selected person in the database.");
Command deletePersonCommand = new Command("Delete Person", "dp", "dp", "Delete the selected person from the database.");
Command editPersonCommand = new Command("Edit Person", "ep", "ep <name>", "Edit the selected person in the database.");
Command deletePersonCommand = new Command("Delete Person", "dp", "dp <name>", "Delete the selected person from the database.");
Command addFavouriteCommand = new Command("Add Favourite Movie", "af", "af <title>", "Add the selected movie to favourites.");
Command deleteFavouriteCommand = new Command("Delete Favourite Movie", "df", "df <title>", "Delete the selected movie from favourites.");
// HashMap<String, Command> commands = new HashMap<String, Command>();
......@@ -308,6 +388,8 @@ public class ClientApplication {
defaultCommands.put(addReviewCommand.getCmd(), addReviewCommand);
defaultCommands.put(editReviewCommand.getCmd(), editReviewCommand);
defaultCommands.put(deleteReviewCommand.getCmd(), deleteReviewCommand);
defaultCommands.put(addFavouriteCommand.getCmd(), addFavouriteCommand);
defaultCommands.put(deleteFavouriteCommand.getCmd(), deleteFavouriteCommand);
defaultCommands.put(switchCommand.getCmd(), switchCommand);
defaultCommands.put(helpCommand.getCmd(), helpCommand);
defaultCommands.put(quitCommand.getCmd(), quitCommand);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment