Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions TaskManager-Project/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/mvnw text eol=lf
*.cmd text eol=crlf
33 changes: 33 additions & 0 deletions TaskManager-Project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
3 changes: 3 additions & 0 deletions TaskManager-Project/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip
292 changes: 292 additions & 0 deletions TaskManager-Project/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
# TaskManagerAPI-Project

A Spring Boot task manager application with user registration, HTTP Basic authentication, PostgreSQL persistence, REST APIs, and a simple browser-based frontend for managing tasks.

This project is designed for Spring Boot beginners who want to learn by building a real, practical application. It introduces common backend concepts step by step, including REST APIs, authentication, database persistence, service layers, repositories, and a simple frontend connection. The goal is to help new learners understand how different parts of a Spring Boot project work together in a friendly and hands-on way.

## Features

- User registration with unique usernames
- Password encryption using BCrypt
- Stateless HTTP Basic authentication
- Create, read, update, and delete tasks
- Assign tasks to registered users
- Filter task list by username
- PostgreSQL database integration
- Static frontend pages for login, registration, and task management
- Client-side validation for task forms and credentials

## Tech Stack

- Java 21
- Spring Boot 4.0.3
- Spring Web MVC
- Spring Security
- Spring Data JPA
- PostgreSQL
- Lombok
- Maven
- HTML, CSS, JavaScript

## Project Structure

```text
TaskManager-Project-master/
├── pom.xml
├── mvnw
├── mvnw.cmd
├── src/
│ ├── main/
│ │ ├── java/com/TaskManagerAPIProject/TaskManagerAPI_Project/
│ │ │ ├── TaskManagerApiProjectApplication.java
│ │ │ ├── PasswordDecryptAndEncrypt.java
│ │ │ ├── configration/
│ │ │ │ └── config.java
│ │ │ ├── controller/
│ │ │ │ ├── taskController.java
│ │ │ │ └── userController.java
│ │ │ ├── model/
│ │ │ │ ├── Task.java
│ │ │ │ ├── user.java
│ │ │ │ ├── UserPrinciple.java
│ │ │ │ └── dto/
│ │ │ ├── Repository/
│ │ │ │ ├── taskRepo.java
│ │ │ │ └── UserRepo.java
│ │ │ └── service/
│ │ │ ├── taskService.java
│ │ │ ├── userService.java
│ │ │ ├── userDetailService.java
│ │ │ └── DtoService.java
│ │ └── resources/
│ │ ├── application.properties
│ │ └── static/
│ │ ├── index.html
│ │ ├── task-ui.html
│ │ ├── styles.css
│ │ ├── login.js
│ │ └── app.js
│ └── test/
│ └── java/
└── README.md
Requirements
Before running the project, install:

Java 21
PostgreSQL
Maven, or use the included Maven wrapper
Database Configuration
The application reads PostgreSQL settings from environment variables.

Required variables:

DB_URL=jdbc:postgresql://localhost:5432/taskmanager
DB_USERNAME=your_postgres_username
DB_PASSWORD=your_postgres_password
Example database creation:

CREATE DATABASE taskmanager;
The project uses:

spring.jpa.hibernate.ddl-auto=update
This allows Hibernate to create or update database tables automatically.

Running the Application
On Windows:

mvnw.cmd spring-boot:run
On macOS/Linux:

./mvnw spring-boot:run
The application starts at:

http://localhost:8080
Frontend Pages
Open the login and registration page:

http://localhost:8080/
After login, the dashboard opens:

http://localhost:8080/task-ui.html
The frontend stores the Basic Auth header and username in browser sessionStorage.

Authentication
The app uses Spring Security with HTTP Basic authentication.

Public routes:

GET /
GET /index.html
GET /task-ui.html
GET /styles.css
GET /login.js
GET /app.js
GET /register
POST /register
Protected routes:

GET /task
GET /task/{id}
POST /task
PUT /task
DELETE /task/{id}
API Endpoints
Register User
POST /register
Request body:

{
"username": "john",
"password": "1234"
}
Response:

Registered
Notes:

Username is trimmed and converted to lowercase.
Password is encrypted before saving.
Duplicate usernames return a conflict error.
View All Users
GET /register
Response:

[
{
"id": 1,
"username": "john",
"password": "encrypted_password"
}
]
Get Tasks By Username
GET /task?username=john
Requires Basic Auth.

Response:

[
{
"title": "Complete project",
"description": "Finish task manager API",
"priority": "High",
"dueDate": "2026-04-20"
}
]
Get Task By ID
GET /task/1
Requires Basic Auth.

Response:

{
"id": 1,
"title": "Complete project",
"description": "Finish task manager API",
"priority": "High",
"dueDate": "2026-04-20",
"createdAt": "2026-04-18"
}
Create Task
POST /task?username=john
Requires Basic Auth.

Request body:

{
"title": "Complete project",
"description": "Finish task manager API",
"priority": "High",
"dueDate": "2026-04-20"
}
Response:

Inserted
Update Task
PUT /task
Requires Basic Auth.

Request body:

{
"id": 1,
"title": "Complete project update",
"description": "Update task details",
"priority": "Medium",
"dueDate": "2026-04-25"
}
Response:

Updated
Delete Task
DELETE /task/1
Requires Basic Auth.

Response:

Deleted
Task Model
{
"id": 1,
"title": "Task title",
"description": "Task description",
"priority": "High",
"dueDate": "2026-04-20",
"createdAt": "2026-04-18",
"assignedTo": {
"id": 1,
"username": "john"
}
}
User Model
{
"id": 1,
"username": "john",
"password": "encrypted_password"
}
Example cURL Commands
Register a user:

curl -X POST http://localhost:8080/register \
-H "Content-Type: application/json" \
-d "{\"username\":\"john\",\"password\":\"1234\"}"
Create a task:

curl -X POST "http://localhost:8080/task?username=john" \
-u john:1234 \
-H "Content-Type: application/json" \
-d "{\"title\":\"Learn Spring Boot\",\"description\":\"Build task manager API\",\"priority\":\"High\",\"dueDate\":\"2026-04-20\"}"
Get user tasks:

curl "http://localhost:8080/task?username=john" \
-u john:1234
Update a task:

curl -X PUT http://localhost:8080/task \
-u john:1234 \
-H "Content-Type: application/json" \
-d "{\"id\":1,\"title\":\"Updated task\",\"description\":\"Updated description\",\"priority\":\"Medium\",\"dueDate\":\"2026-04-25\"}"
Delete a task:

curl -X DELETE http://localhost:8080/task/1 \
-u john:1234
Testing
Run tests with:

mvnw.cmd test
On macOS/Linux:

./mvnw test
Notes
createdAt is set automatically when a task is created.
Usernames are stored in lowercase.
Tasks are linked to users through the assignedTo relationship.
The application uses stateless sessions, so each protected API request must include authentication.
Database credentials should be provided through environment variables, not hardcoded.
Future Improvements
Add JWT authentication
Add task status field
Add pagination for task lists
Hide passwords from user listing responses
Add stronger backend validation
Add role-based authorization
Add unit and integration tests for controllers and services
Loading