Skip to content

Commit

Permalink
Added Docstrings and Removed Unnecessary Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawrence Tsai committed Dec 8, 2021
1 parent 81be383 commit 3c65cfd
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 40 deletions.
22 changes: 19 additions & 3 deletions app/src/main/java/com/amigo/control/DashboardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.ModelAndView;

/**
* Controller for dashboard
*/

@Controller
public class DashboardController {

@Autowired
UserPresenter presenter;

/**
*
* Shows the dashboard
*
*/
@GetMapping("/dashboard")
public ModelAndView showDashboard(@ModelAttribute User user) {
if (!user.isValid() && !presenter.hasUser()) {
Expand All @@ -31,7 +39,11 @@ public ModelAndView showDashboard(@ModelAttribute User user) {
presenter.populate(mav.getModel());
return mav;
}

/**
*
* Shows the "Matching" screen
*
*/
@GetMapping("/matching-screen")
public ModelAndView showMatchingScreen() {
ModelAndView mav = new ModelAndView("matching-screen");
Expand All @@ -54,7 +66,11 @@ public ModelAndView showMatchingScreen() {
}
return mav;
}

/**
*
* Shows the "Error" page
*
*/
@GetMapping("/*")
public String showError() {
return "error-page";
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/amigo/control/DatabaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
@RequestMapping(path="/data")
public class DatabaseController {
// @Autowired
// private UserRepository userRepository;


@Autowired
private CourseRepository courseRepository;

// /**
/**
// * Returns "saved" if a course is added (saved) to the database
// */

Expand All @@ -38,7 +38,9 @@ public class DatabaseController {
courseRepository.save(course);
return "Saved";
}

/**
// * Returns "saved" if a course is added (saved) to the database
// */
@GetMapping("/testaddcourse")
public @ResponseBody String testAddCourse() {
Course course = new Course("CSC101", "LEC0101", "TUT0101");
Expand Down
31 changes: 25 additions & 6 deletions app/src/main/java/com/amigo/control/RegistrationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/
@Controller
public class RegistrationController {

/**
* Validator that validates registration form.
*/
Expand All @@ -43,7 +42,11 @@ public class RegistrationController {

@Autowired
CourseRepository courseRepository;

/**
*
* Shows the "Welcome" page
*
*/
@GetMapping({"/", "/index"})
public String showWelcomePage(Model model) {
model.addAttribute("regForm", new RegistrationForm());
Expand All @@ -66,13 +69,21 @@ public String validateRegistration(Model model, @ModelAttribute("regForm") Regis
userBuilder.populate(form);
return "redirect:/register-courses";
}

/**
*
* Shows the "Register Course" page
*
*/
@GetMapping("/register-courses")
public String showRegisterCoursePage(Model model) {
model.addAttribute("courseForms", new CourseFormList());
return "register-courses";
}

/**
*
* Validate the courses
*
*/
@PostMapping("/register-courses")
public String validateCourses(Model model, @ModelAttribute CourseFormList courseForms, BindingResult result) {
for (CourseForm form : courseForms.getCourseList()) {
Expand All @@ -93,13 +104,21 @@ public String validateCourses(Model model, @ModelAttribute CourseFormList course
userBuilder.populate(courseForms);
return "redirect:/register-interests";
}

/**
*
* Shows the "Register Interest" page
*
*/
@GetMapping("/register-interests")
public String showRegisterInterestPage(Model model) {
model.addAttribute("interestForm", new InterestForm());
return "register-interests";
}

/**
*
* Validate the interests
*
*/
@PostMapping("/register-interests")
public String validateInterests(RedirectAttributes attributes, @ModelAttribute("interestForm") InterestForm interestForm) {
userBuilder.populate(interestForm);
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/amigo/course/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public Course() {}
public Course(String courseCode) {
this(courseCode, "", "");
}
/**
* Creates a course with courseCode, lecture section, and tutorial section
*/

public Course(String courseCode, String lecture, String tutorial) {
this.courseCode = courseCode;
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/amigo/form/CourseFormList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ public CourseFormList() {
courseList.add(new CourseForm());
courseList.add(new CourseForm());
}

/**
* Returns the courselist
*/
public List<CourseForm> getCourseList() {
return courseList;
}

/**
* Creates a courselist
*/
public void setCourseList(List<CourseForm> courseList) {
this.courseList = courseList;
}
Expand Down
25 changes: 24 additions & 1 deletion app/src/main/java/com/amigo/form/InterestForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,51 @@ public class InterestForm {
private String sports;
private String recreational;
private String hobbies;

/**
* Returns the music interest
*/
public String getMusic() {
return music;
}
/**
* Creates a music interest
*/
public void setMusic(String music) {
this.music = music;
}
/**
* Returns the sport interest
*/
public String getSports() {
return sports;
}
/**
* Creates a sport interest
*/
public void setSports(String sports) {
this.sports = sports;
}
/**
* Returns the recreational interest
*/
public String getRecreational() {
return recreational;
}
/**
* Creates a recreational interest
*/
public void setRecreational(String recreational) {
this.recreational = recreational;
}
/**
* Returns the hobby interest
*/
public String getHobbies() {
return hobbies;
}
/**
* Creates a hobby interest
*/
public void setHobbies(String hobbies) {
this.hobbies = hobbies;
}
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/amigo/match/DemoMatching.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
import com.amigo.user.UserFactory;

public class DemoMatching {

/**
* Performs the matching algorthm and returns the matches
*/
public static Map<String, List<Match>> doMatching(User user) {
Matcher matcher = new Matcher();
List<User> users = createDemoUsers();
users.add(user);
return matcher.match(users);
}

/**
* Creates the demo users
*/
private static List<User> createDemoUsers() {
ArrayList<User> users = new ArrayList<User>();
ProfileFactory profileFactory = new ProfileFactory();
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/amigo/match/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public Map<String, List<Match>> match(List<User> users) {
* {@code users}. Each possible pair of users is evaluated by a metric function.
*/
private Map<String, List<Match>> matchPotential(List<User> users) {
// TODO: Add Wildcard Matches
int numUsers = users.size();

// Creates a map of potential matches
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/amigo/match/MatcherBeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public Map<String, List<Match>> match(List<User> users) {
*/

private Map<String, List<Match>> matchPotential(List<User> users) {
// TODO: Add Wildcard Matches
int numUsers = users.size();

// Creates a map of potential matches
Expand Down Expand Up @@ -204,6 +203,7 @@ static boolean differ_by_one(String word1, String word2) {
}
return true;
}

// Check if the words are alternates of each other if the additional letter is removed, at every index
private static boolean check_added_character(String word1, String word2) {
if(word2.length() - word1.length() == 1){
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/java/com/amigo/present/UserPresenter.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.amigo.present;

import java.util.Map;

import com.amigo.user.User;

import org.springframework.stereotype.Controller;

/**
Expand All @@ -27,15 +25,27 @@ public class UserPresenter {
public boolean hasUser() {
return user != null;
}

/**
* Returns the user
*/
public User getUser() {
return user;
}

/**
* Creates a user
*/
public void setUser(User user) {
this.user = user;
}

/**
* Returns the suffix
*/
public String getSuffix() {
return suffix;
}
/**
* Creates a suffix
*/
public void setSuffix(String suffix) {
this.suffix = suffix;
}
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/amigo/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.List;
// import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

Expand All @@ -13,8 +12,6 @@
*/
@Entity
public class User {
// TODO: Add a flag for report-made binary int-created
// TODO: Add a checkbox for Wildcard Matching-created
private Profile profile;
@Id
// @Column(name = "id")
Expand Down Expand Up @@ -130,7 +127,9 @@ public String toStringCurrentMatches() {
}
return namesCurrentMatches.toString();
}

/**
* Creates a password
*/
public void setPassword(String password) {
this.password = password;
}
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/com/amigo/user/UserBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*/
@Service
public class UserBuilder {

// TODO: assign ID to user

private User user;
private Profile profile;

Expand All @@ -39,7 +38,9 @@ public void populate(CourseFormList form) {
populateCourse(each);
}
}

/**
* Populates the {@code Profile} object with attributes from the course form.
*/
private void populateCourse(CourseForm form) {
Course c = new Course(form.getCourseCode(), form.getLectureCode(), form.getTutorialCode());
profile.addCourses(c);
Expand All @@ -54,8 +55,10 @@ public void populate(InterestForm form) {
profile.setMusInterest(form.getMusic());
profile.setSportInterest(form.getSports());
}


/**
* Creates a user
*/
public User createUser() {
user.setProfile(this.profile);
String id = this.profile.getName().split(" ")[0].toLowerCase() + (int) (1000 * Math.random() + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class RegistrationValidator implements Validator {
public boolean supports(Class<?> clazz) {
return RegistrationForm.class.equals(clazz);
}

/**
* Validates the registration form
*/
@Override
public void validate(Object target, Errors errors) {
RegistrationForm form = (RegistrationForm) target;
Expand Down
Loading

0 comments on commit 3c65cfd

Please sign in to comment.