Skip to content

Ankk98/act_planner_backend

Repository files navigation

Act Planner Backend

A RESTful API server for the Act Planner application built with Go, Gin, and PostgreSQL.

Features

  • User authentication with JWT
  • Event management
  • Act scheduling and management
  • Contact management
  • Asset management
  • RESTful API following the OpenAPI specification

Prerequisites

  • Go 1.21 or higher
  • PostgreSQL 14 or higher
  • Docker (optional, for containerized deployment)

Setup

Go Setup

  1. Install Go:

    • For Ubuntu/Debian: sudo apt-get install golang
    • For macOS with Homebrew: brew install go
    • For Windows: Download from golang.org
    • Alternatively, use gvm to manage Go versions
  2. Verify installation:

    go version

Database Setup

Option 1: Local PostgreSQL

  1. Install PostgreSQL:

    • For Ubuntu/Debian: sudo apt-get install postgresql postgresql-contrib
    • For macOS with Homebrew: brew install postgresql
    • For Windows: Download from postgresql.org
  2. Start PostgreSQL service:

    • Ubuntu/Debian: sudo service postgresql start
    • macOS: brew services start postgresql
    • Windows: PostgreSQL is installed as a service and starts automatically
  3. Create a database:

    sudo -u postgres createdb act_planner
  4. Create a user (optional):

    sudo -u postgres psql -c "CREATE USER actplanner WITH PASSWORD 'your_password';"
    sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE act_planner TO actplanner;"

Option 2: Docker PostgreSQL

  1. Install Docker:

  2. Run PostgreSQL container:

    docker run --name act-planner-postgres \
      -e POSTGRES_PASSWORD=postgres \
      -e POSTGRES_DB=act_planner \
      -p 5432:5432 \
      -d postgres:14

Application Setup

  1. Clone the repository:

    git clone https://github.com/ankk98/act-planner-backend.git
    cd act-planner-backend
  2. Install dependencies:

    go mod download
    go mod tidy
  3. Configure environment variables:

    cp .env.example .env

    Edit .env with your database configuration:

    DB_HOST=localhost
    DB_PORT=5432
    DB_USER=postgres  # or your custom user
    DB_PASSWORD=postgres  # your password
    DB_NAME=act_planner
    DB_SSL_MODE=disable
    
  4. Run database migrations:

    go run cmd/migrate/main.go
  5. Start the server:

    go run cmd/server/main.go

The server will start on http://localhost:8080 by default.

Testing

Running API Tests

  1. Make sure the database is set up and the server is running.

  2. Run all tests:

    go test ./tests/...
  3. Run specific test:

    go test ./tests/api/auth_test.go
  4. Run tests with verbose output:

    go test -v ./tests/...

Manual API Testing

You can use curl to test the API endpoints:

  1. Register a new user:

    curl -X POST -H "Content-Type: application/json" \
      -d '{"name":"Test User","email":"[email protected]","password":"password123"}' \
      http://localhost:8080/api/v1/auth/register
  2. Login:

    curl -X POST -H "Content-Type: application/json" \
      -d '{"email":"[email protected]","password":"password123"}' \
      http://localhost:8080/api/v1/auth/login
  3. Get user profile (with token):

    TOKEN="your_jwt_token"
    curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/v1/users/me

API Documentation

The API follows the specifications defined in backend_api_specifications.md.

Project Structure

.
├── cmd/                  # Application entry points
│   ├── migrate/          # Database migration tool
│   └── server/           # API server
├── config/               # Configuration
├── internal/             # Private application code
│   ├── api/              # API-related code
│   │   ├── handlers/     # Request handlers
│   │   ├── middleware/   # HTTP middleware
│   │   └── routes/       # Route definitions
│   ├── models/           # Data models
│   ├── repository/       # Data access layer
│   └── services/         # Business logic
├── pkg/                  # Public libraries
│   ├── auth/             # Authentication utilities
│   ├── database/         # Database utilities
│   └── utils/            # General utilities
├── tests/                # Test files
│   ├── api/              # API tests
│   └── integration/      # Integration tests
└── storage/              # File storage (gitignored)

License

MIT

About

Backend Server for Act Planner

Resources

Stars

Watchers

Forks