Skip to content
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

New pull req #54

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions src/main/java/api/MongoGradeDataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public void leaveTeam() throws JSONException {
// TODO Task 3b: Implement this method
// Hint: Read the Grade API documentation for getMyTeam (link below) and refer to the above similar
// methods to help you write this code (copy-and-paste + edit as needed).

// https://www.postman.com/cloudy-astronaut-813156/csc207-grade-apis-demo/folder/isr2ymn/get-my-team
public Team getMyTeam() {
final OkHttpClient client = new OkHttpClient().newBuilder()
Expand All @@ -256,12 +257,26 @@ public Team getMyTeam() {
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.build();

final Response response;
final JSONObject responseBody;

// TODO Task 3b: Implement the logic to get the team information
// HINT: Look at the formTeam method to get an idea on how to parse the response
try {
final Response response = client.newCall(request).execute();
final JSONObject responseBody = new JSONObject(response.body().string());

return null;
if (responseBody.getInt(STATUS_CODE) == SUCCESS_CODE) {
final JSONObject team = responseBody.getJSONObject("team");
final JSONArray membersArray = team.getJSONArray("members");
final String[] members = new String[membersArray.length()];
for (int i = 0; i < membersArray.length(); i++) {
members[i] = membersArray.getString(i);
}
Team newteam = new Team(team.getString(NAME), members);
return newteam;
}
else {
throw new RuntimeException(responseBody.getString(MESSAGE));
}
}
catch (IOException | JSONException event) {
throw new RuntimeException(event);
}
}
}
9 changes: 8 additions & 1 deletion src/main/java/usecase/GetAverageGradeUseCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import entity.Grade;
import entity.Team;

import java.lang.reflect.Member;

/**
* GetAverageGradeUseCase class.
*/
Expand All @@ -25,7 +27,12 @@ public float getAverageGrade(String course) {
int count = 0;
// TODO Task 3b: Go to the MongoGradeDataBase class and implement getMyTeam.
final Team team = gradeDataBase.getMyTeam();
// Call the API to get all the grades for the course for all your team members
String[] members = team.getMembers();
for (String member : members) {
gradeDataBase.getGrade(member, course).getGrade();
sum += gradeDataBase.getGrade(member, course).getGrade();
count++;
}
// TODO Task 3a: Complete the logic of calculating the average course grade for
// your team members. Hint: the getGrades method might be useful.

Expand Down