Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teekaytech/taofeek-olalere-technical-assessment
Technical Assessment for tix.africa
https://github.com/teekaytech/taofeek-olalere-technical-assessment
api postgres rails7 rspec
Last synced: about 2 months ago
JSON representation
Technical Assessment for tix.africa
- Host: GitHub
- URL: https://github.com/teekaytech/taofeek-olalere-technical-assessment
- Owner: teekaytech
- Created: 2022-10-04T07:06:23.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-05T09:39:37.000Z (over 2 years ago)
- Last Synced: 2024-12-06T03:52:35.318Z (2 months ago)
- Topics: api, postgres, rails7, rspec
- Language: Ruby
- Homepage:
- Size: 77.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Event Ticketing Platform (Technical Assessment)
> This is a basic API for an events application. It allows users to create an event and go live (selling paid or free tickets) in under five minutes.
## Built With
- Ruby v2.7.1
- Ruby on Rails 7.0.4
- PostgreSQL
- Rspec (Testing)
- Devise, Devise-JWT (Authentication)
- Heroku## Getting Started
To get a local copy up and running follow these simple example steps.
- On the project GitHub page, navigate to the main page of the repository [this page](https://github.com/teekaytech/Taofeek-Olalere-Technical-Assessment.git).
- Under the repository name, locate and click on a green button named `Code`.
- Copy the project URL as displayed.
- If you're running Windows Operating System, open your command prompt. On Linux, Open your terminal.
- Change the current working directory to the location where you want the cloned directory to be made. Leave as it is if the current location is where you want the project to be.
- Type `git clone`, and then paste the URL you copied in Step 3.
`$ git clone https://github.com/teekaytech/Taofeek-Olalere-Technical-Assessment.git` Press Enter key
- Press Enter. Your local copy will be created.## Prerequisites
- [Git](https://gist.github.com/derhuerst/1b15ff4652a867391f03).
- Web browser (Chrome/Firefox)
- Ruby v2.7.1
- Ruby on Rails v7
- Postgresql v >= 14## Project Setup
_After cloning, the following steps setup the project_
- `cd Taofeek-Olalere-Technical-Assessment` to change the current working directory.
- `bundle install` to install all necessary dependencies.
- `rails db:create` && `rails db:migrate` to create database and tables.
- `rails db:seed` to populate database with Dummie data.
- `touch .env` to create an env file. This requires just one(1) key namely: `DEVISE_JWT_SECRET_KEY` whose value can be generated with: `rake secret`.
```
DEVISE_JWT_SECRET_KEY=<>
```
- `rails s` to start the application. You're all set.
Feel free to use POSTMAN or any other similar infrastructure to test the different endpoints.To run test suites included, run:
- `bundle exec rake`
## API Documentation
> The base URL for all endpoints is `https://serene-badlands-07566.herokuapp.com/`. The validation is implemented using tokens generated by Devise upon registration or login. This token is then sent with the headers of the requests that requires validation, so that it can be decoded and the app can determine if the token is valid or not. If valid, the user can successfully access end-points that requires authentication.
**Summary of Available API Endpoints**
| Endpoint | Feature | Authentication |
| ---------------------------- | -------------------------------------- | -------------- |
| POST /users | Registers a new user | False |
| POST /sign_in | Logs in a user | False |
| DELETE /sign_out | Logs out a user | False |
| POST /api/v1/events | Creates a new event | True |
| GET /api/v1/users/:id/events | Fetches all available event for a user | True |
| PATCH /api/v1/events/:id | Update an event | True |
| DELETE /api/v1/events/:id | Delete an event | True |
| POST /api/v1/tickets | Creates ticket for an event | True |
| GET /api/v1/events | List all events | True |**Sampling a request that DOES NOT require authentication**
_Sign Up: endpoint creates a new user and ensure that the user can login._
Endpoint: `https://serene-badlands-07566.herokuapp.com/users`
Request (From POSTMAN):
```js
curl --location --request POST 'https://serene-badlands-07566.herokuapp.com/users' \
--header 'Content-Type: application/json' \
--data-raw '{
"user": {
"email": "[email protected]",
"password": "password"
}
}'
```Response:
```json
{
"message": "Signed up successfully."
}
```_Login: endpoint creates a new bearer token and ensure that the user can access all features._
Endpoint: `https://serene-badlands-07566.herokuapp.com/users/sign_in`
Request (From POSTMAN):
```js
curl --location --request POST 'https://serene-badlands-07566.herokuapp.com/users/sign_in' \
--header 'Content-Type: application/json' \
--data-raw '{
"user" : {
"email" : "[email protected]",
"password" : "password"
}
}'
```Response:
```json
{
"message": "Logged in.",
"user": {
"id": "48b107d2-5e16-47af-90f3-754e2e0fb4fc",
"email": "[email protected]",
"created_at": "2022-10-05T09:01:51.251Z",
"updated_at": "2022-10-05T09:01:51.251Z"
}
}
```Note: The bearer token is included as part of the response headers, named **Authorization**. This token is to be used for subsequent requests that requires authentication, and it expires after 24hrs (this can be changed).
**Sampling a request that requires authentication**
_Create an Event: endpoint creates an event on the platform._
Endpoint: `https://serene-badlands-07566.herokuapp.com/api/v1/events`
Request (from POSTMAN):
```js
curl --location --request POST 'https://serene-badlands-07566.herokuapp.com/api/v1/events' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0OGIxMDdkMi01ZTE2LTQ3YWYtOTBmMy03NTRlMmUwZmI0ZmMiLCJzY3AiOiJ1c2VyIiwiYXVkIjpudWxsLCJpYXQiOjE2NjQ5NjA2NzIsImV4cCI6MTY2NTA0NzA3MiwianRpIjoiZWVkNzc0OTYtNmY4MC00Mzc5LWExZWEtMGZkZDZjMjBhMDFiIn0.bWgw_4m77OzerulP74jqgCJ4ZpgyU8CcYqBtlHtE9PU' \
--header 'Content-Type: application/json' \
--data-raw '{
"event": {
"title" : "Initial Event",
"description": "Description here",
"start_date": "2022-10-06T14:33:26.435Z",
"end_date": "2022-10-08T14:33:26.435Z"
}
}'
```Response:
```json
{
"id": "8268a65c-fd39-4996-9f00-bb43cb81fb59",
"title": "Initial Event",
"category": "free",
"status": "active",
"start_date": "2022-10-06T14:33:26.435Z",
"end_date": "2022-10-08T14:33:26.435Z",
"created_at": "2022-10-05T09:12:20.093Z",
"user_id": "48b107d2-5e16-47af-90f3-754e2e0fb4fc",
"url": "https://serene-badlands-07566.herokuapp.com/api/v1/events/8268a65c-fd39-4996-9f00-bb43cb81fb59"
}
```To query events in different categories (i.e. `free` or `paid`), it is okay to pass the `category` query parameter on the endpoint. For instance:
To fetch all paid events:
`https://serene-badlands-07566.herokuapp.com/api/v1/events?category=paid`To fetch all free events that are active:
`https://serene-badlands-07566.herokuapp.com/api/v1/events?status=active&category=free`## Deployment
This app was deployed to Heroku and is accessible at: `https://serene-badlands-07566.herokuapp.com/`
## Author
👤 **Taofeek Olalere**
- Github: [@teekaytech](https://github.com/teekaytech)
- Twitter: [@ola_lere](https://twitter.com/ola_lere)
- Linkedin: [olaleretaofeek](https://linkedin.com/in/olaleretaofeek)
- Portfolio: [Olalere Taofeek](https://teekaytech.github.io/olaleretaofeek/)## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check the [issues page](https://github.com/teekaytech/Taofeek-Olalere-Technical-Assessment/issues).
## Show your support
Give a ⭐️ if you like this project!
## Acknowledgments
- [Heroku Rails 7 Doc](https://devcenter.heroku.com/articles/getting-started-with-rails7)
- [Karim Marabet's article on Devise-JWT](https://enlear.academy/how-to-create-a-rails-6-api-with-devise-jwt-46fa35085e85)