Skip to content

A sample REST API application Layered Architecture, CRUD and not only operations and Tests

Notifications You must be signed in to change notification settings

Almielka/spring-boot-rest-api-mysql-jpa-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST API application Layered Architecture, CRUD and not only operations and Tests

Tools and Technologies: Java8, Spring Boot, MySQL, Maven, IntelliJ IDEA, REST API, Postman, JUnit, Mockito.

Database configuration

Project uses an in-memory database MySQL which gets populated at startup with data.

Security configuration

Basic Authentication

REST API is secured with HTTP Basic Authentication. The existing roles are listed below with the corresponding percompanies:

  • Content Manager — administrator able to manage comanies and products

login: Manager

password: Manager

  • Customer — able to search and order products

login: Customer

password: Customer

Layered Architecture

Layer Source
JavaBean domain domain folder
Repositories repository folder
Services service folder
REST API Controllers controller folder
Security Configuration security folder
Tests tetst controllers

Functionality to support managing

Company Management


Add Company:


URL: http://localhost:8080/api/companies

HTTP-method: POST

Data:

  • Unique company name
  • Company type — a type the company. Possible types are: TYPE1, TYPE2, TYPE3

RequestBody:

{
    "name": "company6-3",
    "companyType": "TYPE3"
}

Edit Company by ID:

URL: http://localhost:8080/api/companies/6

HTTP-method: PUT

Data:

  • Unique company name
  • Company type — a type the company. Possible types are: TYPE1, TYPE2, TYPE3

RequestBody:

{
    "name": "UpdateCompany6-1",
    "companyType": "TYPE1"
}

Edit Company by Name:

URL: http://localhost:8080/api/companies/name/UpdateCompany6-1

HTTP-method: PUT

Data:

  • Unique company name
  • Company type — a type the company. Possible types are: TYPE1, TYPE2, TYPE3

RequestBody:

{
    "name": "UpdateCompany2-2",
    "companyType": "TYPE2"
}

Get Company by ID:

URL: http://localhost:8080/api/companies/2

HTTP-method: GET

Get Company/Companies by Name:

URL: http://localhost:8080/api/companies/name/comp

HTTP-method: GET

Remove Company by ID:

URL: http://localhost:8080/api/companies/6

HTTP-method: DELETE

Remove Company by Name:

URL: http://localhost:8080/api/companies/name/UpdateCompany6-1

HTTP-method: DELETE


Product Management


Add Product:

URL: http://localhost:8080/api/products

HTTP-method: POST

Data:

  • Company name
  • Product name
  • Product created date— the date when the product was made (UTC)
  • Price – the price of the product

RequestBody:

{
	"name": "product7",
	"createdDate": "2019-12-05T06:50:08Z",
	 "price": 20.5,
	 "company": {
            "name": "company4-3"
        }
}	

Remove Product by ID:

URL: http://localhost:8080/api/products/7

HTTP-method: DELETE


Product Search


by Product name:

URL: http://localhost:8080/api/products/search-by-name/product

HTTP-method: GET

by Company name:

URL: http://localhost:8080/api/products/search-by-company-name/company2-2

HTTP-method: GET

by Company Type:

URL: http://localhost:8080/api/products/search-by-company-type/TYPE2

HTTP-method: GET

before date:

URL: http://localhost:8080/api/products/search-before-date?date=2018-12-03T10:15:30.00Z

HTTP-method: GET

after date:

URL: http://localhost:8080/api/products/search-after-date?date=2018-12-03T10:15:30.00Z

HTTP-method: GET

between dates:

URL: http://localhost:8080/api/products/search-between-dates?afterDate=2017-02-03T10:15:30.00Z&beforeDate=2018-05-03T10:15:30.00Z

HTTP-method: GET


Product Ordering


add Order:

URL: http://localhost:8080/api/products/order

HTTP-method: POST

RequestBody:

[{"id":2},
{"id": 4}]

Another RequestBody: any result of search for example:

URL: http://localhost:8080/api/products/search-by-company-name/company

HTTP-method: GET

get History:

URL: http://localhost:8080/api/products/order/history

HTTP-method: GET

get a list of the most ordered products:

URL: http://localhost:8080/api/products/order/history-of-the-most-ordered-products

HTTP-method: GET

get a list of the most ordered companies:

URL: http://localhost:8080/api/products/order/history-of-the-most-ordered-companies

HTTP-method: GET

Releases

No releases published

Packages

No packages published

Languages