This is the Java backend API for the Speak for the Trees frontend.
First follow all the steps for setting up the general development environment which can be found here. This will walk you through:
- Installing, creating, and running a local PostgreSQL database (
speak-for-the-trees) - Configuring IntelliJ
- Installing Maven
- Installing Java 8
- Configuring project properties files
- Compiling and running the API
Following these steps, all that is left is to import data into the database. This has been made easy through import routes. You can find these import routes in the Postman collection posted below. Follow the steps below in order to import all the relevant data:
- Call
POST api/v1/user/signupto create a super admin user with a JSON body that follows the format of:{ "username": "someUsername", "email": "some@email.com", "password": "somePassword", "firstName": "someFirstName", "lastName": "someLastName" }- Using your preferred method for postgres (Intellij, PgAdmin, postgres console, etc.) edit the user row you just created so that their
privilege_levelcolumn is equal toSUPER_ADMIN - Call
POST /api/v1/user/loginto login to your admin user account with a JSON body that follows the format of:
{ "email": "your@email.com", "password": "yourPassword" }- Copy the "accessToken" returned by that call and add it as the value of a header called 'X-Access-Token' for all seeding API calls
- Using your preferred method for postgres (Intellij, PgAdmin, postgres console, etc.) edit the user row you just created so that their
- Import data is stored in the
SFTT.import.dataS3 bucket. Ask one of the team leads for the .json files- Call
POST api/v1/protected/import/neighborhoodswith the contents ofneighborhoods.jsonas the body - Call
POST api/v1/protected/import/siteswith the contents ofsites.jsonas the body. - Call
POST api/v1/protected/import/tree_specieswith the contents oftree_species.jsonas the body. - Call
POST api/v1/protected/import/tree_benefitswith the contents oftree_benefits.jsonas the body.
- Call
At this point your database is fully set up and contains real data for neighborhoods and trees around Boston!
The ServiceMain.java class has the main method for running the code, this can be run directly in IntelliJ. Alternatively: mvn install creates a jar file at: service/target/service-1.0-SNAPSHOT-jar-with-dependencies.jar. This can be run from the command line with the command java -jar service-1.0-SNA..... The API will then be available at http://localhost:8081 by default.
Our Postman collection is an ever expanding list of routes that can easily be called through Postman. You can find our latest collection here. Make sure the API is running when you try to call a route.
The official API specification for this backend can be found at https://docs.c4cneu.com/sftt/sftt-api-spec/. This lists every single route that is callable, explains what it does, shows the associated request body and lists the possible responses. When making changes to the backend developers should create a matching PR for the API spec reflecting their changes.
The database schema can be found here: https://lucid.app/lucidchart/2e440718-aca6-4efa-adb1-4fc6112bcf42/view. This is an up-to-date overview of what fields the database contains.