Skip to content

flex0690/SpringBoot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Journal Entry Application

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

Prerequisites

  • Java 17+
  • Maven
  • MongoDB running on serverURL

Running the Application

./mvnw spring-boot:run

The application runs on http://localhost:8080


API Endpoints

V1 - In-Memory Storage (/journal)

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

V2 - MongoDB Storage (/V2/journal)

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

V2 API Usage Examples

Create Entry

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

Get All Entries

curl http://localhost:8080/V2/journal

Response:

[
  {
    "id": "67a4b1c2d3e4f5a6b7c8d9e0",
    "title": "My First Entry",
    "content": "This is my journal content",
    "date": null
  }
]

Get Entry by ID

curl http://localhost:8080/V2/journal/id/67a4b1c2d3e4f5a6b7c8d9e0

Response:

{
  "id": "67a4b1c2d3e4f5a6b7c8d9e0",
  "title": "My First Entry",
  "content": "This is my journal content",
  "date": null
}

Update Entry (PATCH)

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

Delete Entry

curl -X DELETE http://localhost:8080/V2/journal/id/67a4b1c2d3e4f5a6b7c8d9e0

Response: true


Project Structure

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

MongoDB Configuration

Configuration in application.properties:

spring.data.mongodb.uri=mongodb://localhost:27017/journalDb

The V2 entries are stored in the journal_entries collection in the journalDb database.

Journal Entry V2 Schema

Field Type Description
id String MongoDB ObjectId (auto-generated)
title String Entry title
content String Entry content
date Date Entry date (optional)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages