Skip to content

Commit

Permalink
[UPDATE] Piccolo refactor numero donazioni in donorCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
ZamponiMarco committed Jan 29, 2020
1 parent 6fb8a65 commit 25b4016
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.github.francisfire.anavis.services.DonorServices;
import com.github.francisfire.anavis.services.OfficeServices;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand Down Expand Up @@ -64,17 +65,7 @@ public Set<AuthCredentials> getAuthCredentials() {
@PreAuthorize("permitAll")
@PostMapping("/donor")
public boolean addDonorCredentials(@RequestBody UserAndDonor userAndDonor) {
int leftDonationsInYear = 4;
switch (userAndDonor.donor.getCategory()) {
case MAN:
case NONFERTILEWOMAN:
leftDonationsInYear = 4;
break;
case FERTILEWOMAN:
leftDonationsInYear = 2;
break;
}
userAndDonor.donor.setLeftDonationsInYear(leftDonationsInYear);
userAndDonor.donor.setLeftDonationsInYear(userAndDonor.donor.getCategory().getDonationPerYear());
userAndDonor.donor.setCanDonate(true);
return (donorServices.addDonor(userAndDonor.donor))
? authCredentialsServices.addCredentials(userAndDonor.authCredentials)
Expand Down Expand Up @@ -105,26 +96,18 @@ public boolean removeCredentials(@PathVariable("mail") String mail) {
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
static class UserAndDonor {
private Donor donor;
private AuthCredentials authCredentials;

public UserAndDonor(Donor donor, AuthCredentials authCredentials) {
this.donor = donor;
this.authCredentials = authCredentials;
}
}

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
static class UserAndOffice {
private Office office;
private AuthCredentials authCredentials;

public UserAndOffice(Office office, AuthCredentials authCredentials) {
this.office = office;
this.authCredentials = authCredentials;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -68,24 +69,19 @@ public void resetLeftDonationsInYear() {
public void setLastDonation(Date lastDonation) {
if (this.lastDonation == null || lastDonation.after(this.lastDonation)) {
this.lastDonation = lastDonation;
switch (category) {
case MAN:
case NONFERTILEWOMAN:
if (leftDonationsInYear == 4) {
firstDonationInYear = lastDonation;
}
break;
case FERTILEWOMAN:
if (leftDonationsInYear == 2) {
firstDonationInYear = lastDonation;
}
break;
if (leftDonationsInYear == category.getDonationPerYear()) {
firstDonationInYear = lastDonation;
}
leftDonationsInYear--;
}
}

@AllArgsConstructor
public enum DonorCategory {
MAN, FERTILEWOMAN, NONFERTILEWOMAN

MAN(4), FERTILEWOMAN(2), NONFERTILEWOMAN(4);

@Getter
private int donationPerYear;
}
}

0 comments on commit 25b4016

Please sign in to comment.