Categorygithub.com/w4n2/rest-api
module
0.0.0-20240428131913-fe33a2227fd4
Repository: https://github.com/w4n2/rest-api.git
Documentation: pkg.go.dev

# README

Go Test

Go and MySQL REST API for Project Management

This project provides a RESTful API for managing projects, users, and tasks. It's inspired by Jira and allows you to create, update, and retrieve project-related data.

Setup

  1. Database Configuration:

    • Create a MySQL database (e.g., project_management).
    • Configure the database access credentials in a .env file. Use the .env.example file as a template.
    • Define the following environment variables:
      • DB_USER: MySQL username (e.g., root)
      • DB_PASSWORD: MySQL password (if applicable)
      • DB_HOST: MySQL host (e.g., localhost)
      • DB_PORT: MySQL port (default is 3306)
      • DB_NAME: Database name (e.g., project_management)
  2. Build Package:

    make build
    
  3. Run the Application:

    make run
    

API Endpoints

Projects

  • Create a Project:

    • URL: POST /projects
    • Request Body:
      {
        "name": "My Project",
        "description": "A sample project"
      }
      
    • Response:
      {
        "id": 1,
        "name": "My Project",
        "description": "A sample project",
        "createdAt": "2023-01-01T00:00:00"
      }
      
  • Get All Projects:

    • URL: GET /projects/1
    • Response:
      [
        {
          "id": 1,
          "name": "My Project",
          "description": "A sample project",
          "createdAt": "2023-01-01T00:00:00"
        }
      ]
      

Users

  • Create a User:

    • URL: POST /users
    • Request Body:
      {
        "email": "[email protected]",
        "firstName": "John",
        "lastName": "Example",
        "password": "password"
      }
      
    • Response:
      {
        "id": 1,
        "email": "[email protected]",
        "firstName": "John",
        "lastName": "Example",
        "createdAt": "2023-01-01T00:00:00"
      }
      
  • Get All Users:

    • URL: GET /users
    • Response:
      [
        {
          "id": 1,
          "email": "[email protected]",
          "firstName": "John",
          "lastName": "Example",
          "createdAt": "2023-01-01T00:00:00"
        }
      ]
      

Tasks

  • Create a Task:

    • URL: POST /tasks
    • Request Body:
      {
        "projectId": 1,
        "title": "Implement feature X",
        "assigneeId": 1
      }
      
    • Response:
      {
        "id": 1,
        "projectId": 1,
        "name": "Implement feature X",
        "assigneeId": 1,
        "createdAt": "2023-01-01T00:00:00"
      }
      
  • Get a Task:

    • URL: GET /tasks/1
    • Response:
        {
          "id": 1,
          "projectId": 1,
          "name": "Implement feature X",
          "assigneeId": 1,
          "createdAt": "2023-01-01T00:00:00"
        }
      

Sequence Diagram


sequenceDiagram
  participant Client
  participant API
  participant Authentication
  participant Database

  Client ->> API: POST /user/register
  API ->> Database: Insert User
  Database -->> API: User Created
  Authentication -->> Client: Token Generated

  Client ->> API: GET /user
  API ->> Authentication: Get User
  Authentication ->> Database: Validate User
  Database ->> Authentication:User Validated
  Authentication -->> Client: Token Generated

  Client ->> API: POST /projects
  API ->> Authentication: Authenticate (JWT)
  Authentication -->> API: Authentication Successful
  API ->> Database: Insert Project
  Database -->> Client: Project Created

  Client ->> API: GET /projects
  API ->> Authentication: Authenticate (JWT)
  Authentication -->> API: Authentication Successful
  API ->> Database: Retrieve Projects
  Database -->> Client: List of Projects

  Client ->> API: POST /tasks
  API ->> Authentication: Authenticate (JWT)
  Authentication -->> API: Authentication Successful
  API ->> Database: Insert Task
  Database -->> Client: Task Created

  Client ->> API: GET /tasks
  API ->> Authentication: Authenticate (JWT)
  Authentication -->> API: Authentication Successful
  API ->> Database: Retrieve Tasks
  Database -->> Client: List of Tasks

# Packages

No description provided by the author