Skip to content

danielphilipjohnson/rust-ticket-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Ticket Manager API

A Rust-based issue and project tracking API built with Axum and Diesel ORM.

Rust Axum PostgreSQL Diesel

A lightweight project and issue tracking API built in Rust, using Axum for the web framework and Diesel ORM for PostgreSQL database integration. This service provides CRUD operations for managing projects and issues, supports real-time updates, detailed issue tracking, and secure data storage, making it ideal for team collaboration and agile development workflows.


🌟 Features

βœ” Create, update, and delete projects
βœ” Manage issues within projects
βœ” Track project statuses
βœ” RESTful API design with structured JSON responses
βœ” High-performance Rust backend using Axum
βœ” PostgreSQL database with Diesel ORM


πŸ›  Tech Stack

Technology Purpose
Rust πŸ¦€ Systems programming language
Axum ⚑ Web framework
Diesel πŸ›’οΈ ORM for PostgreSQL
Tokio ⏳ Async runtime
Serde πŸ“¦ Serialization/Deserialization

πŸš€ Getting Started

1️⃣ Install Prerequisites

Install Rust using Rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Install Diesel CLI:

cargo install diesel_cli --no-default-features --features postgres

Ensure Docker is installed:
πŸ”— Docker Installation Guide


🐳 Database Setup with Docker

To simplify database setup, use Docker to run PostgreSQL and pgAdmin.

1️⃣ Run PostgreSQL and pgAdmin

docker-compose up -d

This will:

  • Start a PostgreSQL 16 database container.
  • Start pgAdmin 4 for managing the database.
  • Persist data using Docker volumes.

2️⃣ PostgreSQL Connection Details

Key Value
Host localhost
Port 5432
Database mydb
Username admin
Password adminpassword

3️⃣ Access pgAdmin

  1. Open pgAdmin: http://localhost:5050
  2. Login Credentials:
    • Email: admin@admin.com
    • Password: admin
  3. Click "Add New Server", enter:
    • Host: postgres_db
    • Username: admin
    • Password: adminpassword

πŸ”„ Running Diesel Migrations

After setting up the database, apply migrations:

  1. Set up Diesel
diesel setup
  1. Run Migrations
diesel migration run
  1. Reset Database (Caution)
diesel database reset
diesel migration run

πŸ›  Installation

  1. Clone the repository:
git clone https://github.com/danielphilipjohnson/rust-ticket-manager.git
cd ticket-manager
  1. Set up environment variables (.env file):
DATABASE_URL=postgres://admin:adminpassword@localhost/mydb
  1. Build the project:
cargo build
  1. Run the tests:
cargo test
  1. Start the server:
cargo run

The server will start on http://localhost:3000.


πŸ“‘ API Endpoints

1️⃣ Projects

Create a Project (POST /api/projects)

curl -X POST http://localhost:3000/api/projects \
     -H "Content-Type: application/json" \
     -d '{"name": "New Project", "description": "Project description"}'

Get All Projects (GET /api/projects)

curl -X GET http://localhost:3000/api/projects

Update a Project (PUT /api/projects/{project_id})

curl -X PUT http://localhost:3000/api/projects/1 \
     -H "Content-Type: application/json" \
     -d '{"name": "Updated Name", "description": "Updated description"}'

Delete a Project (DELETE /api/projects/{project_id})

curl -X DELETE http://localhost:3000/api/projects/1

2️⃣ Issues

Create an Issue (POST /api/projects/{project_id}/issues)

curl -X POST http://localhost:3000/api/projects/1/issues \
     -H "Content-Type: application/json" \
     -d '{"title": "Bug", "description": "Issue details", "created_by": "dev@example.com", "status": "open"}'

Get All Issues for a Project (GET /api/projects/{project_id}/issues)

curl -X GET http://localhost:3000/api/projects/1/issues

Update an Issue (PUT /api/projects/{project_id}/issues/{issue_id})

curl -X PUT http://localhost:3000/api/projects/1/issues/1 \
     -H "Content-Type: application/json" \
     -d '{"status": "resolved"}'

Delete an Issue (DELETE /api/projects/{project_id}/issues/{issue_id})

curl -X DELETE http://localhost:3000/api/projects/1/issues/1

πŸ” Error Handling

{
  "error": "Project with ID 1 not found"
}

Possible Errors:

  • 404 Not Found: Resource not found.
  • 400 Bad Request: Invalid request.
  • 500 Internal Server Error: Unexpected failure.

πŸ§ͺ Testing

cargo test

Run specific test:

cargo test test_create_project

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

πŸ“– Tutorial & Blog

πŸ“Œ Read the guide on my blog:
πŸ‘‰ Building a Ticket Manager API with Rust and Axum


πŸ”— Contact

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published