Skip to content

Commit

Permalink
Merge pull request #60 from CSC207-UofT/kill-all-warnings
Browse files Browse the repository at this point in the history
Fix all warnings
  • Loading branch information
SirRAL authored Dec 8, 2021
2 parents 90fbf13 + 5f89b9c commit deac1b2
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 203 deletions.
9 changes: 0 additions & 9 deletions src/main/java/Accounts/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ public void addDeck(Deck deck) {
this.decksToSessions.put(deck, new ArrayList<>());
}

/**
* Delete the given deck from this account.
* @param deck The deck which will be deleted from this account
*/
public void deleteDeck(Deck deck) {
this.decks.remove(deck);
this.decksToSessions.remove(deck);
}

/**
* Add the given StudySession to this account.
* @param deck The deck which the given session is based on
Expand Down
17 changes: 1 addition & 16 deletions src/main/java/Accounts/AccountController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

/**
* TODO: what does this class represent
* This class handles logic that UI elements need from accounts.
*/

public class AccountController {
Expand All @@ -30,13 +30,6 @@ public static void selectDeck(DeckDTO selectedDeckDTO) {
AccountInteractor.selectDeck(selectedDeckDTO);
}

/**
* Provide relevant interactors with the ability to use the given StudySession.
*/
public static void selectSession(DeckDTO deckDTO, StudySessionDTO sessionDTO) {
AccountInteractor.selectSession(deckDTO, sessionDTO);
}

/**
* @return the current account
*/
Expand Down Expand Up @@ -64,14 +57,6 @@ public static AccountDTO createAccount(String username, String password) {
return AccountInteractor.createAccount(username, password);
}

/**
* Change the current account's username to the given username.
* @param newUsername The new username of the account
*/
public static void changeCurrentAccountUsername(String newUsername) {
AccountInteractor.changeCurrentAccountUsername(newUsername);
}

/**
* Add a new deck to the account.
* @param deckDTO The deck to be added
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/Accounts/AccountDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,10 @@
import java.util.Map;

/**
* TODO, representation of class
* This class contains all data values that represent an Account, without any behaviour.
*/
public class AccountDTO {

private final String username;
private final String password;
private final List<DeckDTO> decks;
private final Map<DeckDTO, List<StudySessionDTO>> decksToSessions;

public AccountDTO(String username, String password, List<DeckDTO> decks, Map<DeckDTO,
List<StudySessionDTO>> decksToSessions) {
this.username = username;
this.password = password;
this.decks = decks;
this.decksToSessions = decksToSessions;
}
public record AccountDTO(String username, String password, List<DeckDTO> decks,
Map<DeckDTO, List<StudySessionDTO>> decksToSessions) {

/**
* @return this account's username
Expand Down
36 changes: 14 additions & 22 deletions src/main/java/Accounts/AccountInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Map;

/**
* TODO: what does this class represent
* This class handles use cases for Accounts.
*/
public class AccountInteractor {

Expand Down Expand Up @@ -85,14 +85,6 @@ public static AccountDTO createAccount(String username, String password) {
return convertAccountToDTO(account);
}

/**
* Change the current account's username to the given username.
* @param newUsername The new username of the account
*/
public static void changeCurrentAccountUsername(String newUsername) {
currentAccount.setUsername(newUsername);
}

/**
* Add a new deck to the account.
* @param deckDTO The deck to be added
Expand Down Expand Up @@ -186,9 +178,9 @@ public static void updateSessionsOfDeckInCurrentAccount(DeckDTO deckDTO) {
}

/**
* TODO
* @param accountDTO
* @return
* Converts an AccountDTO to an Account and returns the Account.
* @param accountDTO The AccountDTO to be converted
* @return The entity version of AccountDTO
*/
public static Account convertDTOToAccount(AccountDTO accountDTO) {
String username = accountDTO.getUsername();
Expand All @@ -209,9 +201,9 @@ public static Account convertDTOToAccount(AccountDTO accountDTO) {
}

/**
* TODO
* @param account
* @return
* Convert Account to AccountDTO
* @param account The Account to be converted.
* @return The AccountDTO version of account
*/
public static AccountDTO convertAccountToDTO(Account account) {
String username = account.getUsername();
Expand All @@ -232,9 +224,9 @@ public static AccountDTO convertAccountToDTO(Account account) {
}

/**
* TODO
* @param deckDTO
* @return
* Find and return the Deck corresponding to the deckDTO parameter in the current account.
* @param deckDTO The DeckDTO that corresponds to the Deck that is to be searched for
* @return The Deck that corresponds to deckDTO in the current Account
*/
private static Deck findDeckInCurrentAccountFromDTO(DeckDTO deckDTO) {
return currentAccount.getDecks().stream()
Expand All @@ -244,10 +236,10 @@ private static Deck findDeckInCurrentAccountFromDTO(DeckDTO deckDTO) {
}

/**
* TODO
* @param deck
* @param sessionDTO
* @return
* Find and return the StudySession corresponding to the sessionDTO given within the deck.
* @param deck The Deck that sessionDTO uses
* @param sessionDTO The StudySessionDTO that will be used to search for its entity version
* @return The true entity version of sessionDTO
*/
private static StudySession findSessionInCurrentAccountFromDTO(Deck deck, StudySessionDTO sessionDTO) {
StudySession selectedSession = SessionInteractor.convertDTOToSession(sessionDTO);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/Database/DatabaseGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


import Decks.DeckDTO;

import java.awt.image.BufferedImage;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;


Expand Down
54 changes: 29 additions & 25 deletions src/main/java/Database/MySQLDatabaseGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import java.util.List;

/**
* TODO, what this class represents
* This class implements DatabaseGateway with a MySQL concreteness, giving methods to communicate with a
* MySQl database server.
*/
public class MySQLDatabaseGateway implements DatabaseGateway {

Expand Down Expand Up @@ -70,10 +71,10 @@ public Boolean authenticateAccount(String username, String password){
}

/**
* TODO
* @param username
* @param password
* @return
* Returns the account with the given username and password
* @param username The username of the account
* @param password The password of the account
* @return The AccountDTO that has the same username and password
*/
public AccountDTO getAccountFromDB(String username, String password){
try{
Expand All @@ -90,9 +91,9 @@ public AccountDTO getAccountFromDB(String username, String password){
}

/**
* TODO
* @param username
* @return
* Finds if an account with username already exists
* @param username The username that will be checked for duplicates
* @return Whether an account with the same username already exists.
*/
public Boolean duplicateAccount(String username){
try {
Expand All @@ -110,9 +111,9 @@ public Boolean duplicateAccount(String username){
}

/**
* TODO
* @param username
* @param password
* Add an account with the given username and password to the database.
* @param username The username of the account
* @param password The password of the account
*/
public void addAccountToDB(String username, String password){
try {
Expand Down Expand Up @@ -221,9 +222,9 @@ public void updateCardFrontTextInDB(String oldValue, String newValue){
}

/**
* TODO
* @param oldValue
* @param newValue
* Updates a flashcard with a given back with its new value.
* @param oldValue The old back of the flashcard
* @param newValue The new back of the flashcard
*/
public void updateCardBackInDB(String oldValue, String newValue){
try{
Expand All @@ -241,9 +242,9 @@ public void updateCardBackInDB(String oldValue, String newValue){
}

/**
* TODO
* @param oldValue
* @param newValue
* Updates the deck name in the database after its name has been locally changed.
* @param oldValue The old name of the deck
* @param newValue The new name of the deck
*/
public void updateDeckNameInDB(String oldValue, String newValue){
try{
Expand All @@ -261,18 +262,21 @@ public void updateDeckNameInDB(String oldValue, String newValue){
}

/**
* TODO
* @param oldText
* @param newImage
* Changes a flashcard's image in the database after it was changed locally.
* @param oldText The flashcard's front text
* @param newImage The image that will replace the old image
*/
public void editFlashcardImage(String oldText, BufferedImage newImage){
try{
PreparedStatement pstmt = connection().prepareStatement("UPDATE cards SET image = (?) WHERE front = (?)");
InputStream in = imageToInputStream(newImage);
pstmt.setBlob(1, in);
pstmt.setString(2, oldText);
pstmt.execute();
pstmt.close();

if (newImage != null) {
InputStream in = imageToInputStream(newImage);
pstmt.setBlob(1, in);
pstmt.setString(2, oldText);
pstmt.execute();
pstmt.close();
}
} catch(Exception e){
e.printStackTrace();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/Decks/Deck.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Represents a deck of flashcards
*/
public class Deck implements Observable {
private List<Observer> observers;
private final List<Observer> observers;
private String name;
private final List<Flashcard> flashcards;
private List<Flashcard> flashcardsLastState;
Expand Down Expand Up @@ -96,7 +96,7 @@ public Deck copyDeck(){

/**
* add an observer to the observable
* @param observer
* @param observer The observer to be added
*/
@Override
public void addObserver(Observer observer) {
Expand All @@ -106,7 +106,7 @@ public void addObserver(Observer observer) {

/**
* delete an observer from the observable
* @param observer
* @param observer The observer to be added
*/
@Override
public void deleteObserver(Observer observer) {
Expand Down
30 changes: 13 additions & 17 deletions src/main/java/Decks/DeckController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.List;

/**
* TODO describe class
* This class handles the logic that UI elements need from Decks.
*/
public class DeckController {
// DatabaseGateway DBgateway = new DatabaseGateway();
Expand Down Expand Up @@ -49,17 +49,15 @@ public void selectFlashcard(FlashcardDTO flashcardDTO) {
* Create a new empty deck, which is bound to the current account and stored in a database. Return whether the
* deck was successfully created.
* @param name Name of the new deck
* @return whether the deck was successfully created
*/
public boolean createDeck(String name){
public void createDeck(String name){
DeckDTO deckDTO = DeckInteractor.createDeck(name);
AccountDTO accountDTO = AccountInteractor.getCurrentAccount();
if (!hasUniqueName(deckDTO, accountDTO)) {
return false;
return;
}
AccountInteractor.addDeckToCurrentAccount(deckDTO);
DBgateway.addDeckToDB(accountDTO.getUsername(), name);
return true;
}

/**
Expand Down Expand Up @@ -97,17 +95,15 @@ public void deleteCard(FlashcardDTO flashcardDTO) {
* @param frontText The text on the front of the new flashcard (possibly null)
* @param frontImage The image on the front of the new flashcard (possibly null)
* @param back The text on the back of the new flashcard
* @return whether the card was successfully created.
*/
public boolean addCard(String frontText, BufferedImage frontImage, String back) {
public void addCard(String frontText, BufferedImage frontImage, String back) {
if (!hasUniqueName(frontText, getCurrentDeck())) {
return false;
return;
}
DeckInteractor.addFlashcardToCurrentDeck(frontText, frontImage, back);
AccountInteractor.updateSessionsOfDeckInCurrentAccount(getCurrentDeck());
DBgateway.addCardToDeckInDB(AccountInteractor.getCurrentAccount().getUsername(), DeckInteractor.getCurrentDeck().getName(), frontText, back, frontImage);

return true;
}

/**
Expand All @@ -134,10 +130,10 @@ public void editCurrentFlashcardBack(String newBack) {
}

/**
* TODO
* @param deckDTO
* @param accountDTO
* @return
* Check and return whether the deckDTO has a unique name or not.
* @param deckDTO The deckDTO to be checked
* @param accountDTO The accountDTO that the deckDTO belongs to
* @return Whether the deckDTO's name is unique
*/
private boolean hasUniqueName(DeckDTO deckDTO, AccountDTO accountDTO) {
List<String> existingDeckNames = new ArrayList<>();
Expand All @@ -148,10 +144,10 @@ private boolean hasUniqueName(DeckDTO deckDTO, AccountDTO accountDTO) {
}

/**
* TODO
* @param frontText
* @param deckDTO
* @return
* Check and return whether a flashcard front has a unique front text or not.
* @param frontText The text to be compared
* @param deckDTO The deck that the flashcard belongs to
* @return Whether the front text is unique within that deck or not
*/
private boolean hasUniqueName(String frontText, DeckDTO deckDTO) {
List<String> existingFlashcardNames = new ArrayList<>();
Expand Down
Loading

0 comments on commit deac1b2

Please sign in to comment.