Skip to content

Commit

Permalink
Modified the logic of view pending terminations
Browse files Browse the repository at this point in the history
  • Loading branch information
HusseinYasser committed May 16, 2024
1 parent 55f3dd2 commit 0a604dc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.workup.contracts.logger.ContractsLogger;
import com.workup.contracts.logger.LoggingLevel;
import com.workup.contracts.models.TerminationRequest;
import com.workup.shared.commands.contracts.TerminationRequest;
import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest;
import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse;
import com.workup.shared.enums.HttpStatusCode;
import com.workup.shared.enums.contracts.TerminationRequestStatus;
import java.util.List;

public class GetPendingTerminationsCommand
Expand All @@ -15,8 +16,21 @@ public class GetPendingTerminationsCommand
public GetPendingTerminationsResponse Run(GetPendingTerminationsRequest request) {

try {
@SuppressWarnings("unchecked")
List<TerminationRequest> terminationsList =
terminationRequestRepository.findByContractId(request.getContractId());
(List<TerminationRequest>)
terminationRequestRepository
.findByContractIdAndStatus(
request.getContractId(), TerminationRequestStatus.PENDING)
.stream()
.map(
req ->
TerminationRequest.builder()
.withRequesterId(req.getRequesterId())
.withRequestId(String.valueOf(req.getRequestId()))
.withContractId(req.getContractId())
.withReason(req.getReason())
.build());

if (terminationsList.isEmpty()) {
return GetPendingTerminationsResponse.builder()
Expand All @@ -25,14 +39,8 @@ public GetPendingTerminationsResponse Run(GetPendingTerminationsRequest request)
.build();
}

TerminationRequest terminationRequest = terminationsList.getFirst();

return GetPendingTerminationsResponse.builder()
.withRequestId(terminationRequest.getRequestId().toString())
.withRequesterId(terminationRequest.getRequesterId())
.withContractId(terminationRequest.getContractId())
.withReason(terminationRequest.getReason())
.withStatus(terminationRequest.getStatus())
.withTerminationRequests(terminationsList)
.withStatusCode(HttpStatusCode.OK)
.withErrorMessage("")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
public interface TerminationRequestRepository
extends CassandraRepository<TerminationRequest, UUID> {
@AllowFiltering
List<TerminationRequest> findByRequesterIdAndContractIdAndStatus(
String requesterId, String contractId, TerminationRequestStatus status);
List<TerminationRequest> findByContractIdAndStatus(
String contractId, TerminationRequestStatus status);

@Query("SELECT * FROM contracts_data.termination_requests WHERE contractid = ?0")
List<TerminationRequest> findByContractId(String contractId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.workup.shared.commands.contracts;

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

@Getter
@Setter
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class TerminationRequest {

private final String requestId;

private final String contractId;
private final String requesterId;
private final String reason;

private final TerminationRequestStatus status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import com.workup.shared.commands.CommandRequest;
import lombok.Getter;
import lombok.Setter;
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
@Setter
public class GetPendingTerminationsRequest extends CommandRequest {
private final String contractId;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.workup.shared.commands.contracts.responses;

import com.workup.shared.commands.CommandResponse;
import com.workup.shared.enums.contracts.TerminationRequestStatus;
import com.workup.shared.commands.contracts.TerminationRequest;
import java.util.List;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
Expand All @@ -10,11 +11,5 @@
@SuperBuilder(setterPrefix = "with")
@Jacksonized
public class GetPendingTerminationsResponse extends CommandResponse {
private final String requestId;

private final String contractId;
private final String requesterId;
private final String reason;

private final TerminationRequestStatus status;
private List<TerminationRequest> terminationRequests;
}

0 comments on commit 0a604dc

Please sign in to comment.