This is a Spring Boot application designed to manage cash cards with basic functionality such as creating, retrieving, updating, and deleting cards.
- Java JDK 17 or later
- Maven 3.6 or later (for building the project)
To get started with this project:
-
Clone the repository:
git clone https://github.com/0xsuid/cashcard-api.git cd cashcard-api -
Build the project:
./gradlew build
-
Run the application:
./gradlew bootRun
- GET /cashcards: Retrieve all cash cards.
- POST /cashcards: Create a new cash card.
- GET /cashcards/{id}: Retrieve a specific cash card by ID.
- PUT /cashcards/{id}: Update an existing cash card.
- DELETE /cashcards/{id}: Delete a specific cash card.
The project includes comprehensive tests for the endpoints. To run the tests:
./gradlew testHere is a sample test case that retrieves a cash card by ID:
@Test
void shouldReturnACashCardWhenDataIsSaved() {
ResponseEntity<String> response = restTemplate
.withBasicAuth("sarah1", "abc123")
.getForEntity("/cashcards/99", String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
DocumentContext documentContext = JsonPath.parse(response.getBody());
Number id = documentContext.read("$.id");
assertThat(id).isEqualTo(99);
Double amount = documentContext.read("$.amount");
assertThat(amount).isEqualTo(123.45);
}This test ensures that the API correctly retrieves a cash card with the specified ID and verifies its contents.
The application includes basic authentication for managing cash cards. Ensure to set up appropriate credentials in your environment.
Contributions are welcome! Please fork the repository and submit pull requests or open issues for bug reports or feature suggestions.