Skip to content

Commit

Permalink
Merge pull request #70 from CS196Illinois/matching_algo
Browse files Browse the repository at this point in the history
Added route for match list
  • Loading branch information
adhi-thirumala authored Dec 8, 2024
2 parents 64534c5 + d80a2a4 commit 8223702
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.github.scribejava.core.model.OAuth2AccessToken;
import com.google.gson.JsonObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import java.util.concurrent.ExecutionException;

import com.google.gson.JsonParser;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -74,4 +78,16 @@ public ResponseEntity<ReturnValue> login(@RequestBody String code)
pgController.createAuthRow(discordId, tr.getAccessToken(), tr.getRefreshToken())));
}
}

@PostMapping(path = "/api/v1/matching")
public ResponseEntity<List<User>> matching(@RequestBody int minAge, @RequestBody int maxAge, @RequestBody String[] ranks, @RequestBody String[] roles) throws IOException {
Matching matcher = new Matching();
boolean success = matcher.filterMatches(minAge, maxAge, ranks, roles);
if (success) {
List<User> matches = matcher.getMatchList();
return ResponseEntity.ok(matches);
} else {
return ResponseEntity.ok(new ArrayList<User>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class Main {
*
* @param args Command line arguments.
*/

public static void main(String[] args) {
Dotenv dotenv = Dotenv.load();
System.setProperty(
"SPRING_DATASOURCE_URL", "jdbc:postgresql://" + dotenv.get("PGURL") + "/main");
System.setProperty("SPRING_DATASOURCE_USERNAME", dotenv.get("PGUSER"));
System.setProperty("SPRING_DATASOURCE_PASSWORD", dotenv.get("PGPASSWORD"));
SpringApplication.run(Main.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,43 @@ public boolean fillMatchList(){

public boolean filterMatches(int minAge, int maxAge, String[] ranks, String[] roles) {
List<User> newMatchList = new ArrayList<>();
fillMatchList();
matchList.forEach((user) -> {
if (user.getPrivateUser().getAge() >= minAge && user.getPrivateUser().getAge() <= maxAge) {
String[] userRoles = user.getPublicUser().getRoles();
boolean foundRole = false;
outerLoop:
for (int i = 0; i < userRoles.length; i++) {
String currentRole = userRoles[i];
for (int j = 0; j < roles.length; j++) {
if (currentRole.toLowerCase().equals(roles[j].toLowerCase())) {
foundRole = true;
break outerLoop;
boolean listFilled = fillMatchList();
if (listFilled) {
matchList.forEach((user) -> {
if (user.getPrivateUser().getAge() >= minAge && user.getPrivateUser().getAge() <= maxAge) {
String[] userRoles = user.getPublicUser().getRoles();
boolean foundRole = false;
outerLoop:
for (int i = 0; i < userRoles.length; i++) {
String currentRole = userRoles[i];
for (int j = 0; j < roles.length; j++) {
if (currentRole.toLowerCase().equals(roles[j].toLowerCase())) {
foundRole = true;
break outerLoop;
}
}
}
}
if (foundRole) {
boolean foundRank = false;
String userRole = user.getPublicUser().getRank();
for (int i = 0; i < ranks.length; i++) {
if (userRole.toLowerCase().equals(ranks[i].toLowerCase())) {
foundRank = true;
break;
if (foundRole) {
boolean foundRank = false;
String userRole = user.getPublicUser().getRank();
for (int i = 0; i < ranks.length; i++) {
if (userRole.toLowerCase().equals(ranks[i].toLowerCase())) {
foundRank = true;
break;
}
}
if (foundRank) {
newMatchList.add(user);
}
}
if (foundRank) {
newMatchList.add(user);
}
}
});
matchList = newMatchList;
if (matchList.size() > 0) {
return true;
} else {
return false;
}
});
matchList = newMatchList;
if (matchList.size() > 0) {
return true;
} else {
return false;
}
Expand Down

0 comments on commit 8223702

Please sign in to comment.