8000 GitHub - BetterCodeSoon/showcase-app: β˜• A simple showcase of a dockerized Java/Spring Boot backend web app.
[go: up one dir, main page]

Skip to content

β˜• A simple showcase of a dockerized Java/Spring Boot backend web app.

Notifications You must be signed in to change notification settings

BetterCodeSoon/showcase-app

Repository files navigation

✨ Showcase-App Overview ✨

Table of Contents


πŸ“˜ Introduction

πŸ—‚οΈ Project Overview

This app is a simple showcase of a containerized REST API Java backend using Spring Boot, a relational database and modern development practices like automated testing. πŸ§‘β€πŸŽ¨πŸ™Œ

🎯 Features

  • Create, read, update, and delete (very! 😏) simple AppInfo objects in the database! 🀯
  • RESTful endpoints
  • Examples of automated integration- and unit tests
  • Containerized setup

πŸ“¦ Example: Saving an AppInfo Object

To save an object, send a JSON like this to the POST endpoint:

{
    "version": "0.0.1",
    "description": "A bare skeleton of an app."
}

βš™οΈ How It Works

  1. The REST controller receives the JSON.
  2. It converts the JSON to an AppInfo object.
  3. The object is passed to a service.
  4. The services has access to a repository that can persist the object with an auto generated, sequential ID in the database.

πŸ’‘ Side Note:
For a sketch of a different approach: Namely, autogenerated UUID's (useful for distributed systems) see the Note class and the script to ensure UUIDv7 generation on the database level.

⚑ Quick Summary

All other operations work in a similar way.
As recommended entry points to the code, check out the Docker Compose file, the AppInfo class or the ITAppInfoControllerSpec integration test.


πŸ‘Ύ Tech Stack


πŸ“‹ Requirements

To build and run the project you need the following software installed and available in your systems PATH.

  • Docker 28.2.2, build e6534b4
  • Docker Compose 2.36.2
  • MariaDB 11.4.7
  • Java SDK 21.0.7
  • IDE of your choice for Java/Groovy development

πŸ› οΈ Project Setup and Configuration

1. 🌳 Clone the Repository

  • Clone this repository to your local machine and open it in your favorite IDE.

2. πŸ“ Configure Environment and Application Files

2.1. Create Environment Variables File

  • Copy template.env to .env in the project root directory.
  • Edit .env to set your local credentials and configuration.

2.2. Create Default Spring Profile

2.3. Create Debug Spring Profile

2.4. Create Integration Test Spring Profile

πŸ’‘ For all templates: Follow the instructions inside each file to complete your configuration.

2.5. Set Gradle JDK Path

  • Open gradle.properties and change:
    org.gradle.java.installations.paths={AbsolutePathToYourJDK}

3. πŸ—„οΈ Set Up Local MariaDB for Integration Tests

  • Ensure MariaDB is running on port 7306 (see 🐬 How-To: Change MariaDB Port).
  • If using a different port, update the value in application-integration.properties (e.g., jdbc:mariadb://localhost:{yourPort}).

4. πŸ’Ύ Set Up Persistent Storage for Database Containers

5. 🐳 Docker & Docker Compose

  • Make sure Docker and Docker Compose are installed and running.
  • If you encounter issues (😬) you can consult 🐳 Docker-Help (which also includes links to maintenance scripts).

6. πŸ”Œ Make the build script executable

6.1. Goto the directory of the create-and-run-app.sh script

  • cd scripts/

6.2. Make it executable with the terminal cmd:

  • chmod +x create-and-run-app.sh

πŸ’‘ Side note: Inside the script are some additional config options and deactivated commands for troubleshooting (but highly recommended to leave those untouched! πŸ˜‰).


πŸ§‘β€πŸ”§πŸƒ Build and Run the App

1. πŸš€ Run the Build Script

  • To perform a normal build run: ./create-and-run-app.sh
  • To perform a complete clean build run: ./create-and-run-app.sh clean

2. πŸ“Š View Test Reports (Optional)

3. βœ… Successful Build

After executing the script this is what you should see if everything went well:

Successful build screenshot


πŸ§‘β€πŸ’» Testing the App Using the Endpoints

The following section lists the commands for the command line tool curl to test the app.
But you could also use a more visual tool like Postman if you like.

πŸ“¨ Create Entity

This will create the entity you send in the database.

  • POST url: http://localhost:9007/showcase-api/appinfo

  • Verbose curl cmd with response:
    curl -v -i -X POST http://localhost:9007/showcase-api/appinfo -H "Content-Type: application/json" -d '{"version": "0.0.1", "description": "A bare skeleton of an app."}'

πŸ“€πŸ“„ Retrieve Entity by ID

This will send you the entity you specified by its id from the database.

πŸ“€πŸ“‘ Retrieve all Entities as List

This will send you a list of ALL entities from the database.

πŸ“ Update Entity

This will update the entity you specified by its id in the database with the entity you send.

  • PUT url: http://localhost:9007/showcase-api/appinfo/{id}

  • Verbose curl cmd with response (for ID=1):
    curl -v -i -X PUT http://localhost:9007/showcase-api/appinfo/1 -H "Content-Type: application/json" -d '{"version": "0.0.2", "description": "A skeleton of an app that wastes up to 250mb!"}'

πŸ—‘ Delete Entity

This will delete the entity you specified by its id in the database.

πŸ“š References

About

β˜• A simple showcase of a dockerized Java/Spring Boot backend web app.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0