From c0e981ed66f1c0bff38710d71f9d9cd38af08b47 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Wed, 8 May 2024 22:26:46 +0300 Subject: [PATCH 01/11] working on added basic boilerplate --- services/contracts/pom.xml | 34 +++++++++++++++++-- .../commands/EvaluateMilestoneCommand.java | 18 ++++++++++ .../commands/GetContractCommand.java | 20 +++++++++++ .../commands/GetMilestoneCommand.java | 22 ++++++++++++ .../GetPendingTerminationsCommand.java | 24 +++++++++++++ .../commands/ProgressMilestoneCommand.java | 20 +++++++++++ .../shared/commands/contracts/Milestone.java | 2 +- .../requests/GetContractRequest.java | 15 ++++++++ .../requests/GetMilestoneRequest.java | 16 +++++++++ .../GetPendingTerminationsRequest.java | 15 ++++++++ ...se.java => EvaluateMilestoneResponse.java} | 2 +- .../responses/GetContractResponse.java | 26 ++++++++++++++ .../responses/GetMilestoneResponse.java | 14 ++++++++ .../GetPendingTerminationsResponse.java | 24 +++++++++++++ 14 files changed, 247 insertions(+), 5 deletions(-) create mode 100644 services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java create mode 100644 services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java create mode 100644 services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java create mode 100644 services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java create mode 100644 services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java create mode 100644 shared/src/main/java/com/workup/shared/commands/contracts/requests/GetContractRequest.java create mode 100644 shared/src/main/java/com/workup/shared/commands/contracts/requests/GetMilestoneRequest.java create mode 100644 shared/src/main/java/com/workup/shared/commands/contracts/requests/GetPendingTerminationsRequest.java rename shared/src/main/java/com/workup/shared/commands/contracts/responses/{EvaluatedMilestoneResponse.java => EvaluateMilestoneResponse.java} (80%) create mode 100644 shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java create mode 100644 shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java create mode 100644 shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java diff --git a/services/contracts/pom.xml b/services/contracts/pom.xml index a377bb9a..0ca96710 100644 --- a/services/contracts/pom.xml +++ b/services/contracts/pom.xml @@ -20,6 +20,10 @@ 21 + + org.springframework.boot + spring-boot-starter-amqp + org.springframework.boot spring-boot-starter-web @@ -36,17 +40,41 @@ org.springframework.boot - spring-boot-starter-data-cassandra + spring-boot-testcontainers + test - org.springframework.boot - spring-boot-starter-amqp + org.testcontainers + junit-jupiter + 1.19.7 + test + + + org.testcontainers + cassandra + 1.19.7 + test + + + org.testcontainers + rabbitmq + 1.19.7 + test + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.16.0 org.springframework.amqp spring-rabbit-test test + + org.springframework.boot + spring-boot-starter-data-cassandra + org.projectlombok lombok diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java new file mode 100644 index 00000000..92959fa5 --- /dev/null +++ b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java @@ -0,0 +1,18 @@ +package com.workup.contracts.commands; + +import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; + +import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; + +public class EvaluateMilestoneCommand + extends ContractCommand { + + @Override + public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. + + return null; + + } +} diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java new file mode 100644 index 00000000..50198656 --- /dev/null +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java @@ -0,0 +1,20 @@ +package com.workup.contracts.commands; + +import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; + +import com.workup.shared.commands.contracts.requests.GetContractRequest; +import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; +import com.workup.shared.commands.contracts.responses.GetContractResponse; + +public class GetContractCommand + extends ContractCommand { + + @Override + public GetContractResponse Run(GetContractRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. + + return null; + + } +} diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java new file mode 100644 index 00000000..3308c0ce --- /dev/null +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java @@ -0,0 +1,22 @@ +package com.workup.contracts.commands; + +import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; + +import com.workup.shared.commands.contracts.requests.GetContractRequest; +import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; +import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; +import com.workup.shared.commands.contracts.responses.GetContractResponse; +import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; + +public class GetMilestoneCommand + extends ContractCommand { + + @Override + public GetMilestoneResponse Run(GetMilestoneRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. + + return null; + + } +} diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java new file mode 100644 index 00000000..2988202e --- /dev/null +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java @@ -0,0 +1,24 @@ +package com.workup.contracts.commands; + +import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; + +import com.workup.shared.commands.contracts.requests.GetContractRequest; +import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; +import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest; +import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; +import com.workup.shared.commands.contracts.responses.GetContractResponse; +import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; +import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse; + +public class GetPendingTerminationsCommand + extends ContractCommand { + + @Override + public GetPendingTerminationsResponse Run(GetPendingTerminationsRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. + + return null; + + } +} diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java new file mode 100644 index 00000000..ab886943 --- /dev/null +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java @@ -0,0 +1,20 @@ +package com.workup.contracts.commands; + +import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; + +import com.workup.shared.commands.contracts.requests.ProgressMilestoneRequest; +import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; +import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; + +public class ProgressMilestoneCommand + extends ContractCommand { + + @Override + public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. + + return null; + + } +} diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/Milestone.java b/shared/src/main/java/com/workup/shared/commands/contracts/Milestone.java index 308163c5..159dac47 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/Milestone.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/Milestone.java @@ -11,7 +11,7 @@ @Jacksonized public class Milestone { - private final String milestoneId; // Not Needed when initiating contract, make it null + private final String milestoneId; // Not needed when initiating contract, make it null private final String contractId; // Not needed when initiating contract, make it null private final String description; diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetContractRequest.java b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetContractRequest.java new file mode 100644 index 00000000..5fbb7726 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetContractRequest.java @@ -0,0 +1,15 @@ +package com.workup.shared.commands.contracts.requests; + +import com.workup.shared.commands.CommandRequest; +import com.workup.shared.enums.contracts.TerminationRequestStatus; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +// PURPOSE : To fulfill the need for the read of CRUD for our contract repository +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetContractRequest extends CommandRequest { + private final String contractId; +} diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetMilestoneRequest.java b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetMilestoneRequest.java new file mode 100644 index 00000000..b9dc48b6 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetMilestoneRequest.java @@ -0,0 +1,16 @@ +package com.workup.shared.commands.contracts.requests; + +import com.workup.shared.commands.CommandRequest; +import com.workup.shared.enums.contracts.TerminationRequestStatus; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +// PURPOSE : To fulfill the need for the read of CRUD for our milestone repository +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetMilestoneRequest extends CommandRequest { + + private final String milestoneId; +} diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetPendingTerminationsRequest.java b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetPendingTerminationsRequest.java new file mode 100644 index 00000000..e5ee968a --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetPendingTerminationsRequest.java @@ -0,0 +1,15 @@ +package com.workup.shared.commands.contracts.requests; + +import com.workup.shared.commands.CommandRequest; +import com.workup.shared.enums.contracts.TerminationRequestStatus; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +// PURPOSE : To fulfill the need for the read of CRUD for our terminations repository +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetPendingTerminationsRequest extends CommandRequest { + private final String contractId; +} diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/EvaluatedMilestoneResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/EvaluateMilestoneResponse.java similarity index 80% rename from shared/src/main/java/com/workup/shared/commands/contracts/responses/EvaluatedMilestoneResponse.java rename to shared/src/main/java/com/workup/shared/commands/contracts/responses/EvaluateMilestoneResponse.java index c119e14f..c1319d9d 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/responses/EvaluatedMilestoneResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/EvaluateMilestoneResponse.java @@ -8,4 +8,4 @@ @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized -public class EvaluatedMilestoneResponse extends CommandResponse {} +public class EvaluateMilestoneResponse extends CommandResponse {} diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java new file mode 100644 index 00000000..3165d795 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java @@ -0,0 +1,26 @@ +package com.workup.shared.commands.contracts.responses; + +import com.workup.shared.commands.CommandResponse; +import com.workup.shared.enums.contracts.ContractState; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; +import java.util.UUID; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetContractResponse extends CommandResponse { + private final String contractId; + private String jobTitle; + private String jobId; + private String proposalId; + private String freelancerId; + private String clientId; + private List milestonesIds; + private ContractState status; + +} diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java new file mode 100644 index 00000000..241c9cbb --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java @@ -0,0 +1,14 @@ +package com.workup.shared.commands.contracts.responses; + +import com.workup.shared.commands.CommandResponse; +import com.workup.shared.commands.contracts.Milestone; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetMilestoneResponse extends CommandResponse { + private final Milestone milestone; +} diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java new file mode 100644 index 00000000..f22819d3 --- /dev/null +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java @@ -0,0 +1,24 @@ +package com.workup.shared.commands.contracts.responses; + +import com.workup.shared.commands.CommandResponse; +import com.workup.shared.commands.contracts.Milestone; +import com.workup.shared.enums.contracts.TerminationRequestStatus; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +import java.util.UUID; + +@Getter +@SuperBuilder(setterPrefix = "with") +@Jacksonized +public class GetPendingTerminationsResponse extends CommandResponse { + private String requestId; + + private String contractId; + private String requesterId; + private String reason; + + private TerminationRequestStatus status; +} From 1c7ea22a10523acc6d4e559683188d60c37e52f4 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Wed, 8 May 2024 22:27:14 +0300 Subject: [PATCH 02/11] formatting changes --- .../commands/EvaluateMilestoneCommand.java | 16 ++++++-------- .../commands/GetContractCommand.java | 18 ++++++--------- .../commands/GetMilestoneCommand.java | 19 ++++++---------- .../GetPendingTerminationsCommand.java | 21 ++++++------------ .../commands/ProgressMilestoneCommand.java | 17 ++++++-------- .../requests/GetContractRequest.java | 3 +-- .../requests/GetMilestoneRequest.java | 3 +-- .../GetPendingTerminationsRequest.java | 3 +-- .../responses/GetContractResponse.java | 22 ++++++++----------- .../responses/GetMilestoneResponse.java | 2 +- .../GetPendingTerminationsResponse.java | 14 +++++------- 11 files changed, 53 insertions(+), 85 deletions(-) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java index 92959fa5..488b0a7d 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java @@ -1,18 +1,16 @@ package com.workup.contracts.commands; import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; - import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; public class EvaluateMilestoneCommand - extends ContractCommand { - - @Override - public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + extends ContractCommand { - return null; + @Override + public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. - } + return null; + } } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java index 50198656..cd7aacd3 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java @@ -1,20 +1,16 @@ package com.workup.contracts.commands; -import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; import com.workup.shared.commands.contracts.requests.GetContractRequest; -import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; import com.workup.shared.commands.contracts.responses.GetContractResponse; -public class GetContractCommand - extends ContractCommand { +public class GetContractCommand extends ContractCommand { - @Override - public GetContractResponse Run(GetContractRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + @Override + public GetContractResponse Run(GetContractRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. - return null; - - } + return null; + } } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java index 3308c0ce..8d875cc3 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java @@ -1,22 +1,17 @@ package com.workup.contracts.commands; -import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; -import com.workup.shared.commands.contracts.requests.GetContractRequest; import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; -import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; -import com.workup.shared.commands.contracts.responses.GetContractResponse; import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; public class GetMilestoneCommand - extends ContractCommand { + extends ContractCommand { - @Override - public GetMilestoneResponse Run(GetMilestoneRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + @Override + public GetMilestoneResponse Run(GetMilestoneRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. - return null; - - } + return null; + } } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java index 2988202e..57f6f1fe 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java @@ -1,24 +1,17 @@ package com.workup.contracts.commands; -import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; -import com.workup.shared.commands.contracts.requests.GetContractRequest; -import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest; -import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; -import com.workup.shared.commands.contracts.responses.GetContractResponse; -import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse; public class GetPendingTerminationsCommand - extends ContractCommand { + extends ContractCommand { - @Override - public GetPendingTerminationsResponse Run(GetPendingTerminationsRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + @Override + public GetPendingTerminationsResponse Run(GetPendingTerminationsRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. - return null; - - } + return null; + } } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java index ab886943..7b3591fc 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java @@ -1,20 +1,17 @@ package com.workup.contracts.commands; -import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; import com.workup.shared.commands.contracts.requests.ProgressMilestoneRequest; -import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; public class ProgressMilestoneCommand - extends ContractCommand { + extends ContractCommand { - @Override - public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + @Override + public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { + // First we will get the milestones and add them to the database first, + // This will allow us to have their IDs for when we insert the contract. - return null; - - } + return null; + } } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetContractRequest.java b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetContractRequest.java index 5fbb7726..e9ba104e 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetContractRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetContractRequest.java @@ -1,7 +1,6 @@ package com.workup.shared.commands.contracts.requests; import com.workup.shared.commands.CommandRequest; -import com.workup.shared.enums.contracts.TerminationRequestStatus; import lombok.Getter; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; @@ -11,5 +10,5 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class GetContractRequest extends CommandRequest { - private final String contractId; + private final String contractId; } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetMilestoneRequest.java b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetMilestoneRequest.java index b9dc48b6..6d87533f 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetMilestoneRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetMilestoneRequest.java @@ -1,7 +1,6 @@ package com.workup.shared.commands.contracts.requests; import com.workup.shared.commands.CommandRequest; -import com.workup.shared.enums.contracts.TerminationRequestStatus; import lombok.Getter; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; @@ -12,5 +11,5 @@ @Jacksonized public class GetMilestoneRequest extends CommandRequest { - private final String milestoneId; + private final String milestoneId; } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetPendingTerminationsRequest.java b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetPendingTerminationsRequest.java index e5ee968a..c550287c 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetPendingTerminationsRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/requests/GetPendingTerminationsRequest.java @@ -1,7 +1,6 @@ package com.workup.shared.commands.contracts.requests; import com.workup.shared.commands.CommandRequest; -import com.workup.shared.enums.contracts.TerminationRequestStatus; import lombok.Getter; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; @@ -11,5 +10,5 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class GetPendingTerminationsRequest extends CommandRequest { - private final String contractId; + private final String contractId; } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java index 3165d795..cafbb1c8 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java @@ -2,25 +2,21 @@ import com.workup.shared.commands.CommandResponse; import com.workup.shared.enums.contracts.ContractState; +import java.util.List; import lombok.Getter; -import lombok.Setter; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; -import java.util.List; -import java.util.UUID; - @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized public class GetContractResponse extends CommandResponse { - private final String contractId; - private String jobTitle; - private String jobId; - private String proposalId; - private String freelancerId; - private String clientId; - private List milestonesIds; - private ContractState status; - + private final String contractId; + private String jobTitle; + private String jobId; + private String proposalId; + private String freelancerId; + private String clientId; + private List milestonesIds; + private ContractState status; } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java index 241c9cbb..9dd60802 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java @@ -10,5 +10,5 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class GetMilestoneResponse extends CommandResponse { - private final Milestone milestone; + private final Milestone milestone; } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java index f22819d3..4a028848 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java @@ -1,24 +1,20 @@ package com.workup.shared.commands.contracts.responses; import com.workup.shared.commands.CommandResponse; -import com.workup.shared.commands.contracts.Milestone; import com.workup.shared.enums.contracts.TerminationRequestStatus; import lombok.Getter; -import lombok.Setter; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; -import java.util.UUID; - @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized public class GetPendingTerminationsResponse extends CommandResponse { - private String requestId; + private String requestId; - private String contractId; - private String requesterId; - private String reason; + private String contractId; + private String requesterId; + private String reason; - private TerminationRequestStatus status; + private TerminationRequestStatus status; } From f09a48d35e1286e7ed4f1e948d516a9594376530 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Thu, 9 May 2024 22:45:04 +0300 Subject: [PATCH 03/11] working on progress milestone command --- .../contracts/commands/ContractCommand.java | 3 + .../commands/ContractCommandMap.java | 2 + .../commands/ProgressMilestoneCommand.java | 57 +++++++++++++++++-- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommand.java index b2fef076..cc41552d 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommand.java @@ -7,10 +7,13 @@ import com.workup.shared.commands.CommandRequest; import com.workup.shared.commands.CommandResponse; import lombok.Setter; +import org.springframework.amqp.core.AmqpTemplate; public abstract class ContractCommand implements Command { + @Setter AmqpTemplate rabbitTemplate; + @Setter ContractRepository contractRepository; @Setter ContractMilestoneRepository contractMilestoneRepository; diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommandMap.java b/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommandMap.java index acacec8e..9177f815 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommandMap.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommandMap.java @@ -6,6 +6,7 @@ import com.workup.shared.commands.CommandMap; import com.workup.shared.commands.CommandRequest; import com.workup.shared.commands.CommandResponse; +import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -13,6 +14,7 @@ public class ContractCommandMap extends CommandMap> { + @Autowired AmqpTemplate rabbitTemplate; @Autowired ContractRepository contractRepository; @Autowired ContractMilestoneRepository contractMilestoneRepository; diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java index 7b3591fc..a889205b 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java @@ -1,17 +1,66 @@ package com.workup.contracts.commands; - +import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.ProgressMilestoneRequest; import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.shared.enums.contracts.MilestoneState; +import java.util.Optional; +import java.util.UUID; public class ProgressMilestoneCommand extends ContractCommand { + private ProgressMilestoneResponse isValid(ProgressMilestoneRequest request) { + Optional milestone = + contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); + if (milestone.isEmpty()) + return ProgressMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.BAD_REQUEST) + .withErrorMessage("Milestone is not found") + .build(); + if (milestone.get().getStatus() != MilestoneState.OPEN + && milestone.get().getStatus() != MilestoneState.IN_PROGRESS) + return ProgressMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.BAD_REQUEST) + .withErrorMessage("Milestone cannot be progressed through this command") + .build(); + return null; + } + @Override public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + ProgressMilestoneResponse checkerResponse = isValid(request); + if (checkerResponse != null) return checkerResponse; - return null; + Optional milestone = + contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); + ContractMilestone updatedMilestone = milestone.get(); + if (updatedMilestone.getStatus() == MilestoneState.OPEN) { + updatedMilestone.setStatus(MilestoneState.IN_PROGRESS); + } else if (updatedMilestone.getStatus() == MilestoneState.IN_PROGRESS) { + updatedMilestone.setStatus(MilestoneState.IN_REVIEW); + // Send to payments here + + // get required data from milestone + milestoneContract = + contractRepository.findById(UUID.fromString(updatedMilestone.getContractId())); + } + + try { + contractMilestoneRepository.save(updatedMilestone); + System.out.println(" [x] Milestone Progressed " + updatedMilestone); + return ProgressMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.OK) + .withErrorMessage("") + .build(); + + } catch (Exception e) { + e.printStackTrace(); + return ProgressMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) + .withErrorMessage(e.getMessage()) + .build(); + } } } From 1233eac6dde784d07fde9dafcc6519f1ac56707e Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Thu, 9 May 2024 22:46:49 +0300 Subject: [PATCH 04/11] working on progress milestone command --- .../com/workup/contracts/commands/GetContractCommand.java | 1 - .../com/workup/contracts/commands/GetMilestoneCommand.java | 1 - .../contracts/commands/GetPendingTerminationsCommand.java | 1 - .../workup/contracts/commands/ProgressMilestoneCommand.java | 4 ++-- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java index cd7aacd3..e981356e 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java @@ -1,6 +1,5 @@ package com.workup.contracts.commands; - import com.workup.shared.commands.contracts.requests.GetContractRequest; import com.workup.shared.commands.contracts.responses.GetContractResponse; diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java index 8d875cc3..1669a265 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java @@ -1,6 +1,5 @@ package com.workup.contracts.commands; - import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java index 57f6f1fe..cadb7a73 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java @@ -1,6 +1,5 @@ package com.workup.contracts.commands; - import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest; import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse; diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java index a889205b..40cccb03 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java @@ -43,8 +43,8 @@ public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { // Send to payments here // get required data from milestone - milestoneContract = - contractRepository.findById(UUID.fromString(updatedMilestone.getContractId())); + // milestoneContract = + // contractRepository.findById(UUID.fromString(updatedMilestone.getContractId())); } try { From d05b30ea4b421506058779c571b1dd1f5c3aec36 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Fri, 10 May 2024 01:56:49 +0300 Subject: [PATCH 05/11] worked on implementing remaining contracts commands, added caching --- services/contracts/pom.xml | 16 ++++ .../contracts/ContractsApplication.java | 4 + .../contracts/commands/ContractCommand.java | 3 + .../commands/ContractCommandMap.java | 9 ++- .../commands/EvaluateMilestoneCommand.java | 77 ++++++++++++++++++- .../commands/GetContractCommand.java | 47 ++++++++++- .../commands/GetMilestoneCommand.java | 47 ++++++++++- .../GetPendingTerminationsCommand.java | 46 ++++++++++- .../commands/ProgressMilestoneCommand.java | 38 ++++----- .../contracts/logger/ContractsLogger.java | 9 +++ .../TerminationRequestRepository.java | 6 ++ .../responses/GetContractResponse.java | 14 ++-- .../responses/GetMilestoneResponse.java | 14 +++- .../GetPendingTerminationsResponse.java | 10 +-- 14 files changed, 294 insertions(+), 46 deletions(-) create mode 100644 services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java diff --git a/services/contracts/pom.xml b/services/contracts/pom.xml index 0ca96710..2a000b1c 100644 --- a/services/contracts/pom.xml +++ b/services/contracts/pom.xml @@ -75,6 +75,22 @@ org.springframework.boot spring-boot-starter-data-cassandra + + org.springframework.boot + spring-boot-starter-data-redis + 3.1.2 + + + com.redis.testcontainers + testcontainers-redis-junit-jupiter + 1.4.6 + test + + + redis.clients + jedis + 3.7.0 + org.projectlombok lombok diff --git a/services/contracts/src/main/java/com/workup/contracts/ContractsApplication.java b/services/contracts/src/main/java/com/workup/contracts/ContractsApplication.java index f4d5087c..fac6783f 100644 --- a/services/contracts/src/main/java/com/workup/contracts/ContractsApplication.java +++ b/services/contracts/src/main/java/com/workup/contracts/ContractsApplication.java @@ -12,9 +12,13 @@ import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; @SpringBootApplication +@ComponentScan(basePackages = "com.workup") +@EnableCaching public class ContractsApplication { public static void main(String[] args) { diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommand.java index cc41552d..998734e3 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommand.java @@ -6,6 +6,7 @@ import com.workup.shared.commands.Command; import com.workup.shared.commands.CommandRequest; import com.workup.shared.commands.CommandResponse; +import com.workup.shared.redis.RedisService; import lombok.Setter; import org.springframework.amqp.core.AmqpTemplate; @@ -19,4 +20,6 @@ public abstract class ContractCommand> { - @Autowired AmqpTemplate rabbitTemplate; + @Autowired ContractRepository contractRepository; @Autowired ContractMilestoneRepository contractMilestoneRepository; @Autowired TerminationRequestRepository terminationRequestRepository; + @Autowired AmqpTemplate rabbitTemplate; + + @Autowired RedisService redisService; + public void registerCommands() { commands.put("InitiateContract", InitiateContractCommand.class); commands.put("RequestContractTermination", RequestContractTerminationCommand.class); @@ -36,5 +41,7 @@ public void setupCommand( command.setContractRepository(contractRepository); command.setContractMilestoneRepository(contractMilestoneRepository); command.setTerminationRequestRepository(terminationRequestRepository); + command.setRabbitTemplate(rabbitTemplate); + command.setRedisService(redisService); } } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java index 488b0a7d..2d4811b3 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java @@ -1,16 +1,85 @@ package com.workup.contracts.commands; +import com.workup.contracts.models.Contract; +import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; +import com.workup.shared.commands.contracts.requests.ProgressMilestoneRequest; import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; +import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; +import com.workup.shared.commands.payments.paymentrequest.requests.CreatePaymentRequestRequest; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.shared.enums.ServiceQueueNames; +import com.workup.shared.enums.contracts.MilestoneState; + +import java.util.Optional; +import java.util.UUID; public class EvaluateMilestoneCommand extends ContractCommand { - + private EvaluateMilestoneResponse isValid(Optional milestoneOptional) { + if (milestoneOptional.isEmpty()) + return EvaluateMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.BAD_REQUEST) + .withErrorMessage("Milestone is not found") + .build(); + if (milestoneOptional.get().getStatus() != MilestoneState.IN_REVIEW) + return EvaluateMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.BAD_REQUEST) + .withErrorMessage("Milestone cannot be evaluated as it has not progressed enough") + .build(); + return null; + } @Override public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + Optional milestoneOptional = + contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); + + EvaluateMilestoneResponse checkerResponse = isValid(milestoneOptional); + if (checkerResponse != null) return checkerResponse; + + ContractMilestone updatedMilestone = milestoneOptional.get(); + + updatedMilestone.setStatus(request.getEvaluatedState()); + + try { + contractMilestoneRepository.save(updatedMilestone); + System.out.println(" [x] Milestone evaluated " + updatedMilestone); + System.out.println(" [x] Sending payment request "); + + { + // Getting the contract as we need to send the freelancer and client id since they are + // in the payment request parameters. + Optional contractOptional = contractRepository.findById(UUID.fromString(updatedMilestone.getContractId())); + if(contractOptional.isEmpty()) + throw new Exception("Contract Optional was empty, therefore unable to fetch data"); + + Contract milestoneContract = contractOptional.get(); + + CreatePaymentRequestRequest externalRequest = CreatePaymentRequestRequest + .builder() + .withAmount(updatedMilestone.getAmount()) + .withClientId(milestoneContract.getClientId()) + .withFreelancerId(milestoneContract.getFreelancerId()) + .withDescription(updatedMilestone.getMilestoneId().toString()) + .build(); + rabbitTemplate.convertAndSend(ServiceQueueNames.PAYMENTS,externalRequest); + } + + System.out.println(" [x] Payment request sent "); + return EvaluateMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.OK) + .withErrorMessage("") + .build(); + + } catch (Exception e) { + e.printStackTrace(); + return EvaluateMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) + .withErrorMessage(e.getMessage()) + .build(); + } - return null; } + + } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java index e981356e..25ba8d20 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java @@ -1,15 +1,56 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.models.Contract; import com.workup.shared.commands.contracts.requests.GetContractRequest; import com.workup.shared.commands.contracts.responses.GetContractResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.shared.redis.RedisService; + +import java.util.Optional; +import java.util.UUID; public class GetContractCommand extends ContractCommand { @Override public GetContractResponse Run(GetContractRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + String cachingKey = request.getContractId(); + GetContractResponse cachedResponse = + (GetContractResponse) + redisService.getValue(cachingKey, GetContractResponse.class); + if (cachedResponse != null) { + ContractsLogger.print("[x] Contract request response fetched from cache: " + cachedResponse.toString()); + + return cachedResponse; + } + + + Optional contractOptional = contractRepository.findById(UUID.fromString(request.getContractId())); + + if(contractOptional.isEmpty()){ + return GetContractResponse.builder() + .withStatusCode(HttpStatusCode.NOT_FOUND) + .withErrorMessage("Requested contract does not exist") + .build(); + } + + Contract contract = contractOptional.get(); + + GetContractResponse response = GetContractResponse + .builder() + .withContractId(contract.getContractId().toString()) + .withProposalId(contract.getProposalId()) + .withJobId(contract.getJobId()) + .withJobTitle(contract.getJobTitle()) + .withClientId(contract.getClientId()) + .withFreelancerId(contract.getFreelancerId()) + .withMilestonesIds(contract.getMilestonesIds()) + .withStatus(contract.getStatus()) + .withStatusCode(HttpStatusCode.OK) + .withErrorMessage("") + .build(); - return null; + redisService.setValue(cachingKey, response); + return response; } } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java index 1669a265..b1dcd155 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java @@ -1,16 +1,57 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.models.Contract; +import com.workup.contracts.models.ContractMilestone; +import com.workup.shared.commands.contracts.Milestone; import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; +import com.workup.shared.commands.contracts.responses.GetContractResponse; import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; +import com.workup.shared.enums.HttpStatusCode; + +import java.util.Optional; +import java.util.UUID; public class GetMilestoneCommand extends ContractCommand { @Override public GetMilestoneResponse Run(GetMilestoneRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + String cachingKey = request.getMilestoneId(); + + GetMilestoneResponse cachedResponse = + (GetMilestoneResponse) + redisService.getValue(cachingKey, GetMilestoneResponse.class); + if (cachedResponse != null) { + ContractsLogger.print("[x] Milestone request response fetched from cache: " + cachedResponse.toString()); + + return cachedResponse; + } + + Optional milestoneOptional = contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); + + if(milestoneOptional.isEmpty()){ + return GetMilestoneResponse.builder() + .withStatusCode(HttpStatusCode.NOT_FOUND) + .withErrorMessage("Requested milestone does not exist") + .build(); + } + + ContractMilestone milestone = milestoneOptional.get(); + + GetMilestoneResponse response = GetMilestoneResponse + .builder() + .withContractId(milestone.getContractId()) + .withMilestoneId(milestone.getMilestoneId().toString()) + .withAmount(milestone.getAmount()) + .withDescription(milestone.getDescription()) + .withDueDate(milestone.getDueDate()) + .withAmount(milestone.getAmount()) + .withStatusCode(HttpStatusCode.OK) + .withErrorMessage("") + .build(); - return null; + redisService.setValue(cachingKey, response); + return response; } } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java index cadb7a73..00f42f26 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java @@ -1,16 +1,56 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.models.ContractMilestone; +import com.workup.contracts.models.TerminationRequest; import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest; +import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse; +import com.workup.shared.enums.HttpStatusCode; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; public class GetPendingTerminationsCommand extends ContractCommand { @Override public GetPendingTerminationsResponse Run(GetPendingTerminationsRequest request) { - // First we will get the milestones and add them to the database first, - // This will allow us to have their IDs for when we insert the contract. + String cachingKey = request.getContractId() + "/pending_terminations"; + + GetPendingTerminationsResponse cachedResponse = + (GetPendingTerminationsResponse) + redisService.getValue(cachingKey, GetPendingTerminationsResponse.class); + if (cachedResponse != null) { + ContractsLogger.print("[x] Contract terminations response fetched from cache: " + cachedResponse.toString()); + + return cachedResponse; + } + + List terminationsList = terminationRequestRepository.findByContractId(request.getContractId()); + + if (terminationsList.isEmpty()) { + return GetPendingTerminationsResponse.builder() + .withStatusCode(HttpStatusCode.NOT_FOUND) + .withErrorMessage("No pending terminations exist") + .build(); + } + + TerminationRequest terminationRequest = terminationsList.getFirst(); + + GetPendingTerminationsResponse response = GetPendingTerminationsResponse + .builder() + .withRequestId(terminationRequest.getRequestId().toString()) + .withRequesterId(terminationRequest.getRequesterId()) + .withContractId(terminationRequest.getContractId()) + .withReason(terminationRequest.getReason()) + .withStatus(terminationRequest.getStatus()) + .withStatusCode(HttpStatusCode.OK) + .withErrorMessage("") + .build(); - return null; + redisService.setValue(cachingKey, response); + return response; } } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java index 40cccb03..680ee130 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java @@ -11,16 +11,16 @@ public class ProgressMilestoneCommand extends ContractCommand { - private ProgressMilestoneResponse isValid(ProgressMilestoneRequest request) { - Optional milestone = - contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); - if (milestone.isEmpty()) + private ProgressMilestoneResponse isValid(Optional milestoneOptional) { + if (milestoneOptional.isEmpty()) return ProgressMilestoneResponse.builder() .withStatusCode(HttpStatusCode.BAD_REQUEST) .withErrorMessage("Milestone is not found") .build(); - if (milestone.get().getStatus() != MilestoneState.OPEN - && milestone.get().getStatus() != MilestoneState.IN_PROGRESS) + + MilestoneState milestoneState = milestoneOptional.get().getStatus(); + if (milestoneState != MilestoneState.OPEN + && milestoneState != MilestoneState.IN_PROGRESS) return ProgressMilestoneResponse.builder() .withStatusCode(HttpStatusCode.BAD_REQUEST) .withErrorMessage("Milestone cannot be progressed through this command") @@ -30,22 +30,15 @@ private ProgressMilestoneResponse isValid(ProgressMilestoneRequest request) { @Override public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { - ProgressMilestoneResponse checkerResponse = isValid(request); + Optional milestoneOptional = + contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); + + ProgressMilestoneResponse checkerResponse = isValid(milestoneOptional); if (checkerResponse != null) return checkerResponse; - Optional milestone = - contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); - ContractMilestone updatedMilestone = milestone.get(); - if (updatedMilestone.getStatus() == MilestoneState.OPEN) { - updatedMilestone.setStatus(MilestoneState.IN_PROGRESS); - } else if (updatedMilestone.getStatus() == MilestoneState.IN_PROGRESS) { - updatedMilestone.setStatus(MilestoneState.IN_REVIEW); - // Send to payments here + ContractMilestone updatedMilestone = milestoneOptional.get(); - // get required data from milestone - // milestoneContract = - // contractRepository.findById(UUID.fromString(updatedMilestone.getContractId())); - } + progress(updatedMilestone); try { contractMilestoneRepository.save(updatedMilestone); @@ -63,4 +56,11 @@ public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { .build(); } } + + private void progress(ContractMilestone milestone) { + if (milestone.getStatus() == MilestoneState.OPEN) + milestone.setStatus(MilestoneState.IN_PROGRESS); + else if (milestone.getStatus() == MilestoneState.IN_PROGRESS) + milestone.setStatus(MilestoneState.IN_REVIEW); + } } diff --git a/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java b/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java new file mode 100644 index 00000000..65660cd6 --- /dev/null +++ b/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java @@ -0,0 +1,9 @@ +package com.workup.contracts.logger; + +public class ContractsLogger { + + public static void print(String logMessage) { + System.out.println(logMessage); + } + +} diff --git a/services/contracts/src/main/java/com/workup/contracts/repositories/TerminationRequestRepository.java b/services/contracts/src/main/java/com/workup/contracts/repositories/TerminationRequestRepository.java index 16734af9..d296d126 100644 --- a/services/contracts/src/main/java/com/workup/contracts/repositories/TerminationRequestRepository.java +++ b/services/contracts/src/main/java/com/workup/contracts/repositories/TerminationRequestRepository.java @@ -1,11 +1,13 @@ package com.workup.contracts.repositories; +import com.workup.contracts.models.ContractMilestone; import com.workup.contracts.models.TerminationRequest; import com.workup.shared.enums.contracts.TerminationRequestStatus; import java.util.List; import java.util.UUID; import org.springframework.data.cassandra.repository.AllowFiltering; import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.data.cassandra.repository.Query; import org.springframework.stereotype.Repository; @Repository @@ -14,4 +16,8 @@ public interface TerminationRequestRepository @AllowFiltering List findByRequesterIdAndContractIdAndStatus( String requesterId, String contractId, TerminationRequestStatus status); + + @Query("SELECT * FROM contracts_data.termination_requests WHERE contractid = ?0") + List findByContractId(String contractId); + } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java index cafbb1c8..6b526bb9 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetContractResponse.java @@ -12,11 +12,11 @@ @Jacksonized public class GetContractResponse extends CommandResponse { private final String contractId; - private String jobTitle; - private String jobId; - private String proposalId; - private String freelancerId; - private String clientId; - private List milestonesIds; - private ContractState status; + private final String jobTitle; + private final String jobId; + private final String proposalId; + private final String freelancerId; + private final String clientId; + private final List milestonesIds; + private final ContractState status; } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java index 9dd60802..81c6bf69 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java @@ -2,13 +2,25 @@ import com.workup.shared.commands.CommandResponse; import com.workup.shared.commands.contracts.Milestone; +import com.workup.shared.enums.contracts.MilestoneState; import lombok.Getter; +import lombok.Setter; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; +import java.util.Date; +import java.util.UUID; + @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized public class GetMilestoneResponse extends CommandResponse { - private final Milestone milestone; + private final String milestoneId; + + private final String contractId; + + private final String description; + private final Date dueDate; + private final double amount; + private final MilestoneState status; } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java index 4a028848..7f45a4bc 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetPendingTerminationsResponse.java @@ -10,11 +10,11 @@ @SuperBuilder(setterPrefix = "with") @Jacksonized public class GetPendingTerminationsResponse extends CommandResponse { - private String requestId; + private final String requestId; - private String contractId; - private String requesterId; - private String reason; + private final String contractId; + private final String requesterId; + private final String reason; - private TerminationRequestStatus status; + private final TerminationRequestStatus status; } From 2b81ea6dbb7301d30f4850ebcdc8fb50e292cb48 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Fri, 10 May 2024 01:57:56 +0300 Subject: [PATCH 06/11] format message --- .../commands/ContractCommandMap.java | 1 - .../commands/EvaluateMilestoneCommand.java | 44 +++++++++---------- .../commands/GetContractCommand.java | 24 +++++----- .../commands/GetMilestoneCommand.java | 25 +++++------ .../GetPendingTerminationsCommand.java | 25 +++++------ .../commands/ProgressMilestoneCommand.java | 5 +-- .../contracts/logger/ContractsLogger.java | 7 ++- .../TerminationRequestRepository.java | 2 - .../responses/GetMilestoneResponse.java | 6 +-- 9 files changed, 59 insertions(+), 80 deletions(-) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommandMap.java b/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommandMap.java index 5a75889c..1f12ad3b 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommandMap.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ContractCommandMap.java @@ -15,7 +15,6 @@ public class ContractCommandMap extends CommandMap> { - @Autowired ContractRepository contractRepository; @Autowired ContractMilestoneRepository contractMilestoneRepository; diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java index 2d4811b3..b48b7591 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java @@ -3,14 +3,11 @@ import com.workup.contracts.models.Contract; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; -import com.workup.shared.commands.contracts.requests.ProgressMilestoneRequest; import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; -import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; import com.workup.shared.commands.payments.paymentrequest.requests.CreatePaymentRequestRequest; import com.workup.shared.enums.HttpStatusCode; import com.workup.shared.enums.ServiceQueueNames; import com.workup.shared.enums.contracts.MilestoneState; - import java.util.Optional; import java.util.UUID; @@ -19,20 +16,21 @@ public class EvaluateMilestoneCommand private EvaluateMilestoneResponse isValid(Optional milestoneOptional) { if (milestoneOptional.isEmpty()) return EvaluateMilestoneResponse.builder() - .withStatusCode(HttpStatusCode.BAD_REQUEST) - .withErrorMessage("Milestone is not found") - .build(); + .withStatusCode(HttpStatusCode.BAD_REQUEST) + .withErrorMessage("Milestone is not found") + .build(); if (milestoneOptional.get().getStatus() != MilestoneState.IN_REVIEW) return EvaluateMilestoneResponse.builder() - .withStatusCode(HttpStatusCode.BAD_REQUEST) - .withErrorMessage("Milestone cannot be evaluated as it has not progressed enough") - .build(); + .withStatusCode(HttpStatusCode.BAD_REQUEST) + .withErrorMessage("Milestone cannot be evaluated as it has not progressed enough") + .build(); return null; } + @Override public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { Optional milestoneOptional = - contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); + contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); EvaluateMilestoneResponse checkerResponse = isValid(milestoneOptional); if (checkerResponse != null) return checkerResponse; @@ -49,37 +47,35 @@ public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { { // Getting the contract as we need to send the freelancer and client id since they are // in the payment request parameters. - Optional contractOptional = contractRepository.findById(UUID.fromString(updatedMilestone.getContractId())); - if(contractOptional.isEmpty()) + Optional contractOptional = + contractRepository.findById(UUID.fromString(updatedMilestone.getContractId())); + if (contractOptional.isEmpty()) throw new Exception("Contract Optional was empty, therefore unable to fetch data"); Contract milestoneContract = contractOptional.get(); - CreatePaymentRequestRequest externalRequest = CreatePaymentRequestRequest - .builder() + CreatePaymentRequestRequest externalRequest = + CreatePaymentRequestRequest.builder() .withAmount(updatedMilestone.getAmount()) .withClientId(milestoneContract.getClientId()) .withFreelancerId(milestoneContract.getFreelancerId()) .withDescription(updatedMilestone.getMilestoneId().toString()) .build(); - rabbitTemplate.convertAndSend(ServiceQueueNames.PAYMENTS,externalRequest); + rabbitTemplate.convertAndSend(ServiceQueueNames.PAYMENTS, externalRequest); } System.out.println(" [x] Payment request sent "); return EvaluateMilestoneResponse.builder() - .withStatusCode(HttpStatusCode.OK) - .withErrorMessage("") - .build(); + .withStatusCode(HttpStatusCode.OK) + .withErrorMessage("") + .build(); } catch (Exception e) { e.printStackTrace(); return EvaluateMilestoneResponse.builder() - .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) - .withErrorMessage(e.getMessage()) - .build(); + .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) + .withErrorMessage(e.getMessage()) + .build(); } - } - - } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java index 25ba8d20..8621c65e 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java @@ -5,8 +5,6 @@ import com.workup.shared.commands.contracts.requests.GetContractRequest; import com.workup.shared.commands.contracts.responses.GetContractResponse; import com.workup.shared.enums.HttpStatusCode; -import com.workup.shared.redis.RedisService; - import java.util.Optional; import java.util.UUID; @@ -16,28 +14,28 @@ public class GetContractCommand extends ContractCommand contractOptional = + contractRepository.findById(UUID.fromString(request.getContractId())); - Optional contractOptional = contractRepository.findById(UUID.fromString(request.getContractId())); - - if(contractOptional.isEmpty()){ + if (contractOptional.isEmpty()) { return GetContractResponse.builder() - .withStatusCode(HttpStatusCode.NOT_FOUND) - .withErrorMessage("Requested contract does not exist") - .build(); + .withStatusCode(HttpStatusCode.NOT_FOUND) + .withErrorMessage("Requested contract does not exist") + .build(); } Contract contract = contractOptional.get(); - GetContractResponse response = GetContractResponse - .builder() + GetContractResponse response = + GetContractResponse.builder() .withContractId(contract.getContractId().toString()) .withProposalId(contract.getProposalId()) .withJobId(contract.getJobId()) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java index b1dcd155..3b28b78b 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java @@ -1,14 +1,10 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; -import com.workup.contracts.models.Contract; import com.workup.contracts.models.ContractMilestone; -import com.workup.shared.commands.contracts.Milestone; import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; -import com.workup.shared.commands.contracts.responses.GetContractResponse; import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; import com.workup.shared.enums.HttpStatusCode; - import java.util.Optional; import java.util.UUID; @@ -20,27 +16,28 @@ public GetMilestoneResponse Run(GetMilestoneRequest request) { String cachingKey = request.getMilestoneId(); GetMilestoneResponse cachedResponse = - (GetMilestoneResponse) - redisService.getValue(cachingKey, GetMilestoneResponse.class); + (GetMilestoneResponse) redisService.getValue(cachingKey, GetMilestoneResponse.class); if (cachedResponse != null) { - ContractsLogger.print("[x] Milestone request response fetched from cache: " + cachedResponse.toString()); + ContractsLogger.print( + "[x] Milestone request response fetched from cache: " + cachedResponse.toString()); return cachedResponse; } - Optional milestoneOptional = contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); + Optional milestoneOptional = + contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); - if(milestoneOptional.isEmpty()){ + if (milestoneOptional.isEmpty()) { return GetMilestoneResponse.builder() - .withStatusCode(HttpStatusCode.NOT_FOUND) - .withErrorMessage("Requested milestone does not exist") - .build(); + .withStatusCode(HttpStatusCode.NOT_FOUND) + .withErrorMessage("Requested milestone does not exist") + .build(); } ContractMilestone milestone = milestoneOptional.get(); - GetMilestoneResponse response = GetMilestoneResponse - .builder() + GetMilestoneResponse response = + GetMilestoneResponse.builder() .withContractId(milestone.getContractId()) .withMilestoneId(milestone.getMilestoneId().toString()) .withAmount(milestone.getAmount()) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java index 00f42f26..bfcf3470 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java @@ -1,16 +1,11 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; -import com.workup.contracts.models.ContractMilestone; import com.workup.contracts.models.TerminationRequest; import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest; -import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse; import com.workup.shared.enums.HttpStatusCode; - import java.util.List; -import java.util.Optional; -import java.util.UUID; public class GetPendingTerminationsCommand extends ContractCommand { @@ -20,27 +15,29 @@ public GetPendingTerminationsResponse Run(GetPendingTerminationsRequest request) String cachingKey = request.getContractId() + "/pending_terminations"; GetPendingTerminationsResponse cachedResponse = - (GetPendingTerminationsResponse) - redisService.getValue(cachingKey, GetPendingTerminationsResponse.class); + (GetPendingTerminationsResponse) + redisService.getValue(cachingKey, GetPendingTerminationsResponse.class); if (cachedResponse != null) { - ContractsLogger.print("[x] Contract terminations response fetched from cache: " + cachedResponse.toString()); + ContractsLogger.print( + "[x] Contract terminations response fetched from cache: " + cachedResponse.toString()); return cachedResponse; } - List terminationsList = terminationRequestRepository.findByContractId(request.getContractId()); + List terminationsList = + terminationRequestRepository.findByContractId(request.getContractId()); if (terminationsList.isEmpty()) { return GetPendingTerminationsResponse.builder() - .withStatusCode(HttpStatusCode.NOT_FOUND) - .withErrorMessage("No pending terminations exist") - .build(); + .withStatusCode(HttpStatusCode.NOT_FOUND) + .withErrorMessage("No pending terminations exist") + .build(); } TerminationRequest terminationRequest = terminationsList.getFirst(); - GetPendingTerminationsResponse response = GetPendingTerminationsResponse - .builder() + GetPendingTerminationsResponse response = + GetPendingTerminationsResponse.builder() .withRequestId(terminationRequest.getRequestId().toString()) .withRequesterId(terminationRequest.getRequesterId()) .withContractId(terminationRequest.getContractId()) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java index 680ee130..029c360c 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java @@ -19,8 +19,7 @@ private ProgressMilestoneResponse isValid(Optional milestoneO .build(); MilestoneState milestoneState = milestoneOptional.get().getStatus(); - if (milestoneState != MilestoneState.OPEN - && milestoneState != MilestoneState.IN_PROGRESS) + if (milestoneState != MilestoneState.OPEN && milestoneState != MilestoneState.IN_PROGRESS) return ProgressMilestoneResponse.builder() .withStatusCode(HttpStatusCode.BAD_REQUEST) .withErrorMessage("Milestone cannot be progressed through this command") @@ -31,7 +30,7 @@ private ProgressMilestoneResponse isValid(Optional milestoneO @Override public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { Optional milestoneOptional = - contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); + contractMilestoneRepository.findById(UUID.fromString(request.getMilestoneId())); ProgressMilestoneResponse checkerResponse = isValid(milestoneOptional); if (checkerResponse != null) return checkerResponse; diff --git a/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java b/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java index 65660cd6..1e2e71d6 100644 --- a/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java +++ b/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java @@ -2,8 +2,7 @@ public class ContractsLogger { - public static void print(String logMessage) { - System.out.println(logMessage); - } - + public static void print(String logMessage) { + System.out.println(logMessage); + } } diff --git a/services/contracts/src/main/java/com/workup/contracts/repositories/TerminationRequestRepository.java b/services/contracts/src/main/java/com/workup/contracts/repositories/TerminationRequestRepository.java index d296d126..098dd1e6 100644 --- a/services/contracts/src/main/java/com/workup/contracts/repositories/TerminationRequestRepository.java +++ b/services/contracts/src/main/java/com/workup/contracts/repositories/TerminationRequestRepository.java @@ -1,6 +1,5 @@ package com.workup.contracts.repositories; -import com.workup.contracts.models.ContractMilestone; import com.workup.contracts.models.TerminationRequest; import com.workup.shared.enums.contracts.TerminationRequestStatus; import java.util.List; @@ -19,5 +18,4 @@ List findByRequesterIdAndContractIdAndStatus( @Query("SELECT * FROM contracts_data.termination_requests WHERE contractid = ?0") List findByContractId(String contractId); - } diff --git a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java index 81c6bf69..190d4ad6 100644 --- a/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java +++ b/shared/src/main/java/com/workup/shared/commands/contracts/responses/GetMilestoneResponse.java @@ -1,16 +1,12 @@ package com.workup.shared.commands.contracts.responses; import com.workup.shared.commands.CommandResponse; -import com.workup.shared.commands.contracts.Milestone; import com.workup.shared.enums.contracts.MilestoneState; +import java.util.Date; import lombok.Getter; -import lombok.Setter; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; -import java.util.Date; -import java.util.UUID; - @Getter @SuperBuilder(setterPrefix = "with") @Jacksonized From 19fe16bb7939663ac09047dd93a5dbadc981e070 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Fri, 10 May 2024 02:24:53 +0300 Subject: [PATCH 07/11] small fix to use send and receive instead of just send --- .../com/workup/contracts/commands/EvaluateMilestoneCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java index b48b7591..c4027983 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java @@ -61,7 +61,7 @@ public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { .withFreelancerId(milestoneContract.getFreelancerId()) .withDescription(updatedMilestone.getMilestoneId().toString()) .build(); - rabbitTemplate.convertAndSend(ServiceQueueNames.PAYMENTS, externalRequest); + rabbitTemplate.convertSendAndReceive(ServiceQueueNames.PAYMENTS, externalRequest); } System.out.println(" [x] Payment request sent "); From 996843685fb15377733da7bf23ce16cdd72bd843 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Fri, 10 May 2024 07:38:14 +0300 Subject: [PATCH 08/11] fixed small bug --- .../workup/contracts/commands/EvaluateMilestoneCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java index c4027983..02dc0039 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java @@ -42,9 +42,9 @@ public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { try { contractMilestoneRepository.save(updatedMilestone); System.out.println(" [x] Milestone evaluated " + updatedMilestone); - System.out.println(" [x] Sending payment request "); - { + if (request.getEvaluatedState() == MilestoneState.ACCEPTED) { + System.out.println(" [x] Sending payment request "); // Getting the contract as we need to send the freelancer and client id since they are // in the payment request parameters. Optional contractOptional = @@ -62,9 +62,9 @@ public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { .withDescription(updatedMilestone.getMilestoneId().toString()) .build(); rabbitTemplate.convertSendAndReceive(ServiceQueueNames.PAYMENTS, externalRequest); + System.out.println(" [x] Payment request sent "); } - System.out.println(" [x] Payment request sent "); return EvaluateMilestoneResponse.builder() .withStatusCode(HttpStatusCode.OK) .withErrorMessage("") From 1b1d00668ef2aaa55cc1f7b6d3119593571e9267 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Sun, 12 May 2024 15:55:30 +0300 Subject: [PATCH 09/11] adding testing --- .../contracts/ContractApplicationTests.java | 11 -- .../contracts/ContractsApplicationTests.java | 107 ++++++++++++++++++ .../com/workup/contracts/TestConfigBase.java | 14 +++ 3 files changed, 121 insertions(+), 11 deletions(-) delete mode 100644 services/contracts/src/test/java/com/workup/contracts/ContractApplicationTests.java create mode 100644 services/contracts/src/test/java/com/workup/contracts/ContractsApplicationTests.java create mode 100644 services/contracts/src/test/java/com/workup/contracts/TestConfigBase.java diff --git a/services/contracts/src/test/java/com/workup/contracts/ContractApplicationTests.java b/services/contracts/src/test/java/com/workup/contracts/ContractApplicationTests.java deleted file mode 100644 index 83a3f093..00000000 --- a/services/contracts/src/test/java/com/workup/contracts/ContractApplicationTests.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.workup.contracts; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ContractApplicationTests { - - @Test - void contextLoads() {} -} diff --git a/services/contracts/src/test/java/com/workup/contracts/ContractsApplicationTests.java b/services/contracts/src/test/java/com/workup/contracts/ContractsApplicationTests.java new file mode 100644 index 00000000..f73c83f8 --- /dev/null +++ b/services/contracts/src/test/java/com/workup/contracts/ContractsApplicationTests.java @@ -0,0 +1,107 @@ +package com.workup.contracts; + +import com.workup.contracts.repositories.ContractMilestoneRepository; +import com.workup.contracts.repositories.ContractRepository; +import com.workup.contracts.repositories.TerminationRequestRepository; +import com.workup.shared.commands.jobs.requests.CreateJobRequest; +import com.workup.shared.commands.jobs.responses.CreateJobResponse; +import com.workup.shared.enums.HttpStatusCode; +import com.workup.shared.enums.ServiceQueueNames; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.CassandraContainer; +import org.testcontainers.containers.RabbitMQContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.text.ParseException; +import java.util.UUID; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +@SpringBootTest +@Testcontainers +@Import(TestConfigBase.class) +class ContractsApplicationTests { + + @Container + static CassandraContainer cassandraContainer = + new CassandraContainer<>("cassandra:4.0.7").withConfigurationOverride("cassandra-config"); + + @Container + static RabbitMQContainer rabbitMQContainer = new RabbitMQContainer("rabbitmq:3.13-management"); + + static String GetCassandraContactPoint() { + return cassandraContainer.getHost() + ":" + cassandraContainer.getFirstMappedPort(); + } + + @DynamicPropertySource + static void datasourceProperties(DynamicPropertyRegistry registry) { + registry.add("spring.cassandra.contact-points", ContractsApplicationTests::GetCassandraContactPoint); + + registry.add("spring.rabbitmq.host", rabbitMQContainer::getHost); + registry.add("spring.rabbitmq.port", rabbitMQContainer::getFirstMappedPort); + registry.add("spring.rabbitmq.username", rabbitMQContainer::getAdminUsername); + registry.add("spring.rabbitmq.password", rabbitMQContainer::getAdminPassword); + } + + private static final String CLIENT_ONE_ID = "123"; + private static final String CLIENT_TWO_ID = "456"; + private static final String FREELANCER_ONE_ID = "789"; + + @Autowired + AmqpTemplate template; + @Autowired + ContractRepository contractRepository; + @Autowired + ContractMilestoneRepository contractMilestoneRepository; + @Autowired + TerminationRequestRepository terminationRequestRepository; + + @BeforeEach + void clearAll() { + contractRepository.deleteAll(); + contractMilestoneRepository.deleteAll(); + terminationRequestRepository.deleteAll(); + } + + + /** + * Creates a job request. + * + * @throws ParseException + */ + @Test + void testCreateJob() { + // Example test from jobs +// CreateJobRequest createJobRequest = +// CreateJobRequest.builder() +// .withTitle("Convert HTML Template to React 3") +// .withDescription( +// "I have an HTML template that I have purchased and own the rights to. I would like" +// + " it converted into a React application.") +// .withSkills(new String[] {"HTML", "CSS", "JavaScript", "React"}) +// .withUserId(CLIENT_ONE_ID) +// .build(); +// +// CreateJobResponse response = +// (CreateJobResponse) +// template.convertSendAndReceive(ServiceQueueNames.JOBS, createJobRequest); +// +// assertNotNull(response); +// assertTrue(response.getStatusCode() == HttpStatusCode.CREATED); +// +// jobRepository +// .findById(UUID.fromString(response.getJobId())) +// .ifPresentOrElse( +// job -> assertTrue(job.getTitle().equals(createJobRequest.getTitle())), +// () -> new RuntimeException("Job not found")); + } +} diff --git a/services/contracts/src/test/java/com/workup/contracts/TestConfigBase.java b/services/contracts/src/test/java/com/workup/contracts/TestConfigBase.java new file mode 100644 index 00000000..92856494 --- /dev/null +++ b/services/contracts/src/test/java/com/workup/contracts/TestConfigBase.java @@ -0,0 +1,14 @@ +package com.workup.contracts; + +import com.workup.shared.enums.ServiceQueueNames; +import org.springframework.amqp.core.Queue; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +@TestConfiguration +public class TestConfigBase { + @Bean + public Queue contractsQueueMock() { + return new Queue(ServiceQueueNames.CONTRACTS); + } +} From d0cfc943eeeebeb61a9dd50ab6f43a8499dc9765 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Sun, 12 May 2024 15:58:38 +0300 Subject: [PATCH 10/11] formating --- .../contracts/ContractsApplicationTests.java | 74 ++++++++----------- .../com/workup/contracts/TestConfigBase.java | 8 +- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/services/contracts/src/test/java/com/workup/contracts/ContractsApplicationTests.java b/services/contracts/src/test/java/com/workup/contracts/ContractsApplicationTests.java index f73c83f8..ac6e5ec8 100644 --- a/services/contracts/src/test/java/com/workup/contracts/ContractsApplicationTests.java +++ b/services/contracts/src/test/java/com/workup/contracts/ContractsApplicationTests.java @@ -3,10 +3,7 @@ import com.workup.contracts.repositories.ContractMilestoneRepository; import com.workup.contracts.repositories.ContractRepository; import com.workup.contracts.repositories.TerminationRequestRepository; -import com.workup.shared.commands.jobs.requests.CreateJobRequest; -import com.workup.shared.commands.jobs.responses.CreateJobResponse; -import com.workup.shared.enums.HttpStatusCode; -import com.workup.shared.enums.ServiceQueueNames; +import java.text.ParseException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.AmqpTemplate; @@ -20,12 +17,6 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import java.text.ParseException; -import java.util.UUID; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - @SpringBootTest @Testcontainers @Import(TestConfigBase.class) @@ -33,7 +24,7 @@ class ContractsApplicationTests { @Container static CassandraContainer cassandraContainer = - new CassandraContainer<>("cassandra:4.0.7").withConfigurationOverride("cassandra-config"); + new CassandraContainer<>("cassandra:4.0.7").withConfigurationOverride("cassandra-config"); @Container static RabbitMQContainer rabbitMQContainer = new RabbitMQContainer("rabbitmq:3.13-management"); @@ -44,7 +35,8 @@ static String GetCassandraContactPoint() { @DynamicPropertySource static void datasourceProperties(DynamicPropertyRegistry registry) { - registry.add("spring.cassandra.contact-points", ContractsApplicationTests::GetCassandraContactPoint); + registry.add( + "spring.cassandra.contact-points", ContractsApplicationTests::GetCassandraContactPoint); registry.add("spring.rabbitmq.host", rabbitMQContainer::getHost); registry.add("spring.rabbitmq.port", rabbitMQContainer::getFirstMappedPort); @@ -56,14 +48,10 @@ static void datasourceProperties(DynamicPropertyRegistry registry) { private static final String CLIENT_TWO_ID = "456"; private static final String FREELANCER_ONE_ID = "789"; - @Autowired - AmqpTemplate template; - @Autowired - ContractRepository contractRepository; - @Autowired - ContractMilestoneRepository contractMilestoneRepository; - @Autowired - TerminationRequestRepository terminationRequestRepository; + @Autowired AmqpTemplate template; + @Autowired ContractRepository contractRepository; + @Autowired ContractMilestoneRepository contractMilestoneRepository; + @Autowired TerminationRequestRepository terminationRequestRepository; @BeforeEach void clearAll() { @@ -72,7 +60,6 @@ void clearAll() { terminationRequestRepository.deleteAll(); } - /** * Creates a job request. * @@ -81,27 +68,28 @@ void clearAll() { @Test void testCreateJob() { // Example test from jobs -// CreateJobRequest createJobRequest = -// CreateJobRequest.builder() -// .withTitle("Convert HTML Template to React 3") -// .withDescription( -// "I have an HTML template that I have purchased and own the rights to. I would like" -// + " it converted into a React application.") -// .withSkills(new String[] {"HTML", "CSS", "JavaScript", "React"}) -// .withUserId(CLIENT_ONE_ID) -// .build(); -// -// CreateJobResponse response = -// (CreateJobResponse) -// template.convertSendAndReceive(ServiceQueueNames.JOBS, createJobRequest); -// -// assertNotNull(response); -// assertTrue(response.getStatusCode() == HttpStatusCode.CREATED); -// -// jobRepository -// .findById(UUID.fromString(response.getJobId())) -// .ifPresentOrElse( -// job -> assertTrue(job.getTitle().equals(createJobRequest.getTitle())), -// () -> new RuntimeException("Job not found")); + // CreateJobRequest createJobRequest = + // CreateJobRequest.builder() + // .withTitle("Convert HTML Template to React 3") + // .withDescription( + // "I have an HTML template that I have purchased and own the rights + // to. I would like" + // + " it converted into a React application.") + // .withSkills(new String[] {"HTML", "CSS", "JavaScript", "React"}) + // .withUserId(CLIENT_ONE_ID) + // .build(); + // + // CreateJobResponse response = + // (CreateJobResponse) + // template.convertSendAndReceive(ServiceQueueNames.JOBS, createJobRequest); + // + // assertNotNull(response); + // assertTrue(response.getStatusCode() == HttpStatusCode.CREATED); + // + // jobRepository + // .findById(UUID.fromString(response.getJobId())) + // .ifPresentOrElse( + // job -> assertTrue(job.getTitle().equals(createJobRequest.getTitle())), + // () -> new RuntimeException("Job not found")); } } diff --git a/services/contracts/src/test/java/com/workup/contracts/TestConfigBase.java b/services/contracts/src/test/java/com/workup/contracts/TestConfigBase.java index 92856494..acf2801d 100644 --- a/services/contracts/src/test/java/com/workup/contracts/TestConfigBase.java +++ b/services/contracts/src/test/java/com/workup/contracts/TestConfigBase.java @@ -7,8 +7,8 @@ @TestConfiguration public class TestConfigBase { - @Bean - public Queue contractsQueueMock() { - return new Queue(ServiceQueueNames.CONTRACTS); - } + @Bean + public Queue contractsQueueMock() { + return new Queue(ServiceQueueNames.CONTRACTS); + } } From a1e6c97c2dcacb135f5b0b562ed21da1ab194d2d Mon Sep 17 00:00:00 2001 From: HusseinYasser Date: Sun, 12 May 2024 16:34:01 +0300 Subject: [PATCH 11/11] replaced every sys out with the logger template --- .../contracts/commands/EvaluateMilestoneCommand.java | 7 ++++--- .../commands/HandleTerminationRequestCommand.java | 5 +++-- .../workup/contracts/commands/InitiateContractCommand.java | 5 +++-- .../contracts/commands/MarkMilestoneAsPaidCommand.java | 3 +-- .../contracts/commands/ProgressMilestoneCommand.java | 3 ++- .../commands/RequestContractTerminationCommand.java | 3 ++- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java index 02dc0039..f5df099d 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java @@ -1,5 +1,6 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; import com.workup.contracts.models.Contract; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; @@ -41,10 +42,10 @@ public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { try { contractMilestoneRepository.save(updatedMilestone); - System.out.println(" [x] Milestone evaluated " + updatedMilestone); + ContractsLogger.print(" [x] Milestone evaluated " + updatedMilestone); if (request.getEvaluatedState() == MilestoneState.ACCEPTED) { - System.out.println(" [x] Sending payment request "); + ContractsLogger.print(" [x] Sending payment request "); // Getting the contract as we need to send the freelancer and client id since they are // in the payment request parameters. Optional contractOptional = @@ -62,7 +63,7 @@ public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { .withDescription(updatedMilestone.getMilestoneId().toString()) .build(); rabbitTemplate.convertSendAndReceive(ServiceQueueNames.PAYMENTS, externalRequest); - System.out.println(" [x] Payment request sent "); + ContractsLogger.print(" [x] Payment request sent "); } return EvaluateMilestoneResponse.builder() diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/HandleTerminationRequestCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/HandleTerminationRequestCommand.java index c55e6fcd..d8fd432d 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/HandleTerminationRequestCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/HandleTerminationRequestCommand.java @@ -1,5 +1,6 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; import com.workup.contracts.models.Contract; import com.workup.contracts.models.TerminationRequest; import com.workup.shared.commands.contracts.requests.HandleTerminationRequest; @@ -41,7 +42,7 @@ private HandleTerminationResponse handleTerminationRequest( } try { TerminationRequest updatedRequest = terminationRequestRepository.save(terminationRequest); - System.out.println(" [x] Updated Termination Request " + updatedRequest); + ContractsLogger.print(" [x] Updated Termination Request " + updatedRequest); return HandleTerminationResponse.builder() .withRequestStatus(updatedRequest.getStatus()) .withStatusCode(HttpStatusCode.OK) @@ -67,7 +68,7 @@ private HandleTerminationResponse terminateContract(String contractId) { updatedContract.setStatus(ContractState.TERMINATED); try { updatedContract = contractRepository.save(updatedContract); - System.out.println(" [x] Updated Contract Status to Terminated " + updatedContract); + ContractsLogger.print(" [x] Updated Contract Status to Terminated " + updatedContract); } catch (Exception e) { e.printStackTrace(); return HandleTerminationResponse.builder() diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/InitiateContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/InitiateContractCommand.java index 45a191b5..d85dd4c5 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/InitiateContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/InitiateContractCommand.java @@ -1,5 +1,6 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; import com.workup.contracts.models.Contract; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.Milestone; @@ -56,11 +57,11 @@ public InitiateContractResponse Run(InitiateContractRequest request) { try { Contract savedContract = contractRepository.save(contract); - System.out.println(" [x] Saved Contract '" + savedContract.getJobTitle()); + ContractsLogger.print(" [x] Saved Contract '" + savedContract.getJobTitle()); contractMilestoneRepository.saveAll(milestonesToAdd); - System.out.println(" [x] Saved All Milestones '" + savedContract.getJobTitle()); + ContractsLogger.print(" [x] Saved All Milestones '" + savedContract.getJobTitle()); return InitiateContractResponse.builder() .withContractId(savedContract.getContractId().toString()) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/MarkMilestoneAsPaidCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/MarkMilestoneAsPaidCommand.java index 99720855..9922fd13 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/MarkMilestoneAsPaidCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/MarkMilestoneAsPaidCommand.java @@ -39,6 +39,7 @@ public MarkPaymentCompletedResponse Run(MarkPaymentCompletedRequest request) { try { contractMilestoneRepository.save(updatedMilestone); System.out.println(" [x] Marked Milestone as Paid '" + updatedMilestone); + return MarkPaymentCompletedResponse.builder().withStatusCode(HttpStatusCode.OK).build(); } catch (Exception e) { e.printStackTrace(); return MarkPaymentCompletedResponse.builder() @@ -46,8 +47,6 @@ public MarkPaymentCompletedResponse Run(MarkPaymentCompletedRequest request) { .withErrorMessage(e.getMessage()) .build(); } - - return null; } private void pay(ContractMilestone milestone) { diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java index 029c360c..3f480e3f 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java @@ -1,5 +1,6 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.ProgressMilestoneRequest; import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; @@ -41,7 +42,7 @@ public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { try { contractMilestoneRepository.save(updatedMilestone); - System.out.println(" [x] Milestone Progressed " + updatedMilestone); + ContractsLogger.print(" [x] Milestone Progressed " + updatedMilestone); return ProgressMilestoneResponse.builder() .withStatusCode(HttpStatusCode.OK) .withErrorMessage("") diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/RequestContractTerminationCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/RequestContractTerminationCommand.java index 5eedd8c0..9cd7850d 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/RequestContractTerminationCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/RequestContractTerminationCommand.java @@ -1,5 +1,6 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; import com.workup.contracts.models.Contract; import com.workup.contracts.models.TerminationRequest; import com.workup.shared.commands.contracts.requests.ContractTerminationRequest; @@ -68,7 +69,7 @@ public ContractTerminationResponse Run(ContractTerminationRequest request) { try { TerminationRequest savedRequest = terminationRequestRepository.save(terminationRequest); - System.out.println(" [x] Saved Termination Request '" + savedRequest); + ContractsLogger.print(" [x] Saved Termination Request '" + savedRequest); return ContractTerminationResponse.builder() .withRequestId(savedRequest.getRequestId().toString())