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/
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
-
Clone the repository:
git clone [email protected]:ssaha777/user_campaigns_app.git cd user_campaigns
-
Install dependencies:
bundle install
-
Setup environment variables:
- Create a file .env
- Copy content of .env.sample
- Put values accordingly in .env file
-
Setup the database:
rails db:create rails db:migrate
-
Start the Rails server:
rails server
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"]
}
]
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"]
}
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"]
}
]
/
: Root path, displays the list of users./users/new
: Displays a form to create a new user.
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.
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.