SlideShare a Scribd company logo
1 of 14
Download to read offline
Restaurant Server
Restaurant Server
✦I will not go into all of the details because many
pieces are mundane and boring
✦The server portion is relatively easier when we have a
client ready but there is a lot of hidden complexity
✦This is especially true when it comes to security
which is often unintuitive
© Codename One 2017 all rights reserved
Standard Spring Boot project
✦We’ll create pretty much the same spring boot project
we created in the spring boot tutorial
✦I’ll go with a new Database URL to start fresh and
new project name “AppBackendServer”. The generic
name makes sense for the app maker…
✦My goal isn’t to win an “architecture award” but to
create the bare minimum server within reason
© Codename One 2017 all rights reserved
<dependency>
<groupId>com.braintreepayments.gateway</groupId>
<artifactId>braintree-java</artifactId>
<version>2.71.0</version>
</dependency>
BrainTree Support - pom.xml
@Controller
@RequestMapping("/braintree")
public class BraintreePaymentService {
@Autowired
private RestaurantRepository restaurantRepository;
@Autowired
private OrderRepository orderRepository;
private WeakHashMap<String, BraintreeGateway> gatewayCache = new WeakHashMap<>();
private BraintreeGateway getGateway(String auth) {
BraintreeGateway bg = gatewayCache.get(auth);
if(bg != null) {
return bg;
}
RestaurantEntity r = restaurantRepository.findOne(auth);
if(r != null) {
bg = new BraintreeGateway(
Environment.SANDBOX,
r.getMerchantId(),
r.getPublicKey(),
r.getPrivateKey()
);
gatewayCache.put(auth, bg);
return bg;
}
return null;
}
BraintreePaymentService
@Controller
@RequestMapping("/braintree")
public class BraintreePaymentService {
@Autowired
private RestaurantRepository restaurantRepository;
@Autowired
private OrderRepository orderRepository;
private WeakHashMap<String, BraintreeGateway> gatewayCache = new WeakHashMap<>();
private BraintreeGateway getGateway(String auth) {
BraintreeGateway bg = gatewayCache.get(auth);
if(bg != null) {
return bg;
}
RestaurantEntity r = restaurantRepository.findOne(auth);
if(r != null) {
bg = new BraintreeGateway(
Environment.SANDBOX,
r.getMerchantId(),
r.getPublicKey(),
r.getPrivateKey()
);
gatewayCache.put(auth, bg);
return bg;
}
return null;
}
BraintreePaymentService
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody String getToken(@RequestParam(name = "auth") String auth) {
return getGateway(auth).clientToken().generate();
}
@RequestMapping(method=RequestMethod.POST)
public @ResponseBody PurchaseResult purchase(@RequestBody(required=true) Order i) {
TransactionRequest request = new TransactionRequest()
.amount(i.calculateAmount())
.paymentMethodNonce(i.getNounce())
.options()
.submitForSettlement(true)
.done();
Result<Transaction> result = getGateway(i.getAuth()).transaction().sale(request);
if(result.isSuccess()) {
// Store entry and email restaurant
}
return new PurchaseResult(result.isSuccess(), result.getMessage());
}
}
BraintreePaymentService
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody String getToken(@RequestParam(name = "auth") String auth) {
return getGateway(auth).clientToken().generate();
}
@RequestMapping(method=RequestMethod.POST)
public @ResponseBody PurchaseResult purchase(@RequestBody(required=true) Order i) {
TransactionRequest request = new TransactionRequest()
.amount(i.calculateAmount())
.paymentMethodNonce(i.getNounce())
.options()
.submitForSettlement(true)
.done();
Result<Transaction> result = getGateway(i.getAuth()).transaction().sale(request);
if(result.isSuccess()) {
// Store entry and email restaurant
}
return new PurchaseResult(result.isSuccess(), result.getMessage());
}
}
BraintreePaymentService
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody String getToken(@RequestParam(name = "auth") String auth) {
return getGateway(auth).clientToken().generate();
}
@RequestMapping(method=RequestMethod.POST)
public @ResponseBody PurchaseResult purchase(@RequestBody(required=true) Order i) {
TransactionRequest request = new TransactionRequest()
.amount(i.calculateAmount())
.paymentMethodNonce(i.getNounce())
.options()
.submitForSettlement(true)
.done();
Result<Transaction> result = getGateway(i.getAuth()).transaction().sale(request);
if(result.isSuccess()) {
// Store entry and email restaurant
}
return new PurchaseResult(result.isSuccess(), result.getMessage());
}
}
BraintreePaymentService
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody String getToken(@RequestParam(name = "auth") String auth) {
return getGateway(auth).clientToken().generate();
}
@RequestMapping(method=RequestMethod.POST)
public @ResponseBody PurchaseResult purchase(@RequestBody(required=true) Order i) {
TransactionRequest request = new TransactionRequest()
.amount(i.calculateAmount())
.paymentMethodNonce(i.getNounce())
.options()
.submitForSettlement(true)
.done();
Result<Transaction> result = getGateway(i.getAuth()).transaction().sale(request);
if(result.isSuccess()) {
// Store entry and email restaurant
}
return new PurchaseResult(result.isSuccess(), result.getMessage());
}
}
BraintreePaymentService
@Entity
@Table(name="Restaurant")
public class RestaurantEntity {
@Id
private String id;
private String name;
private String merchantId;
private String publicKey;
private String privateKey;
private double currentVersionIOS = 1.0;
private double lastSupportedVersionIOS = 0;
private double currentVersionAnd = 1.0;
private double lastSupportedVersionAnd = 0;
private double currentVersionUWP = 1.0;
private double lastSupportedVersionUWP = 0;
private long dishListUpdateTimestamp = 1;
private String restaurantEmail;
@OneToMany
private Set<DishEntity> dishes;
@OneToMany
private Set<CategoryEntity> categories;
public RestaurantEntity() {
id = UUID.randomUUID().toString();
}
RestaurantEntity
@Entity
@Table(name="Purchases")
public class OrderEntity {
@Id
private String id;
@OneToMany
private Set<OrderLineEntity> dishQuanity;
private Date date;
private String notes;
public OrderEntity() {
id = UUID.randomUUID().toString();
}
OrderEntity vs. dao Order
public class Order {
private String id;
private Date date;
private boolean purchased;
private Map<Dish, Integer> dishQuantity = new
HashMap<>();
private String notes;
private String nounce;
private String auth;
public BigDecimal calculateAmount() {
BigDecimal b = BigDecimal.ZERO;
for(Map.Entry<Dish, Integer> d :
dishQuantity.entrySet()) {
b = b.add(new BigDecimal(
d.getValue() *
d.getKey().
getPrice()));
}
return b;
}
@Controller
@RequestMapping("/ver")
public class VersionService {
@Autowired
private RestaurantRepository restaurantRepository;
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody AppVersion getKey(@RequestParam(value="os", required=true) String os,
@RequestParam(value="appId", required=true) String appId) {
RestaurantEntity r = restaurantRepository.findOne(appId);
switch(os) {
case "ios":
return new AppVersion(r.getCurrentVersionIOS(), r.getLastSupportedVersionIOS());
case "and":
return new AppVersion(r.getCurrentVersionAnd(), r.getLastSupportedVersionAnd());
case "win":
return new AppVersion(r.getCurrentVersionUWP(), r.getLastSupportedVersionUWP());
}
return null;
}
}
VersionService
Thank You

More Related Content

Similar to Restaurant Server.pdf

Angular Tutorial Freshers and Experienced
Angular Tutorial Freshers and ExperiencedAngular Tutorial Freshers and Experienced
Angular Tutorial Freshers and Experiencedrajkamaltibacademy
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo Ali Parmaksiz
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIEyal Vardi
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networkingVitali Pekelis
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right wayThibaud Desodt
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in reactBOSC Tech Labs
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web servicesMichelangelo van Dam
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicIMC Institute
 
EdgeWorkers: Enabling Autonomous, Developer Friendly Programming at the Edge
EdgeWorkers: Enabling Autonomous, Developer Friendly Programming at the EdgeEdgeWorkers: Enabling Autonomous, Developer Friendly Programming at the Edge
EdgeWorkers: Enabling Autonomous, Developer Friendly Programming at the EdgeAkamai Developers & Admins
 
Connecting to a Webservice.pdf
Connecting to a Webservice.pdfConnecting to a Webservice.pdf
Connecting to a Webservice.pdfShaiAlmog1
 
GWT training session 3
GWT training session 3GWT training session 3
GWT training session 3SNEHAL MASNE
 
Universal JS Applications with React
Universal JS Applications with ReactUniversal JS Applications with React
Universal JS Applications with ReactThanh Trần Trọng
 
Jakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testyJakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testyPaweł Tekliński
 
Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsSami Ekblad
 
Refactoring domain driven design way
Refactoring domain driven design wayRefactoring domain driven design way
Refactoring domain driven design wayAndi Pangeran
 
Protocol-Oriented Networking
Protocol-Oriented NetworkingProtocol-Oriented Networking
Protocol-Oriented NetworkingMostafa Amer
 
Creating a Facebook Clone - Part XXVII - Transcript.pdf
Creating a Facebook Clone - Part XXVII - Transcript.pdfCreating a Facebook Clone - Part XXVII - Transcript.pdf
Creating a Facebook Clone - Part XXVII - Transcript.pdfShaiAlmog1
 

Similar to Restaurant Server.pdf (20)

Angular Tutorial Freshers and Experienced
Angular Tutorial Freshers and ExperiencedAngular Tutorial Freshers and Experienced
Angular Tutorial Freshers and Experienced
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
REST API for your WP7 App
REST API for your WP7 AppREST API for your WP7 App
REST API for your WP7 App
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
EdgeWorkers: Enabling Autonomous, Developer Friendly Programming at the Edge
EdgeWorkers: Enabling Autonomous, Developer Friendly Programming at the EdgeEdgeWorkers: Enabling Autonomous, Developer Friendly Programming at the Edge
EdgeWorkers: Enabling Autonomous, Developer Friendly Programming at the Edge
 
Connecting to a Webservice.pdf
Connecting to a Webservice.pdfConnecting to a Webservice.pdf
Connecting to a Webservice.pdf
 
GWT training session 3
GWT training session 3GWT training session 3
GWT training session 3
 
Universal JS Applications with React
Universal JS Applications with ReactUniversal JS Applications with React
Universal JS Applications with React
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 
Jakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testyJakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testy
 
Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-ons
 
Refactoring domain driven design way
Refactoring domain driven design wayRefactoring domain driven design way
Refactoring domain driven design way
 
Protocol-Oriented Networking
Protocol-Oriented NetworkingProtocol-Oriented Networking
Protocol-Oriented Networking
 
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter LehtoJavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
 
Creating a Facebook Clone - Part XXVII - Transcript.pdf
Creating a Facebook Clone - Part XXVII - Transcript.pdfCreating a Facebook Clone - Part XXVII - Transcript.pdf
Creating a Facebook Clone - Part XXVII - Transcript.pdf
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Restaurant Server.pdf

  • 2. Restaurant Server ✦I will not go into all of the details because many pieces are mundane and boring ✦The server portion is relatively easier when we have a client ready but there is a lot of hidden complexity ✦This is especially true when it comes to security which is often unintuitive © Codename One 2017 all rights reserved
  • 3. Standard Spring Boot project ✦We’ll create pretty much the same spring boot project we created in the spring boot tutorial ✦I’ll go with a new Database URL to start fresh and new project name “AppBackendServer”. The generic name makes sense for the app maker… ✦My goal isn’t to win an “architecture award” but to create the bare minimum server within reason © Codename One 2017 all rights reserved
  • 5. @Controller @RequestMapping("/braintree") public class BraintreePaymentService { @Autowired private RestaurantRepository restaurantRepository; @Autowired private OrderRepository orderRepository; private WeakHashMap<String, BraintreeGateway> gatewayCache = new WeakHashMap<>(); private BraintreeGateway getGateway(String auth) { BraintreeGateway bg = gatewayCache.get(auth); if(bg != null) { return bg; } RestaurantEntity r = restaurantRepository.findOne(auth); if(r != null) { bg = new BraintreeGateway( Environment.SANDBOX, r.getMerchantId(), r.getPublicKey(), r.getPrivateKey() ); gatewayCache.put(auth, bg); return bg; } return null; } BraintreePaymentService
  • 6. @Controller @RequestMapping("/braintree") public class BraintreePaymentService { @Autowired private RestaurantRepository restaurantRepository; @Autowired private OrderRepository orderRepository; private WeakHashMap<String, BraintreeGateway> gatewayCache = new WeakHashMap<>(); private BraintreeGateway getGateway(String auth) { BraintreeGateway bg = gatewayCache.get(auth); if(bg != null) { return bg; } RestaurantEntity r = restaurantRepository.findOne(auth); if(r != null) { bg = new BraintreeGateway( Environment.SANDBOX, r.getMerchantId(), r.getPublicKey(), r.getPrivateKey() ); gatewayCache.put(auth, bg); return bg; } return null; } BraintreePaymentService
  • 7. @RequestMapping(method=RequestMethod.GET) public @ResponseBody String getToken(@RequestParam(name = "auth") String auth) { return getGateway(auth).clientToken().generate(); } @RequestMapping(method=RequestMethod.POST) public @ResponseBody PurchaseResult purchase(@RequestBody(required=true) Order i) { TransactionRequest request = new TransactionRequest() .amount(i.calculateAmount()) .paymentMethodNonce(i.getNounce()) .options() .submitForSettlement(true) .done(); Result<Transaction> result = getGateway(i.getAuth()).transaction().sale(request); if(result.isSuccess()) { // Store entry and email restaurant } return new PurchaseResult(result.isSuccess(), result.getMessage()); } } BraintreePaymentService
  • 8. @RequestMapping(method=RequestMethod.GET) public @ResponseBody String getToken(@RequestParam(name = "auth") String auth) { return getGateway(auth).clientToken().generate(); } @RequestMapping(method=RequestMethod.POST) public @ResponseBody PurchaseResult purchase(@RequestBody(required=true) Order i) { TransactionRequest request = new TransactionRequest() .amount(i.calculateAmount()) .paymentMethodNonce(i.getNounce()) .options() .submitForSettlement(true) .done(); Result<Transaction> result = getGateway(i.getAuth()).transaction().sale(request); if(result.isSuccess()) { // Store entry and email restaurant } return new PurchaseResult(result.isSuccess(), result.getMessage()); } } BraintreePaymentService
  • 9. @RequestMapping(method=RequestMethod.GET) public @ResponseBody String getToken(@RequestParam(name = "auth") String auth) { return getGateway(auth).clientToken().generate(); } @RequestMapping(method=RequestMethod.POST) public @ResponseBody PurchaseResult purchase(@RequestBody(required=true) Order i) { TransactionRequest request = new TransactionRequest() .amount(i.calculateAmount()) .paymentMethodNonce(i.getNounce()) .options() .submitForSettlement(true) .done(); Result<Transaction> result = getGateway(i.getAuth()).transaction().sale(request); if(result.isSuccess()) { // Store entry and email restaurant } return new PurchaseResult(result.isSuccess(), result.getMessage()); } } BraintreePaymentService
  • 10. @RequestMapping(method=RequestMethod.GET) public @ResponseBody String getToken(@RequestParam(name = "auth") String auth) { return getGateway(auth).clientToken().generate(); } @RequestMapping(method=RequestMethod.POST) public @ResponseBody PurchaseResult purchase(@RequestBody(required=true) Order i) { TransactionRequest request = new TransactionRequest() .amount(i.calculateAmount()) .paymentMethodNonce(i.getNounce()) .options() .submitForSettlement(true) .done(); Result<Transaction> result = getGateway(i.getAuth()).transaction().sale(request); if(result.isSuccess()) { // Store entry and email restaurant } return new PurchaseResult(result.isSuccess(), result.getMessage()); } } BraintreePaymentService
  • 11. @Entity @Table(name="Restaurant") public class RestaurantEntity { @Id private String id; private String name; private String merchantId; private String publicKey; private String privateKey; private double currentVersionIOS = 1.0; private double lastSupportedVersionIOS = 0; private double currentVersionAnd = 1.0; private double lastSupportedVersionAnd = 0; private double currentVersionUWP = 1.0; private double lastSupportedVersionUWP = 0; private long dishListUpdateTimestamp = 1; private String restaurantEmail; @OneToMany private Set<DishEntity> dishes; @OneToMany private Set<CategoryEntity> categories; public RestaurantEntity() { id = UUID.randomUUID().toString(); } RestaurantEntity
  • 12. @Entity @Table(name="Purchases") public class OrderEntity { @Id private String id; @OneToMany private Set<OrderLineEntity> dishQuanity; private Date date; private String notes; public OrderEntity() { id = UUID.randomUUID().toString(); } OrderEntity vs. dao Order public class Order { private String id; private Date date; private boolean purchased; private Map<Dish, Integer> dishQuantity = new HashMap<>(); private String notes; private String nounce; private String auth; public BigDecimal calculateAmount() { BigDecimal b = BigDecimal.ZERO; for(Map.Entry<Dish, Integer> d : dishQuantity.entrySet()) { b = b.add(new BigDecimal( d.getValue() * d.getKey(). getPrice())); } return b; }
  • 13. @Controller @RequestMapping("/ver") public class VersionService { @Autowired private RestaurantRepository restaurantRepository; @RequestMapping(method=RequestMethod.GET) public @ResponseBody AppVersion getKey(@RequestParam(value="os", required=true) String os, @RequestParam(value="appId", required=true) String appId) { RestaurantEntity r = restaurantRepository.findOne(appId); switch(os) { case "ios": return new AppVersion(r.getCurrentVersionIOS(), r.getLastSupportedVersionIOS()); case "and": return new AppVersion(r.getCurrentVersionAnd(), r.getLastSupportedVersionAnd()); case "win": return new AppVersion(r.getCurrentVersionUWP(), r.getLastSupportedVersionUWP()); } return null; } } VersionService