Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pkrawat1/rewards
https://github.com/pkrawat1/rewards
Last synced: about 13 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/pkrawat1/rewards
- Owner: pkrawat1
- Created: 2023-12-30T11:09:50.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-01-08T11:29:19.000Z (10 months ago)
- Last Synced: 2024-10-21T22:58:48.025Z (16 days ago)
- Language: Elixir
- Size: 58.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Reward Points Awarding API
This API is designed to facilitate point awarding to customers based on the value of orders in JPY. It allows for the identification of customers using their email and/or phone number and implements functionalities to process orders, manage customer balances, and manipulate points.
## Table of Contents
- [Overview](#overview)
- [Specifications](#specifications)
- [Setup Instructions](#setup-instructions)
- [API Endpoints](#api-endpoints)
- [Example Usage](#example-usage)
- [API Docs](#api-docs)## Overview
The primary goal of this API is to award points to customers based on the value of an order in JPY. Points are awarded at a base percentage of 1% of the order value. It stores all relevant data in a chosen database and provides endpoints to process orders, fetch customer balances, and perform point manipulation operations.
## Specifications
- Back-end Language: Elixir with Phoenix framework.
- Data Storage: All data is stored in a postgresql database.
- API Functionalities:
- Process orders and award a set percentage (1% base) in points.
- Fetch a customer's point balance.
- Add/subtract points from the balance.
- Additional: Modify the percentage of points awarded.## Setup Instructions
To get started with this API on your local machine, follow these steps:
- Clone the Repository
- Configure environment variables using [direnv](https://direnv.net/).
```bash
cp .envrc.example .envrc
```
- Install Dependencies
- Ensure you have Elixir and Phoenix installed.
- Use `asdf install` to install required versions of elixir/erlang.
```bash
mix deps.get
```
- Database Setup
- Modify database configuration in config/dev.exs
- Run migrations to set up the database:
```bash
mix ecto.create
mix ecto.migrate
```
- Start the Server
```bash
mix phx.server
```## API Endpoints
- #### Process Orders
- Endpoint: POST /orders
- Description: Processes orders and awards points to customers based on order value.
- #### Fetch Customer Balance
- Endpoint: GET /customers/:identifier/balance
- Description: Retrieves the current points balance for a specific customer.
- #### Modify Points Balance
- Endpoint: POST /customers/:identifier/balance
- Description: Allows addition or subtraction of points to a customer's balance.
- #### Modify Points Award Percentage (Extra)
- Endpoint: PATCH /settings
- Description: Modifies the percentage of points awarded.
## API Docs
The API docs can be accessed locally on this route : `/api/swagger/index.html`## Example Usage
```bash
## Example API Request for Order Processing```bash
curl -X POST http://localhost:4000/orders/new \
-H "Content-Type: application/json" \
-d '{
"order": {
"id": "104fd7e0-a188-4ffd-9af7-20d7876f70ab",
"paid": 10000,
"currency": "jpy"
},
"customer": {
"email": "[email protected]",
"phone": null
}
}'
```