Skip to content

ssaha777/user_campaigns_app

Repository files navigation

README

Introduction

This is a Ruby on Rails application that manages users and their associated campaigns. The application provides both a web UI for basic user management and an API for advanced operations, including filtering users by campaign names. The application is hosted on an EC2 instance at the following URL:

http://3.81.174.146/

Table of Contents

  1. Prerequisites
  2. Setup
  3. API Documentation
  4. UI Paths
  5. Usage

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Ruby (version 2.7.6)
  • Rails (version 7.0.8.4)
  • Bundler (if not already installed, you can install it using gem install bundler)
  • postgresql

Setup

  1. Clone the repository:

    git clone [email protected]:ssaha777/user_campaigns_app.git
    cd user_campaigns
  2. Install dependencies:

    bundle install
  3. Setup environment variables:

    • Create a file .env
    • Copy content of .env.sample
    • Put values accordingly in .env file
  4. Setup the database:

    rails db:create
    rails db:migrate
  5. Start the Rails server:

    rails server

API Documentation

List Users

Endpoint:

GET /api/v1/users

Response:

  • 200 OK: A list of all users.

Example Request:

curl -X GET "http://3.81.174.146/api/v1/users"

Example Response:

[
  {
    "id": 1,
    "name": "John Doe",
    "email": "[email protected]",
    "campaigns": ["Campaign1", "Campaign2"]
  },
  {
    "id": 2,
    "name": "Jane Smith",
    "email": "[email protected]",
    "campaigns": ["Campaign1"]
  }
]

Create User

Endpoint:

POST /api/v1/users

Parameters:

  • name (required): The name of the user.
  • email (required): The email of the user.
  • campaigns_list (optional): A JSON array of campaign names associated with the user.

Response:

  • 201 Created: The newly created user.
  • 422 Unprocessable Entity: If there is an issue with the request parameters.

Example Request:

curl -X POST "http://3.81.174.146/api/v1/users" -H "Content-Type: application/json" -d '{
  "user": {
    "name": "John Doe",
    "email": "[email protected]",
    "campaigns_list": ["Campaign1", "Campaign2"]
  }
}'

Example Response:

{
  "id": 1,
  "name": "John Doe",
  "email": "[email protected]",
  "campaigns": ["Campaign1", "Campaign2"]
}

Filter Users by Campaign Names

Endpoint:

GET /api/v1/users/filter

Parameters:

  • campaign_names (optional): A comma-separated list of campaign names to filter users by.

Response:

  • 200 OK: A list of users filtered by the provided campaign names.

Example Request:

curl -X GET "http://3.81.174.146/api/v1/users/filter?campaign_names=Campaign1,Campaign2"

Example Response:

[
  {
    "id": 1,
    "name": "John Doe",
    "email": "[email protected]",
    "campaigns": ["Campaign1", "Campaign2"]
  },
  {
    "id": 2,
    "name": "Jane Smith",
    "email": "[email protected]",
    "campaigns": ["Campaign1"]
  }
]

UI Paths

  • /: Root path, displays the list of users.
  • /users/new: Displays a form to create a new user.

Usage

Accessing the Web UI

Open your web browser and navigate to http://3.81.174.146/. You will see the list of users and can create new users via the provided form.

Using the API

You can interact with the API using tools like curl or Postman. For example, to filter users by campaign names, you can use the following curl command:

curl -X GET "http://3.81.174.146/api/v1/users/filter?campaign_names=Campaign1,Campaign2"

This will return a list of users associated with the specified campaigns.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published