forked from CSC207-UofT/course-project-super-turtle-hackers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CSC207-UofT#45 from CSC207-UofT/tony-dashboard
Hooking up frontend dashboard and matching screen with backend
- Loading branch information
Showing
19 changed files
with
1,035 additions
and
94 deletions.
There are no files selected for viewing
53 changes: 51 additions & 2 deletions
53
app/src/main/java/com/amigo/control/DashboardController.java
This file contains 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,13 +1,62 @@ | ||
package com.amigo.control; | ||
|
||
import java.util.List; | ||
|
||
import com.amigo.match.DemoMatching; | ||
import com.amigo.match.Match; | ||
import com.amigo.present.UserPresenter; | ||
import com.amigo.user.User; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
@Controller | ||
public class DashboardController { | ||
|
||
@Autowired | ||
UserPresenter presenter; | ||
|
||
@GetMapping("/dashboard") | ||
public String showDashboard() { | ||
return "dashboard"; | ||
public ModelAndView showDashboard(@ModelAttribute User user) { | ||
if (!user.isValid() && !presenter.hasUser()) { | ||
return new ModelAndView("error-page"); | ||
} | ||
if (user.isValid()) { | ||
presenter.setUser(user); | ||
} | ||
ModelAndView mav = new ModelAndView("dashboard"); | ||
presenter.populate(mav.getModel()); | ||
return mav; | ||
} | ||
|
||
@GetMapping("/matching-screen") | ||
public ModelAndView showMatchingScreen() { | ||
ModelAndView mav = new ModelAndView("matching-screen"); | ||
User currentUser = presenter.getUser(); | ||
var allMatches = DemoMatching.doMatching(currentUser); | ||
List<Match> matchList = allMatches.get(currentUser.getId()); | ||
currentUser.setCurrentMatches(matchList); | ||
|
||
int counter = 0; | ||
for (var each : currentUser.getCurrentMatches()) { | ||
UserPresenter p = new UserPresenter(); | ||
if (each.getUser1() == currentUser){ | ||
p.setUser(each.getUser2()); | ||
} | ||
else { | ||
p.setUser(each.getUser1()); | ||
} | ||
p.setSuffix(String.valueOf(++counter)); | ||
p.populate(mav.getModel()); | ||
} | ||
return mav; | ||
} | ||
|
||
@GetMapping("/*") | ||
public String showError() { | ||
return "error-page"; | ||
} | ||
} |
This file contains 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 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 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 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,48 @@ | ||
package com.amigo.match; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.amigo.course.CourseSetFactory; | ||
import com.amigo.user.ProfileFactory; | ||
import com.amigo.user.User; | ||
import com.amigo.user.UserFactory; | ||
|
||
public class DemoMatching { | ||
|
||
public static Map<String, List<Match>> doMatching(User user) { | ||
Matcher matcher = new Matcher(); | ||
List<User> users = createDemoUsers(); | ||
users.add(user); | ||
return matcher.match(users); | ||
} | ||
|
||
private static List<User> createDemoUsers() { | ||
ArrayList<User> users = new ArrayList<User>(); | ||
ProfileFactory profileFactory = new ProfileFactory(); | ||
CourseSetFactory courseSetFactory = new CourseSetFactory(); | ||
UserFactory userFactory = new UserFactory(); | ||
var p1 = profileFactory.createProfile("Toni", 2, "Linguistics", courseSetFactory.createCourseSet("CSC207,LIN102,LIN101"), | ||
"", "Chess", "Ice Skating", "Taylor Swift", "Eat Manpuku"); | ||
var p2 = profileFactory.createProfile("Ikshat", 2, "Computer Science", courseSetFactory.createCourseSet("CSC207,CSC301,CSC209"), | ||
"", "Sleep", "Rock Climbing", "Zachary Knowles", "Play Video Games"); | ||
var p3 = profileFactory.createProfile("Rue", 2, "Computer Science", courseSetFactory.createCourseSet("CSC207,CSC236,CSC209"), | ||
"", "Poetry", "Ew Sports", "BTS", "Read"); | ||
var p4 = profileFactory.createProfile("Adrian", 2, "Gender Studies", courseSetFactory.createCourseSet("ECO101,CSC207,MAT237"), | ||
"", "Economics", "Ski", "Illenium", "Breathe"); | ||
var p5 = profileFactory.createProfile("Dien", 2, "Computational Biology and Bioinformatics", courseSetFactory.createCourseSet("CSC207,CSC236,BIO101"), | ||
"", "Makeup", "Dance", "Blackpink", "Makeup Even More"); | ||
var p6 = profileFactory.createProfile("Lawrence", 2, "Chemistry", courseSetFactory.createCourseSet("CHM101,CHM102,CSC207,MAT237"), | ||
"", "Crypto", "Run", "Pop", "Lift Weights"); | ||
|
||
users.add(userFactory.createUser(p1)); | ||
users.add(userFactory.createUser(p2)); | ||
users.add(userFactory.createUser(p3)); | ||
users.add(userFactory.createUser(p4)); | ||
users.add(userFactory.createUser(p5)); | ||
users.add(userFactory.createUser(p6)); | ||
|
||
return users; | ||
} | ||
} |
This file contains 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,57 @@ | ||
package com.amigo.present; | ||
|
||
import java.util.Map; | ||
|
||
import com.amigo.user.User; | ||
|
||
import org.springframework.stereotype.Controller; | ||
|
||
/** | ||
* A presenter that populates the model for dashboard page given a specific | ||
* user. | ||
*/ | ||
@Controller | ||
public class UserPresenter { | ||
|
||
private User user; | ||
|
||
/** | ||
* The suffix used to distinguish each attribute set. | ||
*/ | ||
private String suffix = ""; | ||
|
||
/** | ||
* Returns whether there is currently a {@code User} object associated with this | ||
* presenter. | ||
*/ | ||
public boolean hasUser() { | ||
return user != null; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
public void setSuffix(String suffix) { | ||
this.suffix = suffix; | ||
} | ||
|
||
/** | ||
* Populates the ModelMap with attributes taken from the user. | ||
*/ | ||
public void populate(Map<String, Object> map) { | ||
if (user == null) { | ||
throw new IllegalStateException("User not set with setUser()"); | ||
} | ||
map.put("name" + (suffix.equals("") ? "" : "_" + suffix), user.getProfile().getName()); | ||
map.put("hobbies" + (suffix.equals("") ? "" : "_" + suffix), user.getProfile().getHobbies()); | ||
map.put("sports" + (suffix.equals("") ? "" : "_" + suffix), user.getProfile().getSportInterest()); | ||
map.put("music" + (suffix.equals("") ? "" : "_" + suffix), user.getProfile().getMusInterest()); | ||
map.put("recreational" + (suffix.equals("") ? "" : "_" + suffix), user.getProfile().getRecInterest()); | ||
map.put("courses" + (suffix.equals("") ? "" : "_" + suffix), user.getProfile().getCoursesAsString()); | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.