Skip to content

Commit ca25102

Browse files
Tess Stoddardtessstoddard
authored andcommitted
feat: add p2p transfer accounts endpoint
1 parent 5445421 commit ca25102

4 files changed

Lines changed: 128 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.mx.path.model.mdx.accessor.p2p_transfer;
2+
3+
import com.mx.path.core.common.accessor.API;
4+
import com.mx.path.core.common.accessor.AccessorMethodNotImplementedException;
5+
import com.mx.path.core.common.gateway.GatewayAPI;
6+
import com.mx.path.core.common.gateway.GatewayClass;
7+
import com.mx.path.gateway.accessor.Accessor;
8+
import com.mx.path.gateway.accessor.AccessorResponse;
9+
import com.mx.path.model.mdx.model.MdxList;
10+
import com.mx.path.model.mdx.model.account.Account;
11+
12+
/**
13+
* Accessor base for P2P transfer account operations
14+
*/
15+
@GatewayClass
16+
@API(specificationUrl = "https://developer.mx.com/drafts/mdx/p2p_transfer/index.html#p2p-transfer-accounts")
17+
public class AccountBaseAccessor extends Accessor {
18+
public AccountBaseAccessor() {
19+
}
20+
21+
/**
22+
* Lists all p2p transfer accounts
23+
*
24+
* @return MdxList<Account>
25+
*/
26+
@GatewayAPI
27+
@API(description = "Lists all accounts for P2P transfers")
28+
public AccessorResponse<MdxList<Account>> list() {
29+
throw new AccessorMethodNotImplementedException();
30+
}
31+
}

mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/P2PTransferBaseAccessor.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,32 @@
1515
@GatewayClass
1616
@API(specificationUrl = "https://developer.mx.com/drafts/mdx/p2p_transfer/index.html#p2p-transfers")
1717
public class P2PTransferBaseAccessor extends Accessor {
18+
@GatewayAPI
19+
@Getter(AccessLevel.PROTECTED)
20+
private AccountBaseAccessor accounts;
21+
1822
@GatewayAPI
1923
@Getter(AccessLevel.PROTECTED)
2024
private DurationBaseAccessor durations;
2125

26+
/**
27+
* Accessor for account operations
28+
*
29+
* @return accessor
30+
*/
31+
@API
32+
public AccountBaseAccessor accounts() {
33+
return accounts;
34+
}
35+
36+
/**
37+
* Sets account accessor
38+
* @param accounts
39+
*/
40+
public void setAccounts(AccountBaseAccessor accounts) {
41+
this.accounts = accounts;
42+
}
43+
2244
/**
2345
* Accessor for duration operations
2446
*
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.mx.path.model.mdx.web.controller;
2+
3+
import com.mx.path.gateway.accessor.AccessorResponse;
4+
import com.mx.path.model.mdx.model.MdxList;
5+
import com.mx.path.model.mdx.model.account.Account;
6+
7+
import org.springframework.http.HttpStatus;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestMethod;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@RestController
14+
@RequestMapping(value = "{clientId}", produces = BaseController.MDX_MEDIA)
15+
public class P2PTransferAccountsController extends BaseController {
16+
@RequestMapping(value = "/users/{userId}/accounts/p2p_transfer", method = RequestMethod.GET)
17+
public final ResponseEntity<MdxList<Account>> list() {
18+
AccessorResponse<MdxList<Account>> response = gateway().p2pTransfers().accounts().list();
19+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
20+
}
21+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.mx.path.model.mdx.web.controller
2+
3+
import static org.mockito.Mockito.doReturn
4+
import static org.mockito.Mockito.mock
5+
import static org.mockito.Mockito.spy
6+
import static org.mockito.Mockito.verify
7+
8+
import com.mx.path.gateway.accessor.AccessorResponse
9+
import com.mx.path.gateway.api.Gateway
10+
import com.mx.path.gateway.api.p2p_transfer.AccountGateway
11+
import com.mx.path.gateway.api.p2p_transfer.P2PTransferGateway
12+
import com.mx.path.model.mdx.model.MdxList
13+
import com.mx.path.model.mdx.model.account.Account
14+
15+
import org.springframework.http.HttpStatus
16+
17+
import spock.lang.Specification
18+
19+
class P2PTransferAccountsControllerTest extends Specification {
20+
P2PTransferAccountsController subject
21+
Gateway gateway
22+
P2PTransferGateway p2pTransferGateway
23+
AccountGateway accountGateway
24+
25+
def setup() {
26+
subject = new P2PTransferAccountsController()
27+
p2pTransferGateway = mock(P2PTransferGateway)
28+
accountGateway = mock(AccountGateway)
29+
30+
doReturn(accountGateway).when(p2pTransferGateway).accounts()
31+
gateway = spy(Gateway.builder().clientId("client-1234").p2pTransfers(p2pTransferGateway).build())
32+
}
33+
34+
def cleanup() {
35+
BaseController.clearGateway()
36+
}
37+
38+
def "list interacts with gateway"() {
39+
given:
40+
BaseController.setGateway(gateway)
41+
def accounts = new MdxList().tap {
42+
add(new Account())
43+
}
44+
doReturn(new AccessorResponse<MdxList<Account>>().withResult(accounts)).when(accountGateway).list()
45+
46+
when:
47+
def result = subject.list()
48+
49+
then:
50+
HttpStatus.OK == result.statusCode
51+
result.body == accounts
52+
verify(accountGateway).list() || true
53+
}
54+
}

0 commit comments

Comments
 (0)