Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with the Payment Methods endpoint. Java : Simple Rest Server Instructions Create a simple server that uses simple design patterns Factory :

Please help me with the Payment Methods endpoint.

Java: Simple Rest Server

Instructions

Create a simple server that uses simple design patterns

  • Factory: Your server should parse the routes and create a new Processor class depending on the route
  • Builder: The process method of your Processor should use the Builder pattern to create a response.
  • DAO: Make a class that abstracts the data interactions away from the rest of the app
  • Singleton: Wrap your dao instance as a singleton class
  • Lazy Loading: DAOs should only load data when requested
  • DTO: Your JSON parsing, as well as response objects must be DTOs

First parse url, then use factory to instantiate correct Processor class. The factory will internally use the builder pattern to give the processor relevant data. Use builder to set the time, and input parameters.

Processor Class

  • Has a process() method that returns a ResponseDto object
  • Each endpoint is a subclass of Processor
  • Takes a hashmap of key value args
  • Use a factory to create these, based on the endpoint
  • Every processor uses a builder and returns the output of builder.build()

Response Class

  • This class gets stringified with GSON
  • Needs a ResponseBuilder helper
  • Needs Params Map (String, String)
  • Needs response dto
  • Needs Response Code (String)

Dao class

  • Singleton
  • Lazy load data
  • 1 DAO per type of endpoint to hold the data

Endpoints

  • Payment Methods
    • /addPaymentMethod?method=name
      • creates a new payment method and stores it in the paymentMethod DAO
      • assigns a machine code
      • needs Payment DTO + Payment DAO
      • fields: name, machineCode
    • /getAllPaymentMethods
      • Returns list of all payment methods
  • Items
    • /addItem?name=name&price=price
      • Creates a new item and gives it a price
      • Assigns machine readable code and returns it
      • needs ItemDAO + Item DTO
      • fields: name, price, machineCode
    • /listItems
      • returns all items
  • Transactions
    • /createTransaction?itemCode=code&paymentMethod=paymentCode
      • Must have valid payment method
      • fields: itemCode, paymentMethod
    • /listTransactions
      • returns all transaction
      • needs TransactionDAO + Transaction DTO

High level steps

  1. Parse request and extract the endpoint
  2. Parse the get args into a hashmap
  3. Use factory to instantiate correct processor class
  4. Call .process(args) and pass in the arguments on this class (args is a hash map of the get params)
  5. Inside the processor it can get or put data through the DAO
  6. Business Logic goes in processor Load/Store logic goes in DAO
  7. Returns a single ResponseDto
  8. Stringify this response dto and pass it into the output stream

Return Format

You will need a response class that looks like this before passing to JSON.

"{

"date": "2019-02-10T20:40:59.257Z", // time that this was generated

"params": {

"a": 2 // full list of all key value get params

},

responseCode: OK/ERROR

"response": {}, // put your responses here

}"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database Systems Architecture And Techniques

Authors: Kam-Yiu Lam ,Tei-Wei Kuo

1st Edition

1475784023, 978-1475784022

More Books

Students also viewed these Databases questions