-
Notifications
You must be signed in to change notification settings - Fork 0
Week 05 - Assignment on Lecture 09 and 10 #4
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
Open
mikeleo03
wants to merge
35
commits into
main
Choose a base branch
from
Week_05
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
55d29ff
[Refactor] Fix on Assignment 05
mikeleo03 77f0bea
[Refactor] Fix on Assignment 06
mikeleo03 05d249e
Merge pull request #1 from affandyfandy/Week_02
mikeleo03 111eecb
[Feat] Implementation of Assignment 01
mikeleo03 0aa4915
[Refactor] Updated tree strcuture
mikeleo03 4793ccd
[Refactor] Tree structure of code
mikeleo03 15bba48
[Feat] Implementing base case of Assignment 02
mikeleo03 f83860c
[Feat] Details and commentary on program
mikeleo03 b778bb7
[Feat] Backend pagination logic
mikeleo03 6c7b90e
[Feat] Frontend pagination logic
mikeleo03 44d098a
[Feat] Integrating html-css-js
mikeleo03 ede4685
[Feat] More intense validation mechanism on CSV file
mikeleo03 c3d1f71
[Fix] Upload mechanism
mikeleo03 3e15b07
[Feat] README stuff
mikeleo03 04d545b
[Refactor] Update README links
mikeleo03 a6df715
[Feat] Starting Assignment 03 by copying Assignment 02
mikeleo03 e5a03bf
[Feat] PDF generation logic on backend
mikeleo03 a0800f3
[Feat] PDF generating logic frontend
mikeleo03 85621eb
[Feat] Markdown explanation
mikeleo03 c4e4d84
[Feat] Generated PDF result
mikeleo03 466585e
[Feat] Adjusting the model and scheme
mikeleo03 ae91cb9
[Feat] Frontend adjustment to new model
mikeleo03 dd111dc
[Feat] PDF generation based on template
mikeleo03 3bf8046
[Feat] Generated PDF
mikeleo03 267a13c
[Feat] Better UI uisng TailwindCSS
mikeleo03 d46f3b3
[Refactor] Update README.md
mikeleo03 c814cd9
[Refactor] Frontend refinement
mikeleo03 bdf2f95
[Refactor] Updated UI on employee form
mikeleo03 b37d5f6
[Feat] Backend for search feature
mikeleo03 17d96b1
[Feat] Frontend for search feature
mikeleo03 1466cc9
[Feat] Add bonus documentation
mikeleo03 5472050
[Feat] Initialize project by importing lecture 5
mikeleo03 48b7808
[Feat] README documentation
mikeleo03 740488d
[Feat] Full implementation
mikeleo03 26f984c
[Refactor] README component
mikeleo03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| target | ||
| target | ||
| Help.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 37 additions & 28 deletions
65
Week 02/Lecture 04/Assignment 06/RemoveDuplicatesCSV.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,55 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.BufferedWriter; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Paths; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| public class RemoveDuplicatesCSV { | ||
| public static void main(String[] args) { | ||
| String inputFilePath = "data/data.csv"; | ||
| String outputFilePath = "data/unique.csv"; | ||
| String keyFieldName = "id"; | ||
|
|
||
| try (BufferedReader reader = Files.newBufferedReader(Paths.get(inputFilePath))) { | ||
| List<String> lines = reader.lines().collect(Collectors.toList()); | ||
| if (lines.isEmpty()) return; | ||
| try (BufferedReader reader = Files.newBufferedReader(Paths.get(inputFilePath)); | ||
| BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputFilePath))) { | ||
|
|
||
| String header = reader.readLine(); | ||
| if (header == null) return; | ||
|
|
||
| // Extract header and determine the key field index | ||
| String header = lines.get(0); | ||
| List<String> headers = Arrays.asList(header.split(",")); | ||
| int keyIndex = headers.indexOf(keyFieldName); | ||
| if (keyIndex == -1) throw new IllegalArgumentException("Invalid key field name"); | ||
| // Write header to the output file | ||
| writer.write(header); | ||
| writer.newLine(); | ||
|
|
||
| // Process lines and remove duplicates based on the key field | ||
| List<String> uniqueLines = lines.stream() | ||
| .skip(1) // Skip header | ||
| .collect(Collectors.toMap( | ||
| line -> line.split(",")[keyIndex], // Use the key field | ||
| line -> line, // Use the line as value | ||
| (existing, replacement) -> existing // Keep the first occurrence | ||
| )) | ||
| .values() | ||
| .stream() | ||
| .collect(Collectors.toList()); | ||
| // Determine the key field index | ||
| String[] headers = header.split(","); | ||
| int keyIndex = -1; | ||
| for (int i = 0; i < headers.length; i++) { | ||
| if (headers[i].trim().equals(keyFieldName)) { | ||
| keyIndex = i; | ||
| break; | ||
| } | ||
| } | ||
| if (keyIndex == -1) throw new IllegalArgumentException("Invalid key field name"); | ||
|
|
||
| // Add header back to the list | ||
| uniqueLines.add(0, header); | ||
| // Use a Set to track unique keys | ||
| Set<String> seenKeys = new HashSet<>(); | ||
|
|
||
| // Write the results to a new file | ||
| Files.write(Paths.get(outputFilePath), uniqueLines); | ||
| // Read and process each line | ||
| String line; | ||
| while ((line = reader.readLine()) != null) { | ||
| String[] fields = line.split(","); | ||
| if (fields.length > keyIndex) { | ||
| String key = fields[keyIndex]; | ||
| if (seenKeys.add(key)) { // Add returns false if the key was already present | ||
| writer.write(line); | ||
| writer.newLine(); | ||
| } | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| System.out.println("I/O Error occured:" + e); | ||
| System.out.println("I/O Error occurred: " + e); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # 👨🏻🏫 Lecture 09 - Spring MVC | ||
| > This repository is created as a part of assignment for Lecture 09 - Spring MVC | ||
|
|
||
| ## 🔎 Assignment 01 - Practice the Example | ||
| ### 🌳 Project Structure | ||
| ```bash | ||
| lecture_9 | ||
| ├── .mvn/wrapper/ | ||
| │ └── maven-wrapper.properties | ||
| ├── src/main/ | ||
| │ ├── java/com/example/lecture_9/ | ||
| │ │ ├── controller/ | ||
| │ │ │ └── EmployeeController.java | ||
| │ │ ├── model/ | ||
| │ │ │ └── Employee.java | ||
| │ │ ├── repository/ | ||
| │ │ │ └── EmployeeRepository.java | ||
| │ │ ├── service/ | ||
| │ │ │ ├── impl/ | ||
| │ │ │ │ └─ EmployeeServiceImpl.java | ||
| │ │ │ └── EmployeeService.java | ||
| │ │ └── Lecture9Application.java | ||
| │ └── resources/ | ||
| │ ├── static/ | ||
| │ │ └── index.html | ||
| │ ├── templates/employees/ | ||
| │ │ ├── employee-form.html | ||
| │ │ └── list-employees.html | ||
| │ └── application.properties | ||
| ├── .gitignore | ||
| ├── mvnw | ||
| ├── mvnw.cmd | ||
| ├── pom.xml | ||
| ├── run.bat | ||
| └── run.sh | ||
| ``` | ||
|
|
||
| ### 🧩 SQL Query Data | ||
| Here is the SQL query to create the database, table, and instantiate some data, given by the [reference repository](https://github.com/NguyenVanTrieu/spring-mvc). | ||
| ```sql | ||
| -- Create the database | ||
| CREATE DATABASE week5_lecture9; | ||
|
|
||
| -- Use the database | ||
| USE week5_lecture9; | ||
|
|
||
| -- Create the employee table | ||
| CREATE TABLE `employee` ( | ||
| `id` int NOT NULL AUTO_INCREMENT, | ||
| `first_name` varchar(45) DEFAULT NULL, | ||
| `last_name` varchar(45) DEFAULT NULL, | ||
| `email` varchar(45) DEFAULT NULL, | ||
| PRIMARY KEY (`id`) | ||
| ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; | ||
|
|
||
| -- Insert dummy data into the employee table | ||
| INSERT INTO `employee` VALUES | ||
| (1,'Leslie','Andrews','leslie@luv2code.com'), | ||
| (2,'Emma','Baumgarten','emma@luv2code.com'), | ||
| (3,'Avani','Gupta','avani@luv2code.com'), | ||
| (4,'Yuri','Petrov','yuri@luv2code.com'), | ||
| (5,'Juan','Vega','juan@luv2code.com'); | ||
| ``` | ||
|
|
||
| and here is the query to drop the database | ||
| ```sql | ||
| -- Drop the database | ||
| DROP DATABASE IF EXISTS week5_lecture9; | ||
| ``` | ||
|
|
||
| Also don't forget to configure [application properties](/Week%2005/Lecture%2009/Assignment%2001/lecture_9/src/main/resources/application.properties) with this format | ||
| ```java | ||
| spring.datasource.driver-class-name=com.mysql.jdbc.Driver | ||
| spring.datasource.url=jdbc:mysql://localhost:3306/<your_database> | ||
| spring.datasource.username=<your_user_name> | ||
| spring.datasource.password=<your_password> | ||
| ``` | ||
|
|
||
| ### ⚙️ How to run the program | ||
| 1. Go to the `lecture_9` directory by using this command | ||
| ```bash | ||
| $ cd lecture_9 | ||
| ``` | ||
| 2. Make sure you have maven installed on your computer, use `mvn -v` to check the version. | ||
| 3. If you are using windows, you can run the program by using this command. | ||
| ```bash | ||
| $ ./run.bat | ||
| ``` | ||
| And if you are using Linux, you can run the program by using this command. | ||
| ```bash | ||
| $ chmod +x run.sh | ||
| $ ./run.sh | ||
| ``` | ||
|
|
||
| If all the instruction is well executed, the main-view will be something like this. | ||
|
|
||
|  | ||
|
|
||
| ### 📸 Screenshots | ||
| Here is some result of the views and APIs created based on simple MVC architecture. | ||
| <br> | ||
| #### Initial state | ||
|
|
||
| 1. **Get All Employees** | ||
|
|
||
|  | ||
| 2. **Add New Employee** | ||
|
|
||
|  | ||
| 3. **Edit Existing Employee Data** | ||
|
|
||
|  | ||
| 4. **Delete Employee** | ||
|
|
||
|  |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good for recreate repo and clear