Java: Simple Rest Server-Payment Methods endpoint

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: DAO’s 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: namemachineCode
    • /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

}”

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our Guarantees

Money-back Guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism Guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision Policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy Policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation Guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more