Skip to content

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
kai-niemi committed Feb 14, 2024
1 parent 3d9968a commit a8d784e
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<logger name="org.springframework" level="INFO"/>
<logger name="org.springframework.batch" level="INFO" additivity="true"/>

<springProfile name="verbose">
<logger name="io.burpabet" level="TRACE"/>
<logger name="io.burpabet.SQL_TRACE" level="TRACE"/>
<springProfile name="silent">
<logger name="io.burpabet" level="WARN"/>
<logger name="io.burpabet.SQL_TRACE" level="WARN"/>
</springProfile>

<springProfile name="!verbose">
<springProfile name="!silent">
<logger name="io.burpabet" level="INFO"/>
<logger name="io.burpabet.SQL_TRACE" level="INFO"/>
</springProfile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package io.burpabet.customer.saga;

import java.time.Duration;
import java.util.Currency;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import io.burpabet.common.annotations.OutboxOperation;
import io.burpabet.common.annotations.Retryable;
import io.burpabet.common.annotations.ServiceFacade;
Expand All @@ -12,15 +23,6 @@
import io.burpabet.customer.repository.CustomerRepository;
import io.burpabet.customer.service.SimpleSpendingLimit;
import io.burpabet.customer.service.SpendingLimit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

@ServiceFacade
public class CustomerBettingFacade {
Expand All @@ -31,6 +33,10 @@ public class CustomerBettingFacade {
@Autowired
private CustomerRepository customerRepository;

private SpendingLimit defaultSpendingLimit(Currency currency) {
return new SimpleSpendingLimit(Money.of("50.00", currency), Duration.ofSeconds(60));
}

@TransactionBoundary
@Retryable
@OutboxOperation(aggregateType = "placement")
Expand Down Expand Up @@ -58,9 +64,9 @@ public BetPlacement acquireSpendingCredits(BetPlacement placement) {
final Money wager = placement.getStake();

boolean permitted = customerSpendingLimits.computeIfAbsent(placement.getCustomerId(),
x -> new SimpleSpendingLimit(Money.of("50.00", wager.getCurrency()),
Duration.ofSeconds(60)))
x -> defaultSpendingLimit(wager.getCurrency()))
.acquirePermission(placement.getStake());

if (permitted) {
placement.setStatus(Status.APPROVED);
placement.setStatusDetail("Within spending budget");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onBetPlacementEvent(BetPlacementEvent event) {
} else if (placement.getStatus().equals(Status.ROLLBACK)) {
customerBettingFacade.releaseSpendingCredits(placement);
} else {
logger.debug("BetPlacement event received with status: %s".formatted(placement.getStatus()));
logger.info("BetPlacement event received with status: %s".formatted(placement.getStatus()));
}
}

Expand All @@ -54,7 +54,7 @@ public void onBetSettlementEvent(BetSettlementEvent event) {
if (settlement.getStatus().equals(Status.PENDING)) {
customerBettingFacade.approveSettlement(settlement);
} else {
logger.debug("BetSettlement event received with status: %s".formatted(settlement.getStatus()));
logger.info("BetSettlement event received with status: %s".formatted(settlement.getStatus()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.burpabet.customer.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.view.RedirectView;

@Controller
@RequestMapping("/")
public class HomeController {
@GetMapping
public RedirectView homePage(Model model) {
return new RedirectView("api");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<logger name="org.springframework" level="INFO"/>
<logger name="org.springframework.batch" level="INFO" additivity="true"/>

<springProfile name="verbose">
<logger name="io.burpabet" level="TRACE"/>
<logger name="io.burpabet.SQL_TRACE" level="TRACE"/>
<springProfile name="silent">
<logger name="io.burpabet" level="WARN"/>
<logger name="io.burpabet.SQL_TRACE" level="WARN"/>
</springProfile>

<springProfile name="!verbose">
<springProfile name="!silent">
<logger name="io.burpabet" level="INFO"/>
<logger name="io.burpabet.SQL_TRACE" level="INFO"/>
</springProfile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void onRegistrationEvent(RegistrationEvent event) {
} else if (registration.getStatus().equals(Status.ROLLBACK)) {
registrationFacade.reverseAccounts(registration);
} else {
logger.debug("RegistrationEvent received with status: %s".formatted(registration.getStatus()));
logger.info("RegistrationEvent received with status: %s".formatted(registration.getStatus()));
}
}

Expand All @@ -59,7 +59,7 @@ public void onBetPlacementEvent(BetPlacementEvent event) {
} else if (placement.getStatus().equals(Status.ROLLBACK)) {
bettingFacade.reverseWager(placement);
} else {
logger.debug("BetPlacementEvent received with status: %s".formatted(placement.getStatus()));
logger.info("BetPlacementEvent received with status: %s".formatted(placement.getStatus()));
}
}

Expand All @@ -71,7 +71,7 @@ public void onBetSettlementEvent(BetSettlementEvent event) {
if (settlement.getStatus().equals(Status.PENDING)) {
bettingFacade.transferPayout(settlement);
} else {
logger.debug("BetSettlementEvent received with status: %s".formatted(settlement.getStatus()));
logger.info("BetSettlementEvent received with status: %s".formatted(settlement.getStatus()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.burpabet.wallet.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.view.RedirectView;

@Controller
@RequestMapping("/")
public class HomeController {
@GetMapping
public RedirectView homePage(Model model) {
return new RedirectView("api");
}
}
8 changes: 4 additions & 4 deletions burpabet-wallet-service/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<logger name="org.springframework" level="INFO"/>
<logger name="org.springframework.batch" level="INFO" additivity="true"/>

<springProfile name="verbose">
<logger name="io.burpabet" level="TRACE"/>
<logger name="io.burpabet.SQL_TRACE" level="TRACE"/>
<springProfile name="silent">
<logger name="io.burpabet" level="WARN"/>
<logger name="io.burpabet.SQL_TRACE" level="WARN"/>
</springProfile>

<springProfile name="!verbose">
<springProfile name="!silent">
<logger name="io.burpabet" level="INFO"/>
<logger name="io.burpabet.SQL_TRACE" level="INFO"/>
</springProfile>
Expand Down
2 changes: 1 addition & 1 deletion run-betting.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

__params="\
params="\
--spring.profiles.active=local \
--spring.datasource.url=jdbc:postgresql://192.168.1.99:26257/burp_betting?sslmode=disable \
--spring.datasource.username=root \
Expand Down
2 changes: 1 addition & 1 deletion run-customer.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

__params="\
params="\
--spring.profiles.active=local \
--spring.datasource.url=jdbc:postgresql://192.168.1.99:26257/burp_customer?sslmode=disable \
--spring.datasource.username=root \
Expand Down
2 changes: 1 addition & 1 deletion run-wallet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

__params="\
params="\
--spring.profiles.active=local \
--spring.datasource.url=jdbc:postgresql://192.168.1.99:26257/burp_wallet?sslmode=disable \
--spring.datasource.username=root \
Expand Down

0 comments on commit a8d784e

Please sign in to comment.