Skip to content

Commit

Permalink
replace appuser_id with created_by
Browse files Browse the repository at this point in the history
  • Loading branch information
wkigenyi committed May 28, 2024
1 parent 8b2c9da commit 1e9f698
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ public String settleCashFromCashier(@PathParam("tellerId") @Parameter(descriptio
@Path("{tellerId}/cashiers/{cashierId}/transactions")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Retrieve Cashier Transaction", description = "")
@Operation(summary = "Retrieve Cashier Transactions", description = "")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = TellerApiResourceSwagger.GetTellersTellerIdCashiersCashiersIdTransactionsResponse.class)))) })
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TellerApiResourceSwagger.GetTellersTellerIdCashiersCashiersIdTransactionsResponse.class))) })
public String getTransactionsForCashier(@PathParam("tellerId") @Parameter(description = "tellerId") final Long tellerId,
@PathParam("cashierId") @Parameter(description = "cashierId") final Long cashierId,
@QueryParam("currencyCode") @Parameter(description = "currencyCode") final String currencyCode,
Expand Down Expand Up @@ -331,10 +331,10 @@ public String getTransactionsForCashier(@PathParam("tellerId") @Parameter(descri
@Path("{tellerId}/cashiers/{cashierId}/summaryandtransactions")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Transactions Wtih Summary For Cashier", description = "")
@Operation(summary = "Retrieve Transactions With Summary For Cashier", description = "")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TellerApiResourceSwagger.GetTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse.class))) })
public String getTransactionsWtihSummaryForCashier(@PathParam("tellerId") @Parameter(description = "tellerId") final Long tellerId,
public String getTransactionsWithSummaryForCashier(@PathParam("tellerId") @Parameter(description = "tellerId") final Long tellerId,
@PathParam("cashierId") @Parameter(description = "cashierId") final Long cashierId,
@QueryParam("currencyCode") @Parameter(description = "currencyCode") final String currencyCode,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.fineract.organisation.teller.exception;

import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
import org.springframework.dao.EmptyResultDataAccessException;

/**
* Indicates that a cashier could not be found.
Expand All @@ -40,4 +41,9 @@ public class CashierNotFoundException extends AbstractPlatformResourceNotFoundEx
public CashierNotFoundException(Long cashierId) {
super(ERROR_MESSAGE_CODE, DEFAULT_ERROR_MESSAGE, cashierId);
}

public CashierNotFoundException(Long id, EmptyResultDataAccessException e) {
super("error.msg.staff.id.invalid", "Staff with identifier " + id + " does not exist", id, e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.fineract.organisation.teller.exception;

import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
import org.springframework.dao.EmptyResultDataAccessException;

/**
* Indicates that a teller could not be found.
Expand All @@ -40,4 +41,8 @@ public class TellerNotFoundException extends AbstractPlatformResourceNotFoundExc
public TellerNotFoundException(Long tellerId) {
super(ERROR_MESSAGE_CODE, DEFAULT_ERROR_MESSAGE, tellerId);
}

public TellerNotFoundException(Long id, EmptyResultDataAccessException e) {
super("error.msg.teller.id.invalid", "Teller with identifier " + id + " does not exist", id, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.organisation.office.service.OfficeReadPlatformService;
import org.apache.fineract.organisation.staff.data.StaffData;
import org.apache.fineract.organisation.staff.exception.StaffNotFoundException;
import org.apache.fineract.organisation.staff.service.StaffReadPlatformService;
import org.apache.fineract.organisation.teller.data.CashierData;
import org.apache.fineract.organisation.teller.data.CashierTransactionData;
Expand All @@ -51,6 +50,8 @@
import org.apache.fineract.organisation.teller.data.TellerTransactionData;
import org.apache.fineract.organisation.teller.domain.CashierTxnType;
import org.apache.fineract.organisation.teller.domain.TellerStatus;
import org.apache.fineract.organisation.teller.exception.CashierNotFoundException;
import org.apache.fineract.organisation.teller.exception.TellerNotFoundException;
import org.apache.fineract.useradministration.domain.AppUser;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.EmptyResultDataAccessException;
Expand Down Expand Up @@ -163,7 +164,7 @@ public TellerData findTeller(final Long tellerId) {

return this.jdbcTemplate.queryForObject(sql, tm, new Object[] { tellerId }); // NOSONAR
} catch (final EmptyResultDataAccessException e) {
throw new StaffNotFoundException(tellerId, e);
throw new TellerNotFoundException(tellerId, e);
}
}

Expand Down Expand Up @@ -276,7 +277,7 @@ public CashierData findCashier(Long cashierId) {

return this.jdbcTemplate.queryForObject(sql, cm, new Object[] { cashierId }); // NOSONAR
} catch (final EmptyResultDataAccessException e) {
throw new StaffNotFoundException(cashierId, e);
throw new CashierNotFoundException(cashierId, e);
}
}

Expand Down Expand Up @@ -588,7 +589,7 @@ public String savingsTxnSchema() {
sqlBuilder.append(" left join m_savings_account sav on sav_txn.savings_account_id = sav.id ");
sqlBuilder.append(" left join m_client cl on sav.client_id = cl.id ");
sqlBuilder.append(" left join m_office o on cl.office_id = o.id ");
sqlBuilder.append(" left join m_appuser user on sav_txn.appuser_id = user.id ");
sqlBuilder.append(" left join m_appuser user on sav_txn.created_by = user.id ");
sqlBuilder.append(" left join m_staff staff on user.staff_id = staff.id ");
sqlBuilder.append(" left join m_cashiers c on c.staff_id = staff.id ");
sqlBuilder.append(" left join m_payment_detail payDetails on payDetails.id = sav_txn.payment_detail_id ");
Expand Down Expand Up @@ -752,7 +753,7 @@ public String cashierTxnSummarySchema() {
sqlBuilder.append(" left join m_savings_account sav on sav_txn.savings_account_id = sav.id ");
sqlBuilder.append(" left join m_client cl on sav.client_id = cl.id ");
sqlBuilder.append(" left join m_office o on cl.office_id = o.id ");
sqlBuilder.append(" left join m_appuser user on sav_txn.appuser_id = user.id ");
sqlBuilder.append(" left join m_appuser user on sav_txn.created_by = user.id ");
sqlBuilder.append(" left join m_staff staff on user.staff_id = staff.id ");
sqlBuilder.append(" left join m_cashiers c on c.staff_id = staff.id ");
sqlBuilder.append(" left join m_payment_detail payDetails on payDetails.id = sav_txn.payment_detail_id ");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.organization.teller;

import com.google.gson.Gson;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.HashMap;
import java.util.Map;
import org.apache.fineract.integrationtests.common.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class CashierHelper {

private CashierHelper() {

}

private static final Logger LOG = LoggerFactory.getLogger(CashierHelper.class);

private static final String CREATE_CASHIER_URL = "/fineract-provider/api/v1/tellers/1/cashiers";

public static Integer createCashier(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
return (Integer) createTellerWithJson(requestSpec, responseSpec, createTellerAsJSON()).get("resourceId");
}

public static Map<String, Object> createTellerWithJson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String json) {
final String url = CREATE_CASHIER_URL + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, url, json, "");
}

public static String createTellerAsJSON() {

final Map<String, Object> map = getMapWithDates();

map.put("staffId", 1);
map.put("description", Utils.uniqueRandomStringGenerator("test__", 4));
LOG.info("map : {}", map);
return new Gson().toJson(map);
}

public static Map<String, Object> getMapWithDates() {
HashMap<String, Object> map = new HashMap<>();

map.put("locale", "en");
map.put("dateFormat", "dd MMMM yyyy");
map.put("startDate", "01 January 2023");
map.put("endDate", "31 December 2023");
map.put("isFullDay", true);

return map;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.organization.teller;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import org.apache.fineract.client.models.GetTellersTellerIdCashiersCashiersIdTransactionsResponse;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class CashierSummaryAndTransactionsTest {

private CashierTransactionsHelper cashierTransactionsHelper;

private ResponseSpecification responseSpecification;
private RequestSpecification requestSpecification;

@BeforeEach
public void setup() {
Utils.initializeRESTAssured();

requestSpecification = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
requestSpecification.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).build();
cashierTransactionsHelper = new CashierTransactionsHelper(requestSpecification, responseSpecification);
StaffHelper.createStaff(requestSpecification, responseSpecification);
TellerHelper.createTeller(requestSpecification, responseSpecification);
CashierHelper.createCashier(requestSpecification, responseSpecification);

}

@Test
public void testGetCashierTransactions() {
Long tellerId = 1L;
Long cashierId = 1L;

final GetTellersTellerIdCashiersCashiersIdTransactionsResponse result = cashierTransactionsHelper
.getTellersTellerIdCashiersCashiersIdTransactionsResponse(tellerId, cashierId, "UGX", 0, 0, null, null);
assertNotNull(result);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.organization.teller;

import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import org.apache.fineract.client.models.GetTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse;
import org.apache.fineract.client.models.GetTellersTellerIdCashiersCashiersIdTransactionsResponse;
import org.apache.fineract.integrationtests.client.IntegrationTest;

public class CashierTransactionsHelper extends IntegrationTest {

private final ResponseSpecification responseSpecification;
private final RequestSpecification requestSpecification;

public CashierTransactionsHelper(final RequestSpecification requestSpecification, final ResponseSpecification responseSpecification) {
this.requestSpecification = requestSpecification;
this.responseSpecification = responseSpecification;
}

public GetTellersTellerIdCashiersCashiersIdTransactionsResponse getTellersTellerIdCashiersCashiersIdTransactionsResponse(Long tellerId,
Long cashierId, String currencyCode, int offset, int limit, String orderBy, String sortOrder) {
return ok(fineract().tellers.getTransactionsForCashier(tellerId, cashierId, currencyCode, offset, limit, orderBy, sortOrder));
}

public GetTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse getTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse(
Long tellerId, Long cashierId, String currencyCode, int offset, int limit, String orderBy, String sortOrder) {
return ok(fineract().tellers.getTransactionsWithSummaryForCashier(tellerId, cashierId, currencyCode, offset, limit, orderBy,
sortOrder));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.organization.teller;

import com.google.gson.Gson;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.HashMap;
import java.util.Map;
import org.apache.fineract.integrationtests.common.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class TellerHelper {

private TellerHelper() {

}

private static final Logger LOG = LoggerFactory.getLogger(TellerHelper.class);

private static final String CREATE_TELLER_URL = "/fineract-provider/api/v1/tellers";

public static Integer createTeller(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
return (Integer) createTellerWithJson(requestSpec, responseSpec, createTellerAsJSON()).get("resourceId");
}

public static Map<String, Object> createTellerWithJson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String json) {
final String url = CREATE_TELLER_URL + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, url, json, "");
}

public static String createTellerAsJSON() {

final Map<String, Object> map = getMapWithStartDate();

map.put("officeId", 1);
map.put("name", Utils.uniqueRandomStringGenerator("Teller 1", 5));
map.put("description", Utils.uniqueRandomStringGenerator("Teller For Testing", 4));
map.put("status", 300);

LOG.info("map : {}", map);
return new Gson().toJson(map);
}

public static Map<String, Object> getMapWithStartDate() {
HashMap<String, Object> map = new HashMap<>();

map.put("locale", "en");
map.put("dateFormat", "dd MMMM yyyy");
map.put("startDate", "20 September 2011");

return map;
}

}

0 comments on commit 1e9f698

Please sign in to comment.