https://github.com/abhishekshree/iitk-coin
Summer Project 2021, Programming Club
https://github.com/abhishekshree/iitk-coin
backend golang jwt sqlite3
Last synced: about 1 year ago
JSON representation
Summer Project 2021, Programming Club
- Host: GitHub
- URL: https://github.com/abhishekshree/iitk-coin
- Owner: abhishekshree
- License: mit
- Created: 2021-05-28T17:14:27.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-26T08:09:00.000Z (almost 5 years ago)
- Last Synced: 2025-03-14T16:43:45.573Z (over 1 year ago)
- Topics: backend, golang, jwt, sqlite3
- Language: Go
- Homepage: https://iitk-coin-docs.netlify.app/
- Size: 7.82 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IITK Coin
[](https://hub.docker.com/r/abhishekshree/iitk-coin)
[](https://iitk-coin-docs.netlify.app/)


This repository contains the backend for IITK Coin, which is a centralized pseudo-coin system in golang (fiber) for use in IITK Campus.
## Index
- [Directory Structure](#directory-structure)
- [Database](#database-sqlite)
- [Details of the endpoints](#details-of-the-endpoints)
---
## Directory Structure
```
├── config
│ └── config.go
├── db
│ ├── admin.go
│ ├── db.go
│ ├── records.go
│ ├── redeem.go
│ └── transactions.go
├── Dockerfile
├── go.mod
├── go.sum
├── iitk-coin
├── main.go
├── middleware
│ ├── hash.go
│ └── jwt.go
├── README.md
├── routes
│ ├── redeem.go
│ ├── routes.go
│ └── transactions.go
└── Users.db
4 directories, 19 files
```
---
## Database: `SQLite`
The database currently has three tables, they are:
- User
```sql
CREATE TABLE User (
rollno TEXT,
name TEXT,
password TEXT,
coins REAL,
Admin BOOLEAN DEFAULT 0,
PRIMARY KEY(rollno)
);
```
- Transactions
```sql
CREATE TABLE Transactions (
id INTEGER PRIMARY KEY,
from_roll TEXT,
to_roll TEXT,
type TEXT,
timestamp TEXT,
amount_before_tax REAL,
tax REAL
);
```
- RedeemRequests
```sql
CREATE TABLE RedeemRequests (
id INTEGER PRIMARY KEY,
rollno TEXT,
item TEXT,
timestamp TEXT,
status INTEGER DEFAULT 0
);
-- for status: 0 -> Pending, 1 -> Redeemed, 2 -> Declined
```
---
## Details of the endpoints:
Can also be viewed [here.](https://iitk-coin-docs.netlify.app/)
### Signup
```
url : /signup
method : POST
Request Body: {
"Roll" : "",
"Name" : "",
"Password" : ""
}
Response : {
"success": true/false
}
```
### Login
```
url : /login
method : POST
Request Body: {
"Roll" : "",
"Password" : ""
}
Response : {
"token": JWT Token
"status": true/false
}
NOTE: Token is returned only after a successful login. Also it expires in 3 days.
```
### Secretpage
```
url : /secretpage
method : GET
Response : "This is a very secret string."
NOTE: Can access only after a successful JWT verification and if the user Exists.
```
### Get Coins
```
url : /getCoins
method : GET
Request Body: {
"rollno" : "",
}
Response : {
"rollno": ,
"coins": ,
}
```
### Award Coins
```
url : /awardCoins
method : POST (JWT Required)
Request Body: {
"rollno" : "",
"amount":
}
Response : {
"message": "Coins Awarded."
}
Note: Check from JWT if the amount coming from user X is actually after when user X logs in and is an admin.
```
### Transfer Coins
```
url : /transferCoins
method : POST (JWT Required)
Request Body: {
"from" : "",
"to": "190028",
"amount":
}
Response : {
"message": "Coins Transferred.",
"amount": ,
}
Note: Check from JWT if the amount coming from user X is actually after when user X logs in.
```
### Sidenote:
Also defined some functions to give or take admin privileges in the db package.
```go
func MakeAdmin(rollno string) bool
func RemoveAdmin(rollno string) bool
func IsAdmin(rollno string) bool
```
### Get a list of Redeemable items and price
```
url : /getRedeemList
method : GET
Request Body:
Response :
```
### Create a Redeem Request
```
url : /redeemRequest
method : POST
Request Body: {
"item": "B"
}
Response : {
"message":
}
Note: The Roll number is obtained from active JWT
```
### Accept a Redeem Request
```
url : /acceptRedeemRequest
method : POST
Request Body: {
"id":6
}
Response : {
"message":
}
Note: This route is ADMIN ONLY.
```
### Reject a Redeem Request
```
url : /rejectRedeemRequest
method : POST
Request Body: {
"id":6
}
Response : {
"message":
}
Note: This route is ADMIN ONLY. Also, a request which was accepted earlier can be rejected too, in that case the coins are lost (like in other coin based systems).
```
### Reject all the pending requests from a user (in case someone spams a lot of requests)
```
url : /rejectPendingRequests
method : POST
Request Body: {
"roll":"190028"
}
Response : {
"message":
}
Note: This route is ADMIN ONLY.
```