Skip to content

Commit 607b09d

Browse files
Tess Stoddardtessstoddard
authored andcommitted
feat!: add managed card alert endpoints
1 parent 961110f commit 607b09d

11 files changed

Lines changed: 308 additions & 37 deletions

File tree

mdx-models/src/main/java/com/mx/path/model/mdx/accessor/account/AccountAlertBaseAccessor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import com.mx.path.gateway.accessor.AccessorResponse;
1010
import com.mx.path.model.mdx.model.MdxList;
1111
import com.mx.path.model.mdx.model.account.Account;
12-
import com.mx.path.model.mdx.model.account.alerts.AccountAlert;
13-
import com.mx.path.model.mdx.model.account.alerts.DeliveryMethod;
12+
import com.mx.path.model.mdx.model.alerts.Alert;
13+
import com.mx.path.model.mdx.model.alerts.DeliveryMethod;
1414

1515
/**
1616
* Accessor for account alert operations
1717
*/
1818
@GatewayClass
19-
@API(description = "Access to account alerts", specificationUrl = "https://developer.mx.com/drafts/mdx/accounts/#accounts-alerts")
19+
@API(description = "Access to account alerts", specificationUrl = "https://developer.mx.com/drafts/mdx/accounts/#alerts")
2020
public abstract class AccountAlertBaseAccessor extends Accessor {
2121

2222
public AccountAlertBaseAccessor() {
@@ -40,7 +40,7 @@ public AccountAlertBaseAccessor(AccessorConfiguration configuration) {
4040
*/
4141
@GatewayAPI
4242
@API(description = "Get account alert")
43-
public AccessorResponse<AccountAlert> get(String accountId, String alertId) {
43+
public AccessorResponse<Alert> get(String accountId, String alertId) {
4444
throw new AccessorMethodNotImplementedException();
4545
}
4646

@@ -52,7 +52,7 @@ public AccessorResponse<AccountAlert> get(String accountId, String alertId) {
5252
*/
5353
@GatewayAPI
5454
@API(description = "List account alerts")
55-
public AccessorResponse<MdxList<AccountAlert>> list(String accountId) {
55+
public AccessorResponse<MdxList<Alert>> list(String accountId) {
5656
throw new AccessorMethodNotImplementedException();
5757
}
5858

@@ -65,7 +65,7 @@ public AccessorResponse<MdxList<AccountAlert>> list(String accountId) {
6565
*/
6666
@GatewayAPI
6767
@API(description = "Update an account alert")
68-
public AccessorResponse<AccountAlert> update(String accountId, AccountAlert accountAlert) {
68+
public AccessorResponse<Alert> update(String accountId, Alert accountAlert) {
6969
throw new AccessorMethodNotImplementedException();
7070
}
7171

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.mx.path.model.mdx.accessor.managed_card;
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.alerts.Alert;
11+
import com.mx.path.model.mdx.model.alerts.DeliveryMethod;
12+
import com.mx.path.model.mdx.model.managed_cards.ManagedCard;
13+
14+
/**
15+
* Accessor for managed card alert operations
16+
*/
17+
@GatewayClass
18+
@API(description = "Access to managed card alerts", specificationUrl = "https://developer.mx.com/drafts/mdx/managed_cards/#alerts")
19+
public abstract class ManagedCardAlertBaseAccessor extends Accessor {
20+
public ManagedCardAlertBaseAccessor() {
21+
}
22+
23+
/**
24+
* Get a managed card alert
25+
*
26+
* @param cardId
27+
* @param alertId
28+
* @return
29+
*/
30+
@GatewayAPI
31+
@API(description = "Get managed card alert")
32+
public AccessorResponse<Alert> get(String cardId, String alertId) {
33+
throw new AccessorMethodNotImplementedException();
34+
}
35+
36+
/**
37+
* List managed card alerts
38+
*
39+
* @param cardId
40+
* @return
41+
*/
42+
@GatewayAPI
43+
@API(description = "List managed card alerts")
44+
public AccessorResponse<MdxList<Alert>> list(String cardId) {
45+
throw new AccessorMethodNotImplementedException();
46+
}
47+
48+
/**
49+
* Update a managed card alert
50+
*
51+
* @param cardId
52+
* @param alert
53+
* @return
54+
*/
55+
@GatewayAPI
56+
@API(description = "Update a managed card alert")
57+
public AccessorResponse<Alert> update(String cardId, Alert alert) {
58+
throw new AccessorMethodNotImplementedException();
59+
}
60+
61+
/**
62+
* List delivery methods
63+
*
64+
* @param cardId
65+
* @param alertId
66+
* @return
67+
*/
68+
@GatewayAPI
69+
@API(description = "List delivery methods")
70+
public AccessorResponse<MdxList<DeliveryMethod>> deliveryMethods(String cardId, String alertId) {
71+
throw new AccessorMethodNotImplementedException();
72+
}
73+
74+
/**
75+
* List managed cards eligible for alerts
76+
*
77+
* @return
78+
*/
79+
@GatewayAPI
80+
@API(description = "List managed cards eligible for alerts")
81+
public AccessorResponse<MdxList<ManagedCard>> cards() {
82+
throw new AccessorMethodNotImplementedException();
83+
}
84+
}

mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardBaseAccessor.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.mx.path.model.mdx.accessor.managed_card;
22

3+
import lombok.AccessLevel;
4+
import lombok.Getter;
5+
36
import com.mx.path.core.common.accessor.API;
47
import com.mx.path.core.common.accessor.AccessorMethodNotImplementedException;
58
import com.mx.path.core.common.gateway.GatewayAPI;
@@ -19,6 +22,9 @@
1922
@GatewayClass
2023
@API(specificationUrl = "https://developer.mx.com/drafts/mdx/managed_cards/#mdx-managed-cards")
2124
public abstract class ManagedCardBaseAccessor extends Accessor {
25+
@GatewayAPI
26+
@Getter(AccessLevel.PROTECTED)
27+
private ManagedCardAlertBaseAccessor alerts;
2228

2329
public ManagedCardBaseAccessor() {
2430
}
@@ -170,4 +176,22 @@ public AccessorResponse<ManagedCard> update(String id, ManagedCard card) {
170176
public AccessorResponse<NotificationPreferences> updateNotificationPreferences(String id, NotificationPreferences notificationPreferences) {
171177
throw new AccessorMethodNotImplementedException();
172178
}
179+
180+
/**
181+
* Accessor for managed card alerts
182+
*
183+
* @return accessor
184+
*/
185+
@API
186+
public ManagedCardAlertBaseAccessor alerts() {
187+
return alerts;
188+
}
189+
190+
/**
191+
* Sets managed card alert accessor
192+
* @param alerts
193+
*/
194+
public void setAlerts(ManagedCardAlertBaseAccessor alerts) {
195+
this.alerts = alerts;
196+
}
173197
}

mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
import com.mx.path.model.mdx.model.account.StopPaymentReason;
1919
import com.mx.path.model.mdx.model.account.Transaction;
2020
import com.mx.path.model.mdx.model.account.TransactionsPage;
21-
import com.mx.path.model.mdx.model.account.alerts.AccountAlert;
22-
import com.mx.path.model.mdx.model.account.alerts.DeliveryMethod;
2321
import com.mx.path.model.mdx.model.ach_transfer.AchAccount;
2422
import com.mx.path.model.mdx.model.ach_transfer.AchScheduledTransfer;
2523
import com.mx.path.model.mdx.model.ach_transfer.AchTransfer;
24+
import com.mx.path.model.mdx.model.alerts.Alert;
25+
import com.mx.path.model.mdx.model.alerts.DeliveryMethod;
2626
import com.mx.path.model.mdx.model.authorization.Authorization;
2727
import com.mx.path.model.mdx.model.check.CheckImage;
2828
import com.mx.path.model.mdx.model.credit_report.CreditReport;
@@ -285,8 +285,8 @@ public static void registerResources(GsonBuilder builder) {
285285
registerPaymentsModels(builder);
286286
// Register multistage transfer models
287287
registerMultistageTransferModels(builder);
288-
// Register account alert models
289-
registerAccountAlertModels(builder);
288+
// Register alert models
289+
registerAlertModels(builder);
290290
// Register product models
291291
registerProductModels(builder);
292292
// Register P2P transfer models
@@ -446,10 +446,10 @@ private static void registerMultistageTransferModels(GsonBuilder builder) {
446446
}.getType(), new ModelWrappableSerializer("repayments"));
447447
}
448448

449-
private static void registerAccountAlertModels(GsonBuilder builder) {
450-
// AccountAlert
451-
builder.registerTypeAdapter(AccountAlert.class, new ModelWrappableSerializer("alert"));
452-
builder.registerTypeAdapter(new TypeToken<MdxList<AccountAlert>>() {
449+
private static void registerAlertModels(GsonBuilder builder) {
450+
// Alert
451+
builder.registerTypeAdapter(Alert.class, new ModelWrappableSerializer("alert"));
452+
builder.registerTypeAdapter(new TypeToken<MdxList<Alert>>() {
453453
}.getType(), new ModelWrappableSerializer("alerts"));
454454
// DeliveryMethod
455455
builder.registerTypeAdapter(new TypeToken<MdxList<DeliveryMethod>>() {

mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/AccountAlert.java renamed to mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/Alert.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.mx.path.model.mdx.model.account.alerts;
1+
package com.mx.path.model.mdx.model.alerts;
22

33
import java.util.List;
44

@@ -10,7 +10,7 @@
1010

1111
@EqualsAndHashCode(callSuper = true)
1212
@Data
13-
public class AccountAlert extends MdxBase<AccountAlert> {
13+
public class Alert extends MdxBase<Alert> {
1414
private List<Challenge> challenges;
1515
private List<AlertCriteria> criteria;
1616
private List<String> deliveryMethodIds;

mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/AlertCriteria.java renamed to mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/AlertCriteria.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.mx.path.model.mdx.model.account.alerts;
1+
package com.mx.path.model.mdx.model.alerts;
22

33
import lombok.Data;
44
import lombok.EqualsAndHashCode;

mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/DeliveryMethod.java renamed to mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/DeliveryMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.mx.path.model.mdx.model.account.alerts;
1+
package com.mx.path.model.mdx.model.alerts;
22

33
import lombok.Data;
44
import lombok.EqualsAndHashCode;

mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/AccountAlertsController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.mx.path.gateway.accessor.AccessorResponse;
44
import com.mx.path.model.mdx.model.MdxList;
55
import com.mx.path.model.mdx.model.account.Account;
6-
import com.mx.path.model.mdx.model.account.alerts.AccountAlert;
7-
import com.mx.path.model.mdx.model.account.alerts.DeliveryMethod;
6+
import com.mx.path.model.mdx.model.alerts.Alert;
7+
import com.mx.path.model.mdx.model.alerts.DeliveryMethod;
88

99
import org.springframework.http.HttpStatus;
1010
import org.springframework.http.ResponseEntity;
@@ -18,23 +18,23 @@
1818
@RequestMapping(value = "{clientId}")
1919
public class AccountAlertsController extends BaseController {
2020
@RequestMapping(value = "/users/{userId}/accounts/{accountId}/alerts/{id}", method = RequestMethod.GET)
21-
public final ResponseEntity<AccountAlert> getAlert(@PathVariable("accountId") String accountId, @PathVariable("id") String alertId) {
21+
public final ResponseEntity<Alert> getAlert(@PathVariable("accountId") String accountId, @PathVariable("id") String alertId) {
2222
ensureFeature("accounts");
23-
AccessorResponse<AccountAlert> response = gateway().accounts().accountAlerts().get(accountId, alertId);
23+
AccessorResponse<Alert> response = gateway().accounts().accountAlerts().get(accountId, alertId);
2424
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
2525
}
2626

2727
@RequestMapping(value = "/users/{userId}/accounts/{accountId}/alerts", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA)
28-
public final ResponseEntity<MdxList<AccountAlert>> getAlertList(@PathVariable("accountId") String accountId) {
28+
public final ResponseEntity<MdxList<Alert>> getAlertList(@PathVariable("accountId") String accountId) {
2929
ensureFeature("accounts");
30-
AccessorResponse<MdxList<AccountAlert>> response = gateway().accounts().accountAlerts().list(accountId);
30+
AccessorResponse<MdxList<Alert>> response = gateway().accounts().accountAlerts().list(accountId);
3131
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
3232
}
3333

3434
@RequestMapping(value = "/users/{userId}/accounts/{accountId}/alerts/{id}", method = RequestMethod.PUT, consumes = BaseController.MDX_MEDIA)
35-
public final ResponseEntity<AccountAlert> updateAlert(@PathVariable("accountId") String accountId, @RequestBody AccountAlert accountAlert) {
35+
public final ResponseEntity<Alert> updateAlert(@PathVariable("accountId") String accountId, @RequestBody Alert accountAlert) {
3636
ensureFeature("accounts");
37-
AccessorResponse<AccountAlert> response = gateway().accounts().accountAlerts().update(accountId, accountAlert);
37+
AccessorResponse<Alert> response = gateway().accounts().accountAlerts().update(accountId, accountAlert);
3838
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
3939
}
4040

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.alerts.Alert;
6+
import com.mx.path.model.mdx.model.alerts.DeliveryMethod;
7+
import com.mx.path.model.mdx.model.managed_cards.ManagedCard;
8+
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.PathVariable;
12+
import org.springframework.web.bind.annotation.RequestBody;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RequestMethod;
15+
import org.springframework.web.bind.annotation.RestController;
16+
17+
@RestController
18+
@RequestMapping(value = "{clientId}")
19+
public class ManagedCardAlertsController extends BaseController {
20+
@RequestMapping(value = "/users/{userId}/managed_cards/{cardId}/alerts/{id}", method = RequestMethod.GET)
21+
public final ResponseEntity<Alert> getAlert(@PathVariable("cardId") String cardId, @PathVariable("id") String alertId) {
22+
AccessorResponse<Alert> response = gateway().managedCards().alerts().get(cardId, alertId);
23+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
24+
}
25+
26+
@RequestMapping(value = "/users/{userId}/managed_cards/{cardId}/alerts", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA)
27+
public final ResponseEntity<MdxList<Alert>> getAlertList(@PathVariable("cardId") String cardId) {
28+
AccessorResponse<MdxList<Alert>> response = gateway().managedCards().alerts().list(cardId);
29+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
30+
}
31+
32+
@RequestMapping(value = "/users/{userId}/managed_cards/{cardId}/alerts/{id}", method = RequestMethod.PUT, consumes = BaseController.MDX_MEDIA)
33+
public final ResponseEntity<Alert> updateAlert(@PathVariable("cardId") String cardId, @RequestBody Alert alert) {
34+
AccessorResponse<Alert> response = gateway().managedCards().alerts().update(cardId, alert);
35+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
36+
}
37+
38+
@RequestMapping(value = "/users/{userId}/managed_cards/{cardId}/alerts/{id}/delivery_methods", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA)
39+
public final ResponseEntity<MdxList<DeliveryMethod>> getDeliveryMethods(@PathVariable("cardId") String cardId, @PathVariable("id") String alertId) {
40+
AccessorResponse<MdxList<DeliveryMethod>> response = gateway().managedCards().alerts().deliveryMethods(cardId, alertId);
41+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
42+
}
43+
44+
@RequestMapping(value = "/users/{userId}/managed_cards/alert", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA)
45+
public final ResponseEntity<MdxList<ManagedCard>> getCards() {
46+
AccessorResponse<MdxList<ManagedCard>> response = gateway().managedCards().alerts().cards();
47+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
48+
}
49+
}

mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/AccountAlertsControllerTest.groovy

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import com.mx.path.gateway.api.account.AccountAlertGateway
1010
import com.mx.path.gateway.api.account.AccountGateway
1111
import com.mx.path.model.mdx.model.MdxList
1212
import com.mx.path.model.mdx.model.account.Account
13-
import com.mx.path.model.mdx.model.account.alerts.AccountAlert
14-
import com.mx.path.model.mdx.model.account.alerts.DeliveryMethod
15-
16-
import org.springframework.http.HttpStatus
13+
import com.mx.path.model.mdx.model.alerts.Alert
14+
import com.mx.path.model.mdx.model.alerts.DeliveryMethod
1715

1816
import spock.lang.Specification
1917

@@ -43,10 +41,10 @@ class AccountAlertsControllerTest extends Specification {
4341
given:
4442
def accountId = "account-id"
4543
def alertId = "alert-id"
46-
def accountAlert = new AccountAlert()
44+
def accountAlert = new Alert()
4745

4846
when:
49-
doReturn(new AccessorResponse<AccountAlert>().withResult(accountAlert)).when(accountAlertGateway).get(accountId, alertId)
47+
doReturn(new AccessorResponse<Alert>().withResult(accountAlert)).when(accountAlertGateway).get(accountId, alertId)
5048
def response = subject.getAlert(accountId, alertId)
5149

5250
then:
@@ -57,11 +55,11 @@ class AccountAlertsControllerTest extends Specification {
5755
def "getAlertList interacts with gateway"() {
5856
given:
5957
def accountId = "account-id"
60-
def alerts = new MdxList<AccountAlert>()
61-
alerts.add(new AccountAlert())
58+
def alerts = new MdxList<Alert>()
59+
alerts.add(new Alert())
6260

6361
when:
64-
doReturn(new AccessorResponse<MdxList<AccountAlert>>().withResult(alerts)).when(accountAlertGateway).list(accountId)
62+
doReturn(new AccessorResponse<MdxList<Alert>>().withResult(alerts)).when(accountAlertGateway).list(accountId)
6563
def response = subject.getAlertList(accountId)
6664

6765
then:
@@ -72,10 +70,10 @@ class AccountAlertsControllerTest extends Specification {
7270
def "updateAlert interacts with gateway"() {
7371
given:
7472
def accountId = "account-id"
75-
def accountAlert = new AccountAlert()
73+
def accountAlert = new Alert()
7674

7775
when:
78-
doReturn(new AccessorResponse<AccountAlert>().withResult(accountAlert)).when(accountAlertGateway).update(accountId, accountAlert)
76+
doReturn(new AccessorResponse<Alert>().withResult(accountAlert)).when(accountAlertGateway).update(accountId, accountAlert)
7977
def response = subject.updateAlert(accountId, accountAlert)
8078

8179
then:

0 commit comments

Comments
 (0)