Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts commands cache implementation #82

Merged
merged 14 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions services/contracts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -36,17 +40,41 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>cassandra</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>rabbitmq</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.16.0</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends CommandRequest, Q extends CommandResponse>
implements Command<T, Q> {

@Setter AmqpTemplate rabbitTemplate;

@Setter ContractRepository contractRepository;

@Setter ContractMilestoneRepository contractMilestoneRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
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;

@Component
public class ContractCommandMap
extends CommandMap<ContractCommand<? extends CommandRequest, ? extends CommandResponse>> {

@Autowired AmqpTemplate rabbitTemplate;
@Autowired ContractRepository contractRepository;

@Autowired ContractMilestoneRepository contractMilestoneRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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<EvaluateMilestoneRequest, EvaluateMilestoneResponse> {

@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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.workup.contracts.commands;


import com.workup.shared.commands.contracts.requests.GetContractRequest;
import com.workup.shared.commands.contracts.responses.GetContractResponse;

public class GetContractCommand extends ContractCommand<GetContractRequest, GetContractResponse> {

@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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.workup.contracts.commands;


import com.workup.shared.commands.contracts.requests.GetMilestoneRequest;
import com.workup.shared.commands.contracts.responses.GetMilestoneResponse;

public class GetMilestoneCommand
extends ContractCommand<GetMilestoneRequest, GetMilestoneResponse> {

@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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.workup.contracts.commands;


import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest;
import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse;

public class GetPendingTerminationsCommand
extends ContractCommand<GetPendingTerminationsRequest, GetPendingTerminationsResponse> {

@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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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<ProgressMilestoneRequest, ProgressMilestoneResponse> {

private ProgressMilestoneResponse isValid(ProgressMilestoneRequest request) {
Optional<ContractMilestone> 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) {
ProgressMilestoneResponse checkerResponse = isValid(request);
if (checkerResponse != null) return checkerResponse;

Optional<ContractMilestone> 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
Kemosalamy marked this conversation as resolved.
Show resolved Hide resolved

// 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.workup.shared.commands.contracts.requests;

import com.workup.shared.commands.CommandRequest;
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.workup.shared.commands.contracts.requests;

import com.workup.shared.commands.CommandRequest;
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.workup.shared.commands.contracts.requests;

import com.workup.shared.commands.CommandRequest;
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
@Getter
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class EvaluatedMilestoneResponse extends CommandResponse {}
public class EvaluateMilestoneResponse extends CommandResponse {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.workup.shared.commands.contracts.responses;

import com.workup.shared.commands.CommandResponse;
import com.workup.shared.enums.contracts.ContractState;
import java.util.List;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@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<String> milestonesIds;
private ContractState status;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.workup.shared.commands.contracts.responses;

import com.workup.shared.commands.CommandResponse;
import com.workup.shared.enums.contracts.TerminationRequestStatus;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@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;
}