Skip to content
Snippets Groups Projects
Commit f9c75433 authored by Filip Piták's avatar Filip Piták
Browse files

Add endpoints for processes and manual trigger of scheduled payments

parent ec2874fa
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,28 @@ paths: ...@@ -62,6 +62,28 @@ paths:
'404': '404':
description: Resource or process by UUID not found description: Resource or process by UUID not found
/transaction/v1/scheduled/trigger:
post:
tags:
- Transaction
operationId: executeSchedulePayments
summary: Trigger scheduled payments
description: |
Manual execution of scheduled payments for a given date.
The input date is optional, if none is provided then the current day is used.
parameters:
- in: query
name: date
schema:
type: string
format: date
required: false
responses:
'200':
description: Executed
'500':
description: Failure
/transaction/v1/revert: /transaction/v1/revert:
post: post:
tags: tags:
...@@ -89,6 +111,120 @@ paths: ...@@ -89,6 +111,120 @@ paths:
description: Process found by UUID but not in expected state (PROCESSED) description: Process found by UUID but not in expected state (PROCESSED)
'404': '404':
description: Resource or process by UUID not found description: Resource or process by UUID not found
/process/v1/{uuid}/status:
get:
tags:
- Process
operationId: getProcessStatus
summary: Process Status
description: |
Method finds an existing process for a transaction request, returning all information about it's state
and further information regarding errors.
parameters:
- in: path
name: uuid
required: true
schema:
type: string
format: uuid
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ProcessStatusDto'
'404':
description: Process by UUID not found
/processes/v1/{status}:
get:
tags:
- Process
operationId: getProcessesOfState
summary: Processes in a state
description: Find a collection of Processes in a defined state
parameters:
- in: path
name: status
required: true
schema:
$ref: '#/components/schemas/StatusDto'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ProcessStatusListDto'
/processes/v1/resolve/threshold:
get:
tags:
- Process
operationId: getDefaultThreshold
summary: Process resolution date threshold
description: Get the default threshold used by the system to mark unresolved processes as failed
responses:
'200':
description: OK
content:
application/json:
schema:
type: string
format: date
/processes/v1/resolve:
get:
tags:
- Process
operationId: getUnresolvedProcesses
summary: Unresolved processes
description: |
Get a collection of unresolved processes to a given date. If no date is provided, the default threshold is used.
parameters:
- in: query
name: date
schema:
type: string
format: date
required: false
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ProcessStatusListDto'
patch:
tags:
- Process
operationId: resolveProcesses
summary: Fail unresolved processes
description: |
Mark unresolved processes as failed. The input date marks as the threshold below which processes
in the state CREATED or PENDING shall be marked as resolved by failure. The provided date must be
before the current day. If no date is provided, the default threshold is used.
Method returns a collection of Process UUID's, which have been resolved.
parameters:
- in: query
name: date
schema:
type: string
format: date
required: false
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
type: string
format: uuid
components: components:
schemas: schemas:
...@@ -157,4 +293,34 @@ components: ...@@ -157,4 +293,34 @@ components:
allOf: allOf:
- $ref: '#/components/schemas/ProcessDto' - $ref: '#/components/schemas/ProcessDto'
- $ref: '#/components/schemas/TransactionDto' - $ref: '#/components/schemas/TransactionDto'
\ No newline at end of file StatusDetailDto:
type: object
properties:
created:
type: string
format: date-time
status:
$ref: '#/components/schemas/StatusDto'
information:
type: string
ProcessStatusDto:
type: object
properties:
identifier:
type: string
format: uuid
status:
$ref: '#/components/schemas/StatusDto'
ProcessStatusListDto:
type: object
properties:
when:
type: string
format: date-time
processes:
type: array
items:
$ref: '#/components/schemas/ProcessStatusDto'
\ No newline at end of file
package cz.muni.pa165.banking.application.controller;
import cz.muni.pa165.banking.transaction.processor.ProcessApi;
import cz.muni.pa165.banking.transaction.processor.dto.ProcessStatusDto;
import cz.muni.pa165.banking.transaction.processor.dto.ProcessStatusListDto;
import cz.muni.pa165.banking.transaction.processor.dto.StatusDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
@RestController
public class ProcessController implements ProcessApi {
@Override
public ResponseEntity<LocalDate> getDefaultThreshold() {
return null;
}
@Override
public ResponseEntity<ProcessStatusDto> getProcessStatus(UUID uuid) {
return null;
}
@Override
public ResponseEntity<ProcessStatusListDto> getProcessesOfState(StatusDto status) {
return null;
}
@Override
public ResponseEntity<ProcessStatusListDto> getUnresolvedProcesses(LocalDate date) {
return null;
}
@Override
public ResponseEntity<List<UUID>> resolveProcesses(LocalDate date) {
return null;
}
}
package cz.muni.pa165.banking.application.controller; package cz.muni.pa165.banking.application.controller;
import cz.muni.pa165.banking.application.facade.TransactionFacade; import cz.muni.pa165.banking.application.facade.TransactionFacade;
import cz.muni.pa165.banking.application.service.ScheduledPaymentService;
import cz.muni.pa165.banking.transaction.processor.TransactionApi; import cz.muni.pa165.banking.transaction.processor.TransactionApi;
import cz.muni.pa165.banking.transaction.processor.dto.ProcessDetailDto; import cz.muni.pa165.banking.transaction.processor.dto.ProcessDetailDto;
import cz.muni.pa165.banking.transaction.processor.dto.ProcessDto; import cz.muni.pa165.banking.transaction.processor.dto.ProcessDto;
...@@ -8,15 +9,19 @@ import cz.muni.pa165.banking.transaction.processor.dto.TransactionDto; ...@@ -8,15 +9,19 @@ import cz.muni.pa165.banking.transaction.processor.dto.TransactionDto;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.UUID; import java.util.UUID;
@RestController @RestController
public class TransactionController implements TransactionApi { public class TransactionController implements TransactionApi {
private final TransactionFacade facade; private final TransactionFacade facade;
private final ScheduledPaymentService scheduledPaymentService;
public TransactionController(TransactionFacade facade) { public TransactionController(TransactionFacade facade, ScheduledPaymentService scheduledPaymentService) {
this.facade = facade; this.facade = facade;
this.scheduledPaymentService = scheduledPaymentService;
} }
...@@ -38,4 +43,12 @@ public class TransactionController implements TransactionApi { ...@@ -38,4 +43,12 @@ public class TransactionController implements TransactionApi {
return ResponseEntity.ok(revertingProcess); return ResponseEntity.ok(revertingProcess);
} }
@Override
public ResponseEntity<Void> executeSchedulePayments(LocalDate date) {
if (date == null) {
date = LocalDate.now();
}
scheduledPaymentService.executeScheduledPayments(date);
return ResponseEntity.ok(null);
}
} }
...@@ -47,9 +47,13 @@ public class ScheduledPaymentService { ...@@ -47,9 +47,13 @@ public class ScheduledPaymentService {
} }
@Scheduled(cron = "${scheduled-payments.cron.expression}") @Scheduled(cron = "${scheduled-payments.cron.expression}")
public void executeScheduledPayments() { public void autoExecute() {
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
ResponseEntity<ScheduledPaymentsDto> response = accountApi.getScheduledPaymentsOf(now); executeScheduledPayments(now);
}
public void executeScheduledPayments(LocalDate date) {
ResponseEntity<ScheduledPaymentsDto> response = accountApi.getScheduledPaymentsOf(date);
if (!response.getStatusCode().is2xxSuccessful()) { if (!response.getStatusCode().is2xxSuccessful()) {
throw new ServerError("Call to Account Management service unsuccessful."); throw new ServerError("Call to Account Management service unsuccessful.");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment