Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A REST API backend for a personal journaling application built with Spring Boot and MongoDB Atlas. Users can create accounts and manage journal entries scoped to their profile.


Tech stack

  • Java 17
  • Spring Boot
  • Spring Data MongoDB
  • MongoDB Atlas
  • Lombok

Project structure

src/main/java/com/example/yashjournal/
├── controller/
│   ├── UserController.java
│   └── JournalEntryController_v2.java
├── services/
│   ├── UserService.java
│   └── JournalEntryService.java
├── repository/
│   ├── UserRepo.java
│   └── JournalEntryRepo.java
└── entity/
    ├── User.java
    └── JournalEntry.java

Setup

Prerequisites

  • Java 17+
  • Maven
  • A MongoDB Atlas account with a cluster ready

Configuration

This project requires a MongoDB connection string. Do not commit your credentials.

Copy the example config and fill in your values:

cp src/main/resources/application.properties.example src/main/resources/application.properties

Then edit application.properties:

spring.data.mongodb.uri=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/<dbname>
spring.application.name=yashjournal

Run

mvn spring-boot:run

The server starts on http://localhost:8080.


API reference

Users

Method Endpoint Description
GET /users Get all users
POST /users Create a new user
GET /users/{username} Get user by username
PUT /users/{username} Update user by username
DELETE /users/{username} Delete user by username

Create user — request body

{
  "username": "boss",
  "password": "1234"
}

Journal entries

Method Endpoint Description
GET /journal Get all entries (all users)
GET /journal/{username} Get all entries for a user
POST /journal/{username} Create entry for a user
PUT /journal/{id} Update entry by ID
DELETE /journal/{id} Delete entry by ID

Create journal entry — request body

{
  "title": "Day 1",
  "content": "Today was a good day."
}

Data model

User

Field Type Notes
user_id String Auto-generated by MongoDB
username String Unique, required
password String Required
journalEntries List @DBRef to journal_entries collection

JournalEntry

Field Type Notes
id String Auto-generated by MongoDB
title String Required
content String Optional

How entries are linked to users

When a journal entry is created via POST /journal/{username}, the entry is first saved to the journal_entries collection. Its generated ID is then pushed into the corresponding user's journalEntries array in the users collection using a @DBRef reference. This means MongoDB stores a reference (not a copy) of the entry inside the user document.


Notes

  • application.properties is gitignored — never commit your Atlas credentials
  • Passwords are stored as plain text — this is a learning project, not production ready
  • No authentication layer is implemented yet

About

My first springboot application

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages