This repository has been archived on 2022-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
DevOpsOpenHack/apis/user-java
2022-11-03 16:41:13 -04:00
..
src add openhack files 2022-11-03 16:41:13 -04:00
.gitignore add openhack files 2022-11-03 16:41:13 -04:00
buildtest.sh add openhack files 2022-11-03 16:41:13 -04:00
Dockerfile add openhack files 2022-11-03 16:41:13 -04:00
pom.xml add openhack files 2022-11-03 16:41:13 -04:00
README.md add openhack files 2022-11-03 16:41:13 -04:00

Overview

This server was generated by the swagger-codegen project.
By using the OpenAPI-Spec, you can easily generate a server stub.
This is an example of building a swagger-enabled server in Java using the SpringBoot framework.

The underlying library integrating swagger to SpringBoot is springfox

Start your server as an simple java application.

You can view the api documentation in swagger-ui by pointing to http://localhost:8080/api/swagger-ui.html

Change default port value in src/main/resources/application.properties

Build the project

  1. Install Maven https://maven.apache.org/install.html and setup the environment path accordingly

  2. Go into the project root directory that has the pom.xml and run mvn package

Run only the unit tests

mvn test

Run the application

  1. Modify the src/main/resources/application.properties values with valid SQL Server values.

    spring.datasource.url=someurl
    spring.datasource.username=username
    spring.datasource.password=password
    
  2. Start the API: mvn spring-boot:run

POST API Example

This curl command creates a new user with ID 1234.

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
   "createdAt":"2018-08-07", \
   "deleted": false, \
   "firstName": "Hacker", \
   "fuelConsumption": 0, \
   "hardAccelerations": 0, \
   "hardStops": 0, \
   "id": "1234", \
   "lastName": "Test", \
   "maxSpeed": 0, \
   "profilePictureUri": "https://pbs.twimg.com/profile_images/1003946090146693122/IdMjh-FQ_bigger.jpg", \
   "ranking": 0, \
   "rating": 0, \
   "totalDistance": 0, \
   "totalTime": 0, \
   "totalTrips": 0, \
   "updatedAt": "2018-08-07", \
   "userId": "Hacker3" \
 }' 'http://localhost:8080/api/user/1234'

PATCH API Example

This updates the fuelConsumption and hardStops fields from the user created above.

curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
  "fuelConsumption":20, \
  "hardStops":74371 \
}