-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35278d5
commit 6fc18f1
Showing
1 changed file
with
228 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,229 @@ | ||
I have created /secretpage route which needs authentication to send some data. | ||
If you are not logged in than this page will send an login request. | ||
# IITK Coin | ||
|
||
The token will expire automatically in 15mins and user has to login again after this | ||
And token will expire only after this time (i will add redis to resolve this two problems) | ||
This repository contains my implementation of backend of IITK Coin pclub snt summer project. | ||
|
||
## Index | ||
- Directory Structure | ||
- Database | ||
- Endpoint Details | ||
|
||
## Directory Structure | ||
|
||
├── Dockerfile | ||
├── README.md | ||
├── controllers | ||
│ ├── auth.go | ||
│ ├── coins.go | ||
│ ├── db.go | ||
│ ├── item.go | ||
│ ├── middleware.go | ||
│ ├── otp.go | ||
│ ├── redeem.go | ||
│ ├── router.go | ||
│ ├── transaction.go | ||
│ ├── user.go | ||
│ ├── utils.go | ||
│ └── validation.go | ||
├── docker-compose.yml | ||
├── go.mod | ||
├── go.sum | ||
├── main.go | ||
├── models | ||
│ ├── hash.go | ||
│ ├── item.go | ||
│ ├── params.go | ||
│ ├── request.go | ||
│ ├── token.go | ||
│ └── user.go | ||
├── sqldb | ||
│ └── db.go | ||
└── utils | ||
├── mail.go | ||
└── otp.go | ||
|
||
4 directories, 27 files | ||
## Database: Sqlite | ||
My database implementation containe five tables | ||
|
||
- ### users | ||
|
||
CREATE TABLE users ( | ||
rollNo INTEGER PRIMARY KEY, | ||
name TEXT NOT NULL, | ||
password TEXT NOT NULL, | ||
coins TEXT NOT NULL, | ||
isAdmin INTEGER NOT NULL, | ||
isFreezed INTEGER NOT NULL | ||
); | ||
|
||
- ### transactions | ||
|
||
CREATE TABLE transactions ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
sender INTEGER REFERENCES users(rollNo), | ||
reciever INTEGET NOT NULL REFERENCES users(rollNo), | ||
amount INTEGER NOT NULL, | ||
type TEXT NOT NULL, | ||
madeAt INTEGER NOT NULL | ||
); | ||
|
||
- ### redeem_requests | ||
|
||
CREATE TABLE redeem_requests ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
user INTEGER NOT NULL REFERENCES users(rollNo), | ||
itemCode INTEGER NOT NULL REFERENCES items(code), | ||
status TEXT NOT NULL, | ||
madeAt TEXT NOT NULL | ||
); | ||
|
||
- ### items | ||
|
||
CREATE TABLE items ( | ||
code INTEGER PRIMARY KEY AUTOINCREMENT, | ||
amount INTEGER NOT NULL, | ||
name TEXT NOT NULL, | ||
isAvailable INTEGER NOT NULL | ||
); | ||
|
||
- ### otps | ||
|
||
CREATE TABLE otps ( | ||
otp INTEGER NOT NULL, | ||
user INTEGER NOT NULL REFERENCES users(rollNo) PRIMARY KEY, | ||
madeAt TEXT NOT NULL | ||
); | ||
## Details of Endpoints | ||
|
||
### Signup | ||
|
||
url: /user/signup | ||
method: POST | ||
|
||
Request: Body { | ||
"rollNo": "", | ||
"name": "", | ||
"password": "", | ||
"isAdmin": "", | ||
"isFreezed": "" | ||
} | ||
|
||
### Login | ||
|
||
url: /user/login | ||
method: POST | ||
|
||
Request: Body { | ||
"rollNo": "", | ||
"password": "" | ||
} | ||
|
||
### Transfer Coins | ||
|
||
url: /coins/send | ||
method: POST | ||
|
||
Request: Body { | ||
"rollNo": "", | ||
"coins": "" | ||
} | ||
|
||
-> rollNo here refers to reciever's roll no. | ||
|
||
### Reward Coins | ||
|
||
url: /coins/reward | ||
method: POST | ||
|
||
Request: Body { | ||
"rollNo": "", | ||
"coins": "" | ||
} | ||
|
||
-> rollNo here refers to reciever's roll no. | ||
Note:- This is an admin only route. | ||
|
||
### Get coins | ||
|
||
url: /coins/balance | ||
method: GET | ||
|
||
### Item List | ||
|
||
url: /items | ||
method: GET | ||
|
||
### Make Redeem Request | ||
|
||
url: /coins/redeem | ||
method: POST | ||
|
||
Request: Body { | ||
"itemCode: "" | ||
} | ||
|
||
### Get Redeem Requests | ||
|
||
url: /redeemRequests | ||
method: GET | ||
|
||
Note:- This is an admin only route. | ||
|
||
### Update Redeem Request Status | ||
|
||
url: /redeemRequests | ||
method: POST | ||
|
||
Request: Body { | ||
"id": "", | ||
"status": "" | ||
} | ||
|
||
Note:- This is an admin only route. | ||
|
||
### Get Otp | ||
|
||
url: /otp | ||
method: GET | ||
|
||
### Check Otp | ||
|
||
url: /otp | ||
method: POST | ||
|
||
Request: Body { | ||
"otp": "", | ||
} | ||
|
||
### Add Item | ||
|
||
url: /items | ||
method: POST | ||
|
||
Request: Body { | ||
"amount": "", | ||
"name": "", | ||
"isAvailable": "" | ||
} | ||
|
||
Note:- This is an admin only route. | ||
|
||
### Update Item | ||
|
||
url: /items/:itemcode | ||
method: PUT | ||
|
||
Request: Body { | ||
"amount": "", //optional | ||
"name": "", //optional | ||
"isAvailable": "" //optional | ||
} | ||
|
||
Note:- This is an admin only route. | ||
|
||
### Delete Item | ||
|
||
url: /items/:itemcode | ||
method: DELETE | ||
|
||
Note:- This is an admin only route. |