mirror of
https://github.com/valitydev/newway.git
synced 2024-11-06 09:25:22 +00:00
BJ-830: Payment system in rates (#103)
* BJ-830: Add payment system in rate table * Remove unused imports, fix with excluded fields * Remove unused imports * and so the crazy refactoring process sees the sunlight after some months in the dark!
This commit is contained in:
parent
a28ad6d5fb
commit
016f0d733d
2
pom.xml
2
pom.xml
@ -161,7 +161,7 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>xrates-proto</artifactId>
|
||||
<version>1.7-5587fa8</version>
|
||||
<version>1.8-67d5c21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
|
@ -38,7 +38,7 @@ public class RateDaoImpl extends AbstractGenericDao implements RateDao {
|
||||
public Long save(Rate rate) throws DaoException {
|
||||
RateRecord record = getDslContext().newRecord(RATE, rate);
|
||||
Query query = getDslContext().insertInto(RATE).set(record)
|
||||
.onConflict(RATE.SOURCE_ID, RATE.SEQUENCE_ID, RATE.CHANGE_ID, RATE.SOURCE_SYMBOLIC_CODE, RATE.DESTINATION_SYMBOLIC_CODE)
|
||||
.onConflict(RATE.SOURCE_ID, RATE.SEQUENCE_ID, RATE.CHANGE_ID, RATE.SOURCE_SYMBOLIC_CODE, RATE.DESTINATION_SYMBOLIC_CODE, RATE.PAYMENT_SYSTEM)
|
||||
.doNothing()
|
||||
.returning(RATE.ID);
|
||||
|
||||
|
@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Component
|
||||
@ -76,6 +77,7 @@ public class RateCreatedHandler extends AbstractRateHandler {
|
||||
rate.setSourceExponent(source.getExponent());
|
||||
rate.setDestinationSymbolicCode(destination.getSymbolicCode());
|
||||
rate.setDestinationExponent(destination.getExponent());
|
||||
rate.setPaymentSystem(Objects.toString(quote.getPaymentSystem(), null));
|
||||
|
||||
// ExchangeRate
|
||||
rate.setExchangeRateRationalP(exchangeRate.getP());
|
||||
|
@ -0,0 +1,4 @@
|
||||
alter table nw.rate add column payment_system character varying not null default '';
|
||||
|
||||
drop index idx_uniq;
|
||||
create unique index rate_ukey on nw.rate(source_id, sequence_id, change_id, source_symbolic_code, destination_symbolic_code, payment_system);
|
@ -11,6 +11,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServiceTests extends AbstractAppDaoTests {
|
||||
|
||||
@ -43,7 +44,23 @@ public class ServiceTests extends AbstractAppDaoTests {
|
||||
String sourceId = "CBR";
|
||||
|
||||
RateSinkEventTestUtils.Dto dto = RateSinkEventTestUtils.create(sourceId);
|
||||
rateService.handleEvents(dto.getSinkEvent(), dto.getEvent());
|
||||
rateService.handleEvents(dto.getSinkEvent(), dto.getEvent());
|
||||
|
||||
List<Rate> rates = jdbcTemplate.query(
|
||||
"SELECT * FROM nw.rate AS rate WHERE rate.source_id = ? AND rate.current",
|
||||
new Object[]{sourceId},
|
||||
new BeanPropertyRowMapper(Rate.class)
|
||||
);
|
||||
assertEquals(4, rates.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rateServiceDuplicationWhenPaymentSystemIsNullTest() {
|
||||
jdbcTemplate.execute("truncate table nw.rate cascade");
|
||||
String sourceId = "CBR";
|
||||
|
||||
RateSinkEventTestUtils.Dto dto = RateSinkEventTestUtils.create(sourceId, "payment_system");
|
||||
rateService.handleEvents(dto.getSinkEvent(), dto.getEvent());
|
||||
rateService.handleEvents(dto.getSinkEvent(), dto.getEvent());
|
||||
|
||||
|
@ -15,10 +15,8 @@ import static io.github.benas.randombeans.api.EnhancedRandom.randomListOf;
|
||||
|
||||
public class RateSinkEventTestUtils extends AbstractTestUtils {
|
||||
|
||||
public static Dto create(String sourceId) {
|
||||
List<Quote> quotes = new ArrayList<Quote>() {{
|
||||
addAll(randomListOf(4, Quote.class));
|
||||
}};
|
||||
public static Dto create(String sourceId, String... excludedFields) {
|
||||
List<Quote> quotes = randomListOf(4, Quote.class, excludedFields);
|
||||
|
||||
Event event = new Event(
|
||||
Collections.singletonList(
|
||||
|
Loading…
Reference in New Issue
Block a user