-
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 #45 from Group-5/feat/User
Merge Feat/user into release/v1.0.0, completing the backend of the application
- Loading branch information
Showing
19 changed files
with
1,443 additions
and
319 deletions.
There are no files selected for viewing
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 |
|---|---|---|
| @@ -1,17 +1,10 @@ | ||
| package edu.group5.app; | ||
|
|
||
| import java.sql.Wrapper; | ||
| import java.util.HashMap; | ||
|
|
||
| import edu.group5.app.control.OrgAPIWrapper; | ||
| import tools.jackson.core.type.TypeReference; | ||
| import tools.jackson.databind.ObjectMapper; | ||
|
|
||
| /** | ||
| * Hello world! | ||
| */ | ||
| public class App { | ||
| public static void main(String[] args) throws InterruptedException { | ||
| Wrapper wrap = new Wrapper(); | ||
| System.out.println("Hello World!"); | ||
| } | ||
| } |
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
63 changes: 63 additions & 0 deletions
63
src/main/java/edu/group5/app/model/donation/DonationService.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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package edu.group5.app.model.donation; | ||
| import java.time.Instant; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.sql.Timestamp; | ||
| import edu.group5.app.model.organization.Organization; | ||
| import edu.group5.app.model.organization.OrganizationRepository; | ||
| import edu.group5.app.model.user.Customer; | ||
|
|
||
| /** | ||
| * DonationService class provides functionality for handling donations in the system. | ||
| * It interacts with the DonationRepository to manage donation records | ||
| * and the OrganizationRepository to validate organization information. | ||
| * The donate method allows a customer to make a donation to a specified organization, | ||
| * ensuring that the customer, organization, and donation amount are valid before processing the donation. | ||
| */ | ||
| public class DonationService { | ||
|
|
||
| private final DonationRepository donationRepository; | ||
| private final OrganizationRepository organizationRepository; | ||
|
|
||
| /** | ||
| * Constructor for DonationService. Initializes the service with the required repositories. | ||
| * @param donationRepository the repository for managing donation records | ||
| * @param organizationRepository the repository for managing organization information | ||
| * @throws IllegalArgumentException if either repository is null | ||
| */ | ||
| public DonationService(DonationRepository donationRepository, | ||
| OrganizationRepository organizationRepository) { | ||
| if (donationRepository == null) { | ||
| throw new IllegalArgumentException("DonationRepository cannot be null"); | ||
| } | ||
| if (organizationRepository == null) { | ||
| throw new IllegalArgumentException("OrganizationRepository cannot be null"); | ||
| } | ||
| this.donationRepository = donationRepository; | ||
| this.organizationRepository = organizationRepository; | ||
| } | ||
|
|
||
| /** | ||
| * Processes a donation from a customer to a specified organization with a given amount. | ||
| * Validates the customer, organization number, and donation amount before creating a donation record. | ||
| * @param customer the customer making the donation | ||
| * @param orgNumber the organization number to which the donation is made | ||
| * @param amount the amount of the donation | ||
| * @return true if the donation is successfully processed, false otherwise | ||
| */ | ||
| public boolean donate(Customer customer, int orgNumber, BigDecimal amount, String paymentMethod) { | ||
| if (customer == null || amount == null | ||
| || amount.compareTo(BigDecimal.ZERO) <= 0 || paymentMethod.isBlank()) { | ||
| return false; | ||
| } | ||
| Organization org = organizationRepository.findByOrgNumber(orgNumber); | ||
| if (org == null) { | ||
| return false; | ||
| } | ||
| Donation donation = | ||
| new Donation(donationRepository.getNextDonationId(), | ||
| customer.getUserId(), org.orgNumber(), amount, Timestamp.from(Instant.now()), paymentMethod); | ||
| donationRepository.addContent(donation); | ||
| return true; | ||
| } | ||
| } |
Oops, something went wrong.