Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1df9a7f
LoggedInView.java - execute the logout use case, save the logout cont…
PikachuSean Oct 21, 2024
ca34968
Task 2
Wang20030509 Oct 21, 2024
f709fc6
Merge pull request #1 from Kaguya-kyuu/sean.yin
Kaguya-kyuu Oct 21, 2024
a95179e
Merge pull request #2 from Kaguya-kyuu/interface
Kaguya-kyuu Oct 21, 2024
6ea99c5
Complete usecase.logout 4 TODOs
Kaguya-kyuu Oct 21, 2024
193aa92
Updated README.md to include team members and GitHub usernames (missi…
PikachuSean Nov 4, 2024
a9c6f7d
Updated README.md to include team members and GitHub usernames (missi…
PikachuSean Nov 4, 2024
d4d8c9e
Updated README.md to include team members and GitHub usernames (missi…
PikachuSean Nov 4, 2024
c704109
Merge pull request #3 from Kaguya-kyuu/sean_yin
Kaguya-kyuu Nov 4, 2024
2cdebff
Updated README.md to include Charles' GitHub username
PikachuSean Nov 10, 2024
e01520e
Merge pull request #4 from Kaguya-kyuu/sean_yin
Kaguya-kyuu Nov 10, 2024
449d8e1
Added Translate and TranslateFactory entities, added DeepL API to dep…
PikachuSean Nov 11, 2024
7e0088f
Merge pull request #5 from Kaguya-kyuu/sean_yin
Kaguya-kyuu Nov 11, 2024
7511f5a
Update the LoggedInView
Wang20030509 Nov 11, 2024
6316c05
Merge pull request #6 from Kaguya-kyuu/doran
Kaguya-kyuu Nov 11, 2024
b1551bc
,
Kaguya-kyuu Nov 11, 2024
c304b68
,
Kaguya-kyuu Nov 11, 2024
9ac188a
Merge branch 'main' of https://github.com/Kaguya-kyuu/Translator-program
Kaguya-kyuu Nov 11, 2024
75156b9
Add Javadoc, Exception to translateText method
Kaguya-kyuu Nov 11, 2024
dc03bef
Merge pull request #7 from Kaguya-kyuu/ericka.qiu
PikachuSean Nov 11, 2024
4b058e1
Create Folders
Kaguya-kyuu Nov 11, 2024
9057e1f
Merge pull request #8 from Kaguya-kyuu/ericka.qiu
PikachuSean Nov 11, 2024
028fa91
Update TranslatorUserDataAccessInterface
Wang20030509 Nov 15, 2024
a8db28f
Merge pull request #9 from Kaguya-kyuu/doran
PikachuSean Nov 15, 2024
b7b23ff
Updated TranslatorOutputData.java
PikachuSean Nov 15, 2024
626324b
Merge pull request #10 from Kaguya-kyuu/sean.yin
Wang20030509 Nov 15, 2024
c637508
Upload translate folder in Interface_adapter
Wang20030509 Nov 15, 2024
5cea11b
Merge pull request #11 from Kaguya-kyuu/doran
PikachuSean Nov 15, 2024
2889eed
Updated TranslatorOutputBoundary.java
PikachuSean Nov 15, 2024
0394c67
Merge pull request #12 from Kaguya-kyuu/sean.yin
Wang20030509 Nov 15, 2024
3a821c5
implement TranslatorInputBoundary and TranslatorInputData
Kaguya-kyuu Nov 15, 2024
e39bf40
add javadoc
Kaguya-kyuu Nov 15, 2024
1bfcb71
Merge pull request #13 from Kaguya-kyuu/ericka.qiu
Wang20030509 Nov 15, 2024
4bd6fff
Update the InMemoryUserDataAccessObject
Wang20030509 Nov 15, 2024
8c95176
Merge pull request #14 from Kaguya-kyuu/doran
PikachuSean Nov 15, 2024
b3f2db2
charles
charles0504 Nov 15, 2024
97b052b
charles
charles0504 Nov 18, 2024
425ec61
charles
charles0504 Nov 18, 2024
a87e476
charles
charles0504 Dec 1, 2024
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
198 changes: 40 additions & 158 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,181 +1,63 @@
# Lab 5: Logout

## Preamble

In the current homework, you added code to the login use case to save the currently-logged-in
user by saving the user in the Data Access Layer. You also added a unit test for this.

In this lab, you will complete a logout use case as a team. You will also begin to discuss your project
and the use cases that need to be implemented.

We have created all the Clean Architecture classes necessary for the logout use case.

By Friday, your team will submit:
- your completed lab code [for credit]
- a draft of your project blueprint proposal. [required, but not for credit]

# Phase 2 [for credit]
_(recall, Phase 1 was your solo task of adding the storage of the currently-logged-in user)_

## Task 0: Fork this repo on GitHub
**To get started, one team member should fork this repo on GitHub and share it with the team.
All of you should then clone it.**

* * *

Suggested logistics: One of you should invite the others to collaborate on their fork of the
original repo on GitHub. You can do this in your repo on GitHub under `Settings -> Collaborators`.
This will allow you to push branches to a common repo and then use pull requests to contribute
your code and review. To prevent others from pushing directly to the main branch,
we recommend you set branch protection rules on GitHub. Below are how the settings might look if you
add branch protection rules:

![image of branch protection rules for main with the
requirement of two approvers to merge in pull requests.
](images/branch_protection_rules.png)

* * *

Open the project in IntelliJ and make sure you can successfully run `app/Main.java`.
Note: you may need to set the Project SDK in the `Project Structure...` menu, and possibly
also manually link the Maven project, as you did in Phase 1.

## Task 1: Understanding the Program

You may notice that we have refactored the CA engine code _slightly_ since Phase 1, but the
way we build the engine is drastically different: we have switched from using Factories to
using the Builder design pattern, which we'll be discussing in lecture soon.

Open up `app.Main` and read it as a team.
- What are the Views and what are the current Use Cases?
- Which Uses Cases are triggered from each View?
- Which version of the DAO is `app.Main` using?

The major change since Phase 1 is that we have added the `app.AppBuilder` class which makes
it easier to understand how our CA engine is being constructed — it also makes `app.Main` nice and concise!
- Why do all those `addX` methods end in `return this;`?

Run the program and make sure the signup and login Use Cases work.

Currently, you'll notice that the "Log Out" button still doesn't actually log you out. It's time to fix
that button, which is part of the `LoggedInView`.
We have created all the classes for you, but some of the code is missing.
As a team, your task is to fill in the missing code so that the Logout Use Case is implemented.
**The next part of the readme describes how your team will do this.**

* * *

**Your team will know when you are done when:**

- Clicking the "Log Out" button takes the user back to the Login View when you use the program.
- The provided `LogoutInteractorTest` test passes.

The "Log Out" button is an instance variable in class `LoggedInVew`. Go find it.
Also look at the `interface_adapter.change_password.LoggedInViewModel`, which contains any
data showing on the `LoggedInVew`.
# CSC207 Group Project

* * *

## Task 2: Dividing up the work
## Group 108 - Translator Program

There are `TODO` comments left in the files
Recall that you can use the TODO tool window to conveniently pull up a complete list.
* * *

Once the TODOs are all complete, the "Log Out" button _should_ work!

As a team, split up the TODOs (see below) between the members of your team.

There are TODOs in seven of the files.
Make sure each member has at least one TODO which they will be responsible for completing.
If your team prefers to work in pairs, that is fine too. Your individual branches
will not be graded for this — only the final, working version.

The TODOs are summarized below (by file) to help your team decide how to split them up:
**Team Members:**
- Sean Yin (GitHub Username: PikachuSean)
- Haoxuan Qiu (GitHub Username: Kaguya-kyuu)
- Doran Wang (GitHub Username: Wang20030509)
- Charles Cai (GitHub Username: charles0504)

* * *

- `Main.java`
**Domain:** Translation generation and management

- [ ] TODO: add the Logout Use Case to the app using the appBuilder
**Software Specification:**
The program allows users to translate between several languages. Users can create and sign in to accounts, allowing users to bookmark translations and view their translation history. Users can submit feedback on translations they think are inaccurate and can suggest a better translation.

* * *
**User Stories:**
1. Bob creates and signs in to an account for the translation app. He translates a sentence from one language to another and receives a translation from the app. (Team story)

- `LoggedInView.java` (tip: refer to the other views for similar code)
2. Bob is a student in a language class. His teacher has created a class account for all the students to use, and he wants to see the translations that his teacher displayed in class. He signs in to the class account, and he views the translation history. (Doran)

- [ ] TODO: save the logout controller in the instance variable.
- [ ] TODO: execute the logout use case through the Controller
3. Bob is a user of the translation app. He translates a sentence from one language to another. He finds the translation inaccurate and decides to submit a suggestion for a better translation. After some time, the suggestion is accepted by the developers of the app and now the app displays the new suggested translation. (Sean)

* * *

- `LogoutController.java` (tip: refer to the other controllers for similar code)
4. Bob is studying a second language. Sometimes he wants to be able to save his translation result for future review. So he decides to bookmark it so he can see it later by accessing his bookmarked translations. (Ericka)

- [ ] TODO: Save the interactor in the instance variable.
- [ ] TODO: run the use case interactor for the logout use case
5. Bob is sick and tired of google translate so he decided to find a better translator. He found this amazing translator called (our app name). He finds out there is a create account/sign in function which is always ignored on translator apps. He decided to create an account and found out there are so many useful functions! He translated a long paragraph that he will be working on for a few days. Unfortunately, he forgot to bookmark it, but he looks through his translation history to find it and bookmarks it from there so he can come back to it within a few clicks. (Charles)

* * *
**Proposed Entities for the Domain:**

- `LogoutInputData.java` (should be done with the LogoutInteractor TODOs below)
Translator
- String inputLanguage
- String outputLanguage
- String inputText
- String translatedText

- [ ] TODO: save the current username in an instance variable and add a getter.
History
- User currentUser
- List<Translator> translationHistory

- `LogoutInteractor.java` (tip: refer to `ChangePasswordInteractor.java` for similar code)
Bookmark
- User currentUser
- List<Translator> bookmarkedTranslations

- [ ] TODO: save the DAO and Presenter in the instance variables.
- [ ] TODO: implement the logic of the Logout Use Case

* * *

- `LogoutOutputData.java`

- [ ] TODO: save the parameters in the instance variables.

* * *
User
- String username
- String password

- `LogoutPresenter.java` (tip: refer to `SignupPresenter.java` for similar code)
Feedback
- Translator wrongTranslation
- String inputFeedback

- [ ] TODO: assign to the three instance variables.
- [ ] TODO: have prepareSuccessView update the LoggedInState
- [ ] TODO: have prepareSuccessView update the LoginState

* * *

1. Make a branch named the first part of your UofT email address, everything before the `@`.
For example, if your email address is `paul.gries@mail.utoronto.ca`, then the branch name would
be `paul.gries`.

Make sure you switch to the new branch.

In the terminal, this would look like below, but replaced with your own information:
```
git branch paul.gries
git switch paul.gries
```

2. Complete your assigned TODOs and make a pull request on GitHub. In your pull request,
briefly describe what your TODOs were and how you implemented them. If you aren't sure
about part of it, include this in your pull request so everyone knows what to look
for when reviewing — or you can of course discuss with your team before making your
pull request since you are physically working in the same space.
- **Important: don't push any changes to the `.idea` folder, as that
may cause issues for your other teammates, as some files contain
configurations specific to your individual IntelliJ projects.**

3. Review each other's pull requests to ensure each TODO is correctly implemented and that
there are no Checkstyle issues in the files that were modified.

4. Once all TODOs are completed, your team should debug as needed to ensure the
correctness of the code. Setting a breakpoint where the log-out use case
interactor starts its work will likely be a great place to start when debugging.

And that's it; you now have a working Logout Use Case! Instructions for
how to submit your work on MarkUs will be posted later.

Your team should spend the rest of the lab working on your project blueprint.

* * *
**Proposed API to Use:**
https://www.deepl.com/en/docs-api

# Project Blueprint
**Scheduled Meeting Times + Mode of Communication:**

See Quercus for details about the project blueprint! By the end of the week,
the goal is for your team to have a fully drafted blueprint so that your team
will be ready to get started on your project after Reading Week.
Meeting time outside of lab: Meet on Friday afternoons
Mode of Communication: Discord group chat
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.deepl.api</groupId>
<artifactId>deepl-java</artifactId>
<version>1.6.0</version>
</dependency>

</dependencies>

Expand All @@ -44,4 +49,4 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
</project>
23 changes: 23 additions & 0 deletions src/main/java/Example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import com.deepl.api.*;

public class Example {
private Translator translator;

public Example() throws Exception {
final String authKey = "59431b39-31eb-423d-9fcd-b86eb38b23e0:fx"; // Replace with your key
translator = new Translator(authKey);
final TextResult result =
translator.translateText("Hello, world!", null, "fr");
System.out.println(result.getText()); // "Bonjour, le monde !"
}

public static void main(String[] args) {
try {
final String authKey = "59431b39-31eb-423d-9fcd-b86eb38b23e0:fx"; // Replace with your key
final Translator translator2 = new Translator(authKey);
final TextResult result = translator2.translateText("How are you doing", null, "ja");
System.out.println(result.getText());
}
catch (InterruptedException e) {}
catch (DeepLException e) {}
}}
2 changes: 1 addition & 1 deletion src/main/java/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class Main {
*/
public static void main(String[] args) {
final AppBuilder appBuilder = new AppBuilder();
// TODO: add the Logout Use Case to the app using the appBuilder
final JFrame application = appBuilder
.addLoginView()
.addSignupView()
.addLoggedInView()
.addSignupUseCase()
.addLoginUseCase()
.addLogoutUseCase()
.addChangePasswordUseCase()
.build();

Expand Down
60 changes: 59 additions & 1 deletion src/main/java/data_access/InMemoryUserDataAccessObject.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package data_access;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import entity.Translate;
import entity.User;
import use_case.change_password.ChangePasswordUserDataAccessInterface;
import use_case.login.LoginUserDataAccessInterface;
import use_case.logout.LogoutUserDataAccessInterface;
import use_case.signup.SignupUserDataAccessInterface;
import use_case.translator.TranslatorUserDataAccessInterface;

/**
* In-memory implementation of the DAO for storing user data. This implementation does
Expand All @@ -16,12 +19,17 @@
public class InMemoryUserDataAccessObject implements SignupUserDataAccessInterface,
LoginUserDataAccessInterface,
ChangePasswordUserDataAccessInterface,
LogoutUserDataAccessInterface {
LogoutUserDataAccessInterface,
TranslatorUserDataAccessInterface {

private final Map<String, User> users = new HashMap<>();

private String currentUsername;

private final Map<String, Translate> translates = new HashMap<>();

private final Map<User, List<Translate>> userTranslates = new HashMap<>();

@Override
public boolean existsByName(String identifier) {
return users.containsKey(identifier);
Expand Down Expand Up @@ -52,4 +60,54 @@ public void setCurrentUsername(String name) {
public String getCurrentUsername() {
return this.currentUsername;
}

@Override
public void saveTranslation(Translate translation) {
translates.put(translation.getInputText(), translation);
}

@Override
public Translate getTranslation(String text) {
return translates.get(text);
}

@Override
public void deleteTranslation(String text) {
translates.remove(text);
}

@Override
public List<Translate> getAllTranslationsByUser(User user) {
return userTranslates.get(user);
}

@Override
public Translate getMostRecentTranslation(User user) {
return userTranslates.get(user).get(0);
}

@Override
public boolean existsByText(String text) {
return users.containsKey(text);
}

@Override
public void updateTranslation(User user, Translate updatedTranslation) {
translates.put(updatedTranslation.getInputText(), updatedTranslation);

}

public class InMemoryUserDataAccessObject implements ChangePasswordUserDataAccessInterface {
private User currentUser;

@Override
public boolean updatePassword(String newPassword) {
if (currentUser != null) {
currentUser.setPassword(newPassword);
return true;
}
return false;
}
}

}
Loading