Skip to content

Instantly share code, notes, and snippets.

View gytis's full-sized avatar

Gytis Trikleris gytis

  • Turing College
  • Barcelona
View GitHub Profile
@gytis
gytis / hello-service_openshift.yml
Created February 28, 2017 11:11
spring-boot-health-check-example hello-service openshift.yml Raw
---
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/scrape: "true"
fabric8.io/scm-tag: HEAD
@gytis
gytis / name-service_openshift.yml
Created February 28, 2017 11:10
spring-boot-health-check-example name-service openshift.yml
---
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/scrape: "true"
fabric8.io/scm-tag: HEAD
@gytis
gytis / sell.java
Created January 25, 2017 11:41
Blog :: New Narayana release and Spring Boot quickstart :: Sell operation
@DeleteMapping("/portfolio/{username}/{symbol}")
@Transactional
public void sell(@PathVariable String username, @PathVariable String symbol, @RequestParam("amount") int amount) {
User user = getUser(username);
Share share = getShare(symbol);
PortfolioEntry portfolioEntry = getPortfolioEntry(user, share);
updateBudget(user, amount * share.getPrice()); // Increase user's budget
updateSharesAmount(share, amount); // Increase shares amount available for sale
updatePortfolioEntry(portfolioEntry, -1 * amount); // Decrease shares amount owned by the user
@gytis
gytis / buy.java
Last active January 25, 2017 11:36
Blog :: New Narayana release and Spring Boot quickstart :: Buy operation
@PutMapping("/portfolio/{username}/{symbol}")
@Transactional
public void buy(@PathVariable String username, @PathVariable String symbol, @RequestParam("amount") int amount) {
User user = getUser(username);
Share share = getShare(symbol);
PortfolioEntry portfolioEntry = getOrCreatePortfolioEntry(user, share); // Get user's portfolio entry or create a new one
updateBudget(user, -1 * amount * share.getPrice()); // Decrease user's budget
updateSharesAmount(share, -1 * amount); // Decrease shares amount available for sale
updatePortfolioEntry(portfolioEntry, amount); // Increase shares amount owned by the user
@gytis
gytis / compensating-tx-in-jta.java
Last active July 26, 2016 09:13
Compensating transaction in JTA
class Service {
@Inject
EntityManager entityManager;
@Inject
CompensationManager compensationManager;
@Inject
Session session; // E.g. Neo4j session