A Spring Boot REST API for managing journal entries with two versions:
- V1: Basic CRUD with in-memory storage (HashMap)
- V2: CRUD with MongoDB persistence
- Java 17+
- Maven
- MongoDB running on
serverURL
./mvnw spring-boot:runThe application runs on http://localhost:8080
Basic CRUD operations using an in-memory HashMap. Data is lost when the application restarts.
| Method | Endpoint | Description |
|---|---|---|
| GET | /journal |
Get all entries |
| POST | /journal |
Create a new entry |
| GET | /journal/id/{id} |
Get entry by ID |
| DELETE | /journal/id/{id} |
Delete entry by ID |
| PATCH | /journal/id/{id} |
Update entry by ID |
CRUD operations with MongoDB persistence. Data is stored in the journal_entries collection.
| Method | Endpoint | Description |
|---|---|---|
| GET | /V2/journal |
Get all entries |
| POST | /V2/journal |
Create a new entry |
| GET | /V2/journal/id/{id} |
Get entry by ID |
| DELETE | /V2/journal/id/{id} |
Delete entry by ID |
| PATCH | /V2/journal/id/{id} |
Update entry by ID |
curl -X POST http://localhost:8080/V2/journal \
-H "Content-Type: application/json" \
-d '{
"title": "My First Entry",
"content": "This is my journal content"
}'Response: true
curl http://localhost:8080/V2/journalResponse:
[
{
"id": "67a4b1c2d3e4f5a6b7c8d9e0",
"title": "My First Entry",
"content": "This is my journal content",
"date": null
}
]curl http://localhost:8080/V2/journal/id/67a4b1c2d3e4f5a6b7c8d9e0Response:
{
"id": "67a4b1c2d3e4f5a6b7c8d9e0",
"title": "My First Entry",
"content": "This is my journal content",
"date": null
}curl -X PATCH http://localhost:8080/V2/journal/id/67a4b1c2d3e4f5a6b7c8d9e0 \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Title",
"content": "Updated content"
}'Response: Returns the updated entry
curl -X DELETE http://localhost:8080/V2/journal/id/67a4b1c2d3e4f5a6b7c8d9e0Response: true
src/main/java/com/example/firstusingmaven/
├── FirstUsingMavenApplication.java # Main application class
├── controller/
│ ├── JournalEntryController.java # V1 controller (in-memory)
│ └── JournalEntryControllerV2.java # V2 controller (MongoDB)
├── entity/
│ ├── journalEntry.java # V1 entity
│ └── journalEntryV2.java # V2 entity (MongoDB document)
├── repository/
│ └── JournalEntryRepository.java # MongoDB repository
└── service/
└── JournalEntryServiceV2.java # V2 service layer
Configuration in application.properties:
spring.data.mongodb.uri=mongodb://localhost:27017/journalDbThe V2 entries are stored in the journal_entries collection in the journalDb database.
| Field | Type | Description |
|---|---|---|
| id | String | MongoDB ObjectId (auto-generated) |
| title | String | Entry title |
| content | String | Entry content |
| date | Date | Entry date (optional) |