-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4ffacf
commit fa6802c
Showing
5 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 124 additions & 1 deletion
125
webserver/src/main/java/com/workup/webserver/controller/ContractsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,131 @@ | ||
package com.workup.webserver.controller; | ||
|
||
import com.workup.shared.commands.contracts.requests.ContractTerminationRequest; | ||
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.requests.HandleTerminationRequest; | ||
import com.workup.shared.commands.contracts.requests.ProgressMilestoneRequest; | ||
import com.workup.shared.commands.contracts.requests.ViewContractMilestonesRequest; | ||
import com.workup.shared.commands.contracts.responses.ContractTerminationResponse; | ||
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; | ||
import com.workup.shared.commands.contracts.responses.HandleTerminationResponse; | ||
import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; | ||
import com.workup.shared.commands.contracts.responses.ViewContractMilestonesResponse; | ||
import com.workup.shared.enums.ServiceQueueNames; | ||
import org.springframework.amqp.core.AmqpTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestAttribute; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/contracts") | ||
public class ContractsController {} | ||
public class ContractsController { | ||
@Autowired AmqpTemplate rabbitTemplate; | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<GetContractResponse> getContractById( | ||
@PathVariable String id, @RequestAttribute(name = "userId") String userId) { | ||
GetContractRequest request = | ||
GetContractRequest.builder().withContractId(id).withUserId(userId).build(); | ||
GetContractResponse response = | ||
(GetContractResponse) | ||
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
return ResponseEntity.status(response.getStatusCode().getValue()).body(response); | ||
} | ||
|
||
@GetMapping("/{id}/milestones") | ||
public ResponseEntity<ViewContractMilestonesResponse> viewContractMilestones( | ||
@PathVariable String id, @RequestAttribute(name = "userId") String userId) { | ||
ViewContractMilestonesRequest request = | ||
ViewContractMilestonesRequest.builder().withContractId(id).withUserId(userId).build(); | ||
ViewContractMilestonesResponse response = | ||
(ViewContractMilestonesResponse) | ||
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
return ResponseEntity.status(response.getStatusCode().getValue()).body(response); | ||
} | ||
|
||
@GetMapping("/milestones/{id}") | ||
public ResponseEntity<GetMilestoneResponse> getMilestoneById( | ||
@PathVariable String id, @RequestAttribute(name = "userId") String userId) { | ||
GetMilestoneRequest request = | ||
GetMilestoneRequest.builder().withMilestoneId(id).withUserId(userId).build(); | ||
GetMilestoneResponse response = | ||
(GetMilestoneResponse) | ||
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
return ResponseEntity.status(response.getStatusCode().getValue()).body(response); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<GetPendingTerminationsResponse> getContractTermination( | ||
@PathVariable String id, @RequestAttribute(name = "userId") String userId) { | ||
GetPendingTerminationsRequest request = | ||
GetPendingTerminationsRequest.builder().withContractId(id).withUserId(userId).build(); | ||
GetPendingTerminationsResponse response = | ||
(GetPendingTerminationsResponse) | ||
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
return ResponseEntity.status(response.getStatusCode().getValue()).body(response); | ||
} | ||
|
||
@PostMapping("/{id}/termination/handle") | ||
public ResponseEntity<ContractTerminationResponse> submitTerminationRequest( | ||
@RequestBody ContractTerminationRequest request, | ||
@PathVariable String id, | ||
@RequestAttribute(name = "userId") String userId) { | ||
request.setUserId(userId); | ||
request.setContractId(id); | ||
ContractTerminationResponse response = | ||
(ContractTerminationResponse) | ||
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
return ResponseEntity.status(response.getStatusCode().getValue()).body(response); | ||
} | ||
|
||
@PostMapping("/milestones/{id}/evaluate") | ||
public ResponseEntity<EvaluateMilestoneResponse> evaluateMilestone( | ||
@RequestBody EvaluateMilestoneRequest request, | ||
@PathVariable String id, | ||
@RequestAttribute(name = "userId") String userId) { | ||
request.setUserId(userId); | ||
request.setMilestoneId(id); | ||
EvaluateMilestoneResponse response = | ||
(EvaluateMilestoneResponse) | ||
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
return ResponseEntity.status(response.getStatusCode().getValue()).body(response); | ||
} | ||
|
||
@PostMapping("/terminations/{id}/handle") | ||
public ResponseEntity<HandleTerminationResponse> handleTerminationRequest( | ||
@RequestBody HandleTerminationRequest request, | ||
@PathVariable String id, | ||
@RequestAttribute(name = "userId") String userId) { | ||
request.setUserId(userId); | ||
request.setContractTerminationRequestId(id); | ||
HandleTerminationResponse response = | ||
(HandleTerminationResponse) | ||
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
return ResponseEntity.status(response.getStatusCode().getValue()).body(response); | ||
} | ||
|
||
@PostMapping("/milestones/{id}/progress") | ||
public ResponseEntity<ProgressMilestoneResponse> progressMilestone( | ||
@RequestBody ProgressMilestoneRequest request, | ||
@PathVariable String id, | ||
@RequestAttribute(name = "userId") String userId) { | ||
request.setUserId(userId); | ||
request.setMilestoneId(id); | ||
ProgressMilestoneResponse response = | ||
(ProgressMilestoneResponse) | ||
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
return ResponseEntity.status(response.getStatusCode().getValue()).body(response); | ||
} | ||
} |