summaryrefslogtreecommitdiff
path: root/src/main/java/design/model/Golfer.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/design/model/Golfer.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java
index 6ea9d32..4fb521e 100644
--- a/src/main/java/design/model/Golfer.java
+++ b/src/main/java/design/model/Golfer.java
@@ -1,6 +1,7 @@
package design.model;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.ArrayList;
@@ -18,10 +19,14 @@ public class Golfer implements Originator {
private final List<Round> rounds;
private final List<Club> clubs; // Keep track of golfer's clubs
private int nextClubId;
+ private final List<Invite> invites;
+ private Team joinedTeam;
+
+
@JsonCreator
private Golfer(String username, int passwordHash, String fullName, List<Course> courses, List<Round> rounds,
- List<Club> clubs) {
+ List<Club> clubs, List<Invite> invites, Team joinedTeam) {
this.username = username;
this.passwordHash = passwordHash;
this.fullName = fullName;
@@ -29,6 +34,8 @@ public class Golfer implements Originator {
this.rounds = rounds;
this.clubs = clubs;
this.nextClubId = this.clubs.stream().mapToInt(Club::getId).max().orElse(0) + 1;
+ this.invites = invites;
+ this.joinedTeam = joinedTeam;
}
public Golfer(String fullName, String username, String password) {
@@ -39,6 +46,8 @@ public class Golfer implements Originator {
this.rounds = new ArrayList<>();
this.clubs = new ArrayList<>();
this.nextClubId = 1;
+ this.invites = new ArrayList<>();
+ this.joinedTeam = null;
}
public String getUsername() {
@@ -160,5 +169,21 @@ public class Golfer implements Originator {
this.clubs.addAll(gm.clubs);
this.nextClubId = gm.nextClubId;
- }
+ }
+
+ public boolean joinTeam(Team team){
+ for(Invite invite : invites){
+ if(invite.getTeam().equals(team)){
+ this.joinedTeam = team;
+ team.addMember(this);
+ invites.remove(invite);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Team getTeam(){
+ return joinedTeam;
+ }
}