Coder Social home page Coder Social logo

fernandoguide / clean-architecture-example-java-spring-boot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grant-burgess/clean-architecture-example-java-spring-boot

0.0 0.0 0.0 128 KB

My interpretation of Clean Architecture with Spring Boot

License: Apache License 2.0

Java 100.00%

clean-architecture-example-java-spring-boot's Introduction

Offer service

Dear stargazers, hope you like the project. Feel free to ask questions. I'll add some diagrams when I get a chance

This is a REST based service that allows API consumers to create, cancel and query offers for merchants.

The project was developed using TDD. The system architecture is heavily inspired by Robert C. Martin's Clean Architecture, a use case driven approach. I developed this program with the mindset that this module is apart of a large system and attempted to make it as modular and pluggable as possible.

The APIs invoke a single Use Case. The Use Case constructs and acts over one to many Entities and in doing so also talks to a Gateway more commonly known as Repository or Adapters. When an API needs to return a result, a Presenter is passed into the API. As we pass through the various layers we use separate models. Use Cases produce Response Models, Presenters produce View Models.

For the delivery mechanism I used Spring's REST controllers to deliver JSON

There are 4 public APIs

  • Create Offer
POST /offer-service/api/v1/offers
{
  "name: "offer name",
  "description: "offer description",
  "price: "5.00",
  "currency: "GBP",
  "duration: {
    "startDate: "2018-01-01",
    "endDate: "2018-01-31"
  }
}

Response
HTTP Status 201 Created
{
  id: "12c3009d-046d-411c-85eb-6e379e2f5d2a"
}
  • Cancel Offer

There are various ways in which we could cancel an offer e.g. use the PATCH or DELETE HTTP method, I instead opted for a command style

POST /offer-service/api/v1/offers/{offer-id}/cancel

Response
HTTP Status 204 No Content
  • Get Offers
GET  /offer-service/api/v1/offers`

Response
HTTP Status 200
offers: [
  {
    id: "12c3009d-046d-411c-85eb-6e379e2f5d2a",
    name: "offer name",
    description: "offer description",
    price: "5.00",
    currency: "GBP",
    duration: {
      startDate: "2018-01-01",
      endDate: "2018-01-31"
    },
    status: "ACTIVE|EXPIRED"
  },
  {
    id: "cc3453d7-6d75-422c-87da-37ee9f65bd11",
    ...
  },
  {
    id: "3f5f779c-b145-49fd-8a73-c8770fad072a",
    ...
  }
]

  • Get Offer by ID
GET  /offer-service/api/v1/offers/{offer-id}`

Response
HTTP Status 200
{
  id: "12c3009d-046d-411c-85eb-6e379e2f5d2a",
  name: "offer name",
  description: "offer description",
  price: "5.00",
  currency: "GBP",
  duration: {
    startDate: "2018-01-01",
    endDate: "2018-01-31"
  },
  status: "ACTIVE|EXPIRED"
}

Or

HTTP Status 404 Not Found

Project dependencies

This project uses Java 8 with Spring Boot, H2 database and Swagger for API documentation. Tests were written with JUnit4.

Running the application

To build the project, run:

gradlew clean build

To run the application, from the root of the project run:

gradlew bootRun

View the Swagger documentation

clean-architecture-example-java-spring-boot's People

Contributors

grant-burgess avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.