/TodoList-API

Primary LanguageJavaMIT LicenseMIT

TodoList-API


Logo

TodoList API

Explore the docs »

. Report Bug . Request Feature

Downloads Forks Issues

Table Of Contents

About The Project

Screen Shot

This is a Todo List API created with Java Spring. It allows users to create an account and log in. Only authorized users can use the API to manage their Todo Lists and Todo List Items. The API is connected to a Postgre database, which includes five tables: Users, Roles, User Role Junctions, Todo Lists, and Todo Items.

The API contains several endpoints that allow users to manage their todo lists and items, such as creating, updating, and deleting them. These endpoints are restricted based on the user's authorization level, ensuring that only the user can manage their own todo lists and items. If the input is invalid, the API will handle it appropriately using a strong error handling mechanism.

Built With

Java Spring & PostgreSQL Dependencies

  • Spring JPA Data
  • Spring WEB
  • Spring Security
  • Spring DevTools
  • Spring Validation
  • Lombok
  • OAuth2
  • Model Mapper
  • PostgreSQL Driver

Getting Started

To use this API, you'll need to have Java and Spring installed on your computer. You'll also need to clone this repository and set up a Postgre database. Then fill the application.properties based on your database

Installation

application.properties can be found in the following directory src/main/resources/application.properties

application.properties

server.port=8000
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.show-sql=false
spring.datasource.url=jdbc:postgresql://localhost:5432/todo
spring.datasource.username=postgres
spring.datasource.password=12345
spring.jpa.properties.javax.persistence.validation.mode = none

Change "todo" to your database name

spring.datasource.url=jdbc:postgresql://localhost:5432/todo

Fill the username and password fields based on your PostgreSQL application.

spring.datasource.username=postgres spring.datasource.password=12345

Also you can change the server port.

server.port=8000

Usage

To use this API, you'll need to make requests to the various endpoints using a tool like Postman or curl. The Admin account is added to the database as soon as the application runs. username: "admin" password: password

Here are the examples of the types of requests you can make:

User Registration

POST /auth/register
Content-Type: application/json
{
    "username": "johndoe",
    "password": "password123",
}

User Login

POST /auth/login
Content-Type: application/json
{
    "username": "johndoe",
    "password": "password123",
}

User Profile

POST /user/profile
Content-Type: application/json
Authorization: Bearer <token>

Example Response

{
    "username": "ahmet",
    "authorities": [
        {
            "roleId": 2,
            "authority": "USER"
        }
    ]
}

User Update

POST /user/profile/update
Content-Type: application/json
Authorization: Bearer <token>
{

    "username":"johndoe",
    "password":"password123",
    "accountNonLocked":"false"

}

Create TodoList

POST /user/create/todolist
Content-Type: application/json
Authorization: Bearer <token>
{
"name": "John Doe's Yoga Practice Todo List"
}

Delete TodoList

POST /user/delete/todolist/{id}
Content-Type: application/json
Authorization: Bearer <token>

Update TodoList

POST /user/update/todolist
Content-Type: application/json
Authorization: Bearer <token>
{

    "id":"2",
    "name": "Updated TodoListName"

}

Create TodoItem

POST /user/create/todoitem
Content-Type: application/json
Authorization: Bearer <token>
{
"name": "Yoga class at 6 PM",
"description": "Go to yoga class at 6pm at Mecidiyeköy",
"completed": false,
"todoListId": 1
}

Update TodoItem

POST /user/update/todoitem
Content-Type: application/json
Authorization: Bearer <token>
{

    "id":1,
    "name": "Yoga class at 4 PM",
    "description": "Yoga class was moved to 4 pm, don't forget to attend",
    "completed": false

}

Delete TodoList

POST /user/delete/todoitem/{id}
Content-Type: application/json
Authorization: Bearer <token>

User Get TodoLists

POST /user/get/todolists
Content-Type: application/json
Authorization: Bearer <token>

Example Response

[
    {
        "id": 23,
        "name": "Ahmet's Yoga Practice Todo List"
    },
    {
        "id": 24,
        "name": "Ahmet's Shopping TODO List"
    }
]

User Get TodoLists & Items

POST /user/get/todolistsanditems
Content-Type: application/json
Authorization: Bearer <token>

Example Response

[
    {
        "name": "Buy bunch of onions and 3 bread",
        "description": "This is all we can eat these days in Turkey ;)",
        "completed": false,
        "todoListId": 24,
        "todoListName": "Ahmet's Shopping TODO List"
    },
    {
        "name": "Buy Yoga Equipments",
        "description": "Buy Yoga equipments for the class at 4pm",
        "completed": false,
        "todoListId": 23,
        "todoListName": "Ahmet's Yoga Practice Todo List"
    },
    {
        "name": "Yoga class at 6 PM",
        "description": "Join yoga class at the local gym",
        "completed": false,
        "todoListId": 23,
        "todoListName": "Ahmet's Yoga Practice Todo List"
    }
]

Admin Get TodoLists & Items

POST /admin/get/todolistsanditems
Content-Type: application/json
Authorization: Bearer <token>

Example Response

[
    {
        "name": "1000 Pushups",
        "description": "1000 push ups in 10 days",
        "completed": false,
        "todoListName": "John's Gym Todo List",
        "todoListId": 21,
        "username": "john"
    },
    {
        "name": "Lose 10 kgs",
        "description": "Lose 10 kgs in 5 months",
        "completed": false,
        "todoListName": "John's Gym Todo List",
        "todoListId": 21,
        "username": "john"
    },
    {
        "name": "Run 4kms",
        "description": "Run 4 kms each day",
        "completed": false,
        "todoListName": "John's Gym Todo List",
        "todoListId": 21,
        "username": "john"
    },
    {
        "name": "Boxing Practice",
        "description": "Attend boxing practice every Tuesday and Thursday",
        "completed": false,
        "todoListName": "John's Boxing Todo List",
        "todoListId": 22,
        "username": "john"
    },
    {
        "name": "Yoga class at 6 PM",
        "description": "Join yoga class at the local gym",
        "completed": false,
        "todoListName": "Ahmet's Yoga Practice Todo List",
        "todoListId": 23,
        "username": "ahmet"
    },
    {
        "name": "Buy boxing gloves",
        "description": "Purchase a new pair of boxing gloves from Decathlon",
        "completed": false,
        "todoListName": "John's Boxing Todo List",
        "todoListId": 22,
        "username": "john"
    },
    {
        "name": "Buy bunch of onions and 3 bread",
        "description": "This is all we can eat these days in Turkey ;)",
        "completed": false,
        "todoListName": "Ahmet's Shopping TODO List",
        "todoListId": 24,
        "username": "ahmet"
    },
    {
        "name": "Buy Yoga Equipments",
        "description": "Buy Yoga equipments for the class at 4pm",
        "completed": false,
        "todoListName": "Ahmet's Yoga Practice Todo List",
        "todoListId": 23,
        "username": "ahmet"
    }
]

SQL Template

sqltemplate

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  • If you have suggestions for adding or removing projects, feel free to open an issue to discuss it, or directly create a pull request after you edit the README.md file with necessary changes.
  • Please make sure you check your spelling and grammar.
  • Create individual PR for each suggestion.
  • Please also read through the Code Of Conduct before posting your first idea as well.

Creating A Pull Request

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements