Skip to content

Commit

Permalink
Merge pull request #159 from meniga/feature/add-new-add-comment-method
Browse files Browse the repository at this point in the history
Add addComments method to MenigaTransaction
  • Loading branch information
tomrozb authored Apr 22, 2020
2 parents 93e190d + c2cae36 commit 7c0c792
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ public void shouldFetchMultipleTransactionsWithFiltersList() throws Exception {
.hasMerchantsIncluded();
}

@Test
public void shouldAddCommentToTransactions() throws InterruptedException {
server.enqueue(mockResponse("addComments.json"));

List<Long> transactionIds = newArrayList(1L, 2L);
Task<List<MenigaComment>> task = MenigaTransaction.addComments(transactionIds, "newComment").getTask();

assertThat(task).isSuccessful();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getPath()).isEqualTo("/v1/transactions/comments");
assertThat(recordedRequest.getMethod()).isEqualTo("POST");
List<MenigaComment> comments = task.getResult();
MenigaComment firstComment = comments.get(0);
assertThat(firstComment.id).isEqualTo(20409);
assertThat(firstComment.comment).isEqualTo("newComment");
assertThat(firstComment.personId).isEqualTo(1180);
MenigaComment secondComment = comments.get(1);
assertThat(secondComment.id).isEqualTo(20410);
assertThat(secondComment.comment).isEqualTo("newComment");
assertThat(secondComment.personId).isEqualTo(1180);
}

private Condition<RecordedRequest> withPath(final String expectedPath) {
return new Condition<RecordedRequest>(expectedPath) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1196,8 +1196,8 @@ public static Result<MenigaTransaction> create(
/**
* Deletes a list of user created transactions
*
* @param transactionIds The ids of the user transactions to deleteUpcoming
* @return A task of type Void. The task will indicate if the deleteUpcoming was successful or not
* @param transactionIds The ids of the user transactions to delete
* @return A task of type Void. The task will indicate if the deleteTransactions was successful or not
*/
public static Result<Void> deleteTransactions(List<Long> transactionIds) {
return MenigaTransaction.apiOperator.deleteTransactions(transactionIds);
Expand All @@ -1210,9 +1210,21 @@ public static Result<Void> deleteTransactions(List<Long> transactionIds) {
* @param recategorizeUnreadOnly Recategorize only unread transactions if true, otherwise recategorize unread or read transactions
* @param useSubTextInRecat Whether to include the subText field when searching for transactions to recategorize
* @param markAsRead Mark recategorized transactions as read or not
* @return A task of type Void. The task will indicate if the deleteUpcoming was successful or not
* @return A task of type Void. The task will indicate if the recategorize was successful or not
*/
public static Result<Void> recategorize(List<String> transactionTexts, Boolean recategorizeUnreadOnly, Boolean useSubTextInRecat, Boolean markAsRead) {
return MenigaTransaction.apiOperator.recategorize(transactionTexts, recategorizeUnreadOnly, useSubTextInRecat, markAsRead);
}

/**
* Create a comment for a list of transaction ids. If the comment contains any tags (words starting with '#') they are automatically
* created and associated with these transaction if they do not already exist.
*
* @param transactionIds The ids of the user transactions to add the comment
* @param comment The new comment to add to transactions
* @return Result with newly added transaction comments
*/
public static Result<List<MenigaComment>> addComments(List<Long> transactionIds, String comment) {
return MenigaTransaction.apiOperator.addComments(transactionIds, comment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.meniga.sdk.helpers.MenigaDecimal;
import com.meniga.sdk.helpers.Result;
import com.meniga.sdk.models.transactions.MenigaComment;
import com.meniga.sdk.models.transactions.MenigaTransaction;
import com.meniga.sdk.models.transactions.MenigaTransactionPage;
import com.meniga.sdk.models.transactions.MenigaTransactionUpdate;
Expand Down Expand Up @@ -49,4 +50,6 @@ Result<MenigaTransactionUpdate> updateTransactions(
);

Result<List<MenigaTransaction>> updateSplits(long id, List<UpdateSplits> updates);

Result<List<MenigaComment>> addComments(List<Long> transactionIds, String comment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.meniga.sdk.MenigaSDK;
import com.meniga.sdk.helpers.MenigaDecimal;
import com.meniga.sdk.helpers.Result;
import com.meniga.sdk.models.transactions.MenigaComment;
import com.meniga.sdk.models.transactions.MenigaTransaction;
import com.meniga.sdk.models.transactions.MenigaTransactionPage;
import com.meniga.sdk.models.transactions.MenigaTransactionUpdate;
import com.meniga.sdk.models.transactions.TransactionsFilter;
import com.meniga.sdk.webservices.requests.AddComments;
import com.meniga.sdk.webservices.requests.CreateTransaction;
import com.meniga.sdk.webservices.requests.DeleteTransaction;
import com.meniga.sdk.webservices.requests.DeleteTransactions;
Expand Down Expand Up @@ -151,4 +153,11 @@ public Result<Void> recategorize(List<String> transactionTexts, Boolean recatego

return MenigaSDK.executor().recategorizeTransactions(req);
}

@Override
public Result<List<MenigaComment>> addComments(List<Long> transactionIds, String comment) {
AddComments req = new AddComments(transactionIds, comment);

return MenigaSDK.executor().addComments(req);
}
}
4 changes: 4 additions & 0 deletions sdk/src/main/java/com/meniga/sdk/webservices/MenigaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.meniga.sdk.models.transactions.MenigaTransactionUpdate;
import com.meniga.sdk.models.upcoming.MenigaUpcoming;
import com.meniga.sdk.models.userevents.MenigaUserEvent;
import com.meniga.sdk.webservices.requests.AddComments;
import com.meniga.sdk.webservices.requests.CreateComment;
import com.meniga.sdk.webservices.requests.CreateNetWorthAccount;
import com.meniga.sdk.webservices.requests.CreateNetWorthBalanceHistory;
Expand Down Expand Up @@ -123,6 +124,9 @@ public interface MenigaAPI {
@DELETE(APIConst.URL_TRANSACTIONS + "/{id}/" + APIConst.COMMENTS + "/{commentId}")
Call<Void> deleteComment(@Path("id") long transactionId, @Path("commentId") long commentId);

@POST(APIConst.URL_TRANSACTIONS + "/" + APIConst.COMMENTS)
Call<List<MenigaComment>> addComments(@Body AddComments req);

@GET(APIConst.URL_TRANSACTIONS + "/{id}/" + APIConst.SPLIT)
Call<List<MenigaTransaction>> fetchSplitTransactions(@Path("id") long parentId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ public Result<Void> deleteComment(DeleteComment req) {
return persist(req, getClient(Service.TRANSACTIONS).deleteComment(req.transactionId, req.commentId));
}

public Result<List<MenigaComment>> addComments(AddComments req) {
return persist(req, getClient(Service.TRANSACTIONS).addComments(req));
}

public Result<Void> recategorizeTransactions(RecategorizeTransactions req) {
return persist(req, getClient(Service.TRANSACTIONS).recategorizeTransactions(req));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2020 Meniga Iceland Inc.
*/
package com.meniga.sdk.webservices.requests

class AddComments(
val transactionIds: List<Long>,
val comment: String
) : QueryRequestObject() {

override fun getValueHash(): Long = hashCode().toLong()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.meniga.sdk.helpers.MTask;
import com.meniga.sdk.helpers.MenigaDecimal;
import com.meniga.sdk.helpers.Result;
import com.meniga.sdk.models.transactions.MenigaComment;
import com.meniga.sdk.models.transactions.MenigaTransaction;
import com.meniga.sdk.models.transactions.MenigaTransactionPage;
import com.meniga.sdk.models.transactions.MenigaTransactionUpdate;
Expand Down Expand Up @@ -106,6 +107,13 @@ public Result<List<MenigaTransaction>> updateSplits(long id, List<UpdateSplits>
return new MTask<>(task.getTask(), task);
}

@Override
public Result<List<MenigaComment>> addComments(List<Long> transactionIds, String comment) {
TaskCompletionSource<List<MenigaComment>> task = new TaskCompletionSource<>();
task.setResult(null);
return new MTask<>(task.getTask(), task);
}

@Override
public Result<List<MenigaTransaction>> fetchSplitTransactions(MenigaTransaction menigaTransaction) {
TaskCompletionSource<List<MenigaTransaction>> task = new TaskCompletionSource<>();
Expand Down
18 changes: 18 additions & 0 deletions sdk/src/test/resources/raw/addComments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"data": [
{
"id": 20409,
"personId": 1180,
"comment": "newComment",
"createdDate": "2020-04-22T07:46:49.7710157+00:00",
"modifiedDate": null
},
{
"id": 20410,
"personId": 1180,
"comment": "newComment",
"createdDate": "2020-04-22T07:46:49.8022631+00:00",
"modifiedDate": null
}
]
}

0 comments on commit 7c0c792

Please sign in to comment.