Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/glebegor/ton-work-back

This is example of UpWork where you can use Ton coin.
https://github.com/glebegor/ton-work-back

api backend docker gin golang postgresql

Last synced: 3 days ago
JSON representation

This is example of UpWork where you can use Ton coin.

Awesome Lists containing this project

README

        

# Backend of TonWork service.
TonWork that's platform/marketplace where you can find work, team, and interesting project that rooted with IT(and not also).
If you need team, you will can create a find order on, for example, data sciences developer or another.
And you can pay for work by crypto currency(in our plan start from TON coint and move to another SOL, ETH, BTC...).

Start project by cmd


1-Start database:


You need to download a docker image(postgres).

And after create database:

docker run --name=name-of-database -e POSTGRES_PASSWORD="password" -p 5436:5432 -d --rm postgres

2-Create migrations:


migrate -path ./schema -database "postgres://postgres:password@localhost:5436/postgres?sslmode=disable" up

3-Create .env file:


DB_PASSWORD='password'

Secret_Key='SECRET-KEY'

4-Run project:

Run project by Makefile:


installdb:


This command will install docker image to your computer.

docker pull postgres

build:


This command will run docker database(PostgresSQL).

docker run --name=name-of-database -e POSTGRES_PASSWORD='password' -p 5436:5432 -d --rm postgres

migrate:


This command will create migrations for your database.

migrate -path ./schema -database "postgres://postgres:password@localhost:5436/postgres?sslmode=disable" up

run:


This command will run project.

go run cmd/main.go

Loading by docker compose


docker compose build

docker compose up

Work with API

1. "/auth":
- "/register" POST
- "/login" POST
- "/profile/:username" GET
- "/updateProfile" PUT
2. "/api/v2/":
- "/work":
- "/" POST
- "/" GET
- "/:id" GET
- "/:id" PATCH
- "/:id" DELETE
- "/posts":
- "/" POST
- "/" GET
- "/:id" GET
- "/:id" PATCH
- "/:id" DELETE
- "/subscribe":
- "/buy" POST
- "/cancel" POST
- "/timetoend" GET
- "/chat":
- "/CreateRoom" POST
- "/GetRooms" GET
- "/JoinRoom/:roomId" WebSocket
- "/GetClients/:roomId" Get

Or you can see it in this format(Handler is realizated if has "+" on the right side):



"/auth":

"/auth/updateProfile" PUT

"/auth/register" POST+

"/auth/login" POST+

"/auth/profile" GET+



"/api/v2/":



"/api/v2/work":

"/api/v2/work/" POST+

"/api/v2/work/" GET+

"/api/v2/work/:id" GET+

"/api/v2/work/:id" PATCH+

"/api/v2/work/:id" DELETE+



"/api/v2/posts":

"/api/v2/posts/" POST+

"/api/v2/posts/" GET+

"/api/v2/posts/:id" GET+

"/api/v2/posts/:id" PATCH+

"/api/v2/posts/:id" DELETE+



"/api/v2/subscribe":

"/api/v2/subscribe/buy" POST+

"/api/v2/subscribe/cancel" POST+

"/api/v2/subscribe/timetoend" GET+



"/api/v2/chat:

"/api/v2/chat/CreateRoom" POST+

"/api/v2/chat/GetRooms" GET+

"/api/v2/chat/JoinRoom/:roomId" WebSocket+

"/api/v2/chat/GetClients/:roomId" GET+

JWT token and his structure




JWT token looks like this:
qweioucu34ioslk1j23lkjds.dkowjrlekwjriodfslvvldkwsjqr.dsfouqweopriuoiu3oi3o2uadflsk
And has three parts: header.payload.signature

Claims of our JWT token: userId, userUsername, userName, userSurname.

Please, save in cookies or session storage.

Header for token: Authorization.

Requests and responses on every link


AUTH




"/auth/register", method:POST.

Type | JSON
--- | ---
Request | { "username": "User Name", "password_hash": "123456789", "email": "[email protected]" }
Response | { "Status": "OK" }
Error Response | { "message": "Some text" }

"/auth/login", method:POST.

Type | JSON
--- | ---
Request | { "username": "User Name", "password_hash": "123456789" }
Response | { "token": "wqewqeqwr123o1kepo2k-c439!(#_$I(#$.@)#@!O)$K@J)!$.!@(#JWJDWADISIADOUI" }
Error Response | { "message": "Some text" }

"/auth/profile/${Username}", method:GET.

Type | JSON | Headers
--- | --- | ---
Request | write param to url, example: "/auth/profile/Glebegor" | Headers
Response | { "username": "User name", "email": "[email protected]", "telefon": "+3242 3242 432", "position": "Position", "description": "Description text", "subscribe": "Subscribe", "companies": "Companies", "name": "name", "surname": "Surname", "id": "Id" } | Headers
Error Response | { "message": "Some text" } | Headers

POSTS




"/api/v2/posts/", method:GET.

Type | JSON | Headers
--- | --- | ---
Request | --- | ---
Response | {data: [{ "title": "Title", "description": "Title", "text": "aqweqweqwesd", "tags": "['asdasd','asdasd','asdasd']", "rating": 1, "id": 2 }... ]}| ---
Error Response | { "message": "Some text" } | ---

"/api/v2/posts/", method:POST.

Type | JSON | Headers
--- | --- | ---
Request | { "title": "Title", "description": "Title", "text": "aqweqweqwesd", "tags": "['asdasd','asdasd','asdasd']", "rating": 1} | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "Status": "OK" }| ---
Error Response | { "message": "Some text" } | ---

"/api/v2/posts/:id", method:GET.

Type | JSON | Headers
--- | --- | ---
Request | --- | ---
Response | { "title": "Title", "description": "Title", "text": "aqweqweqwesd", "tags": "['asdasd','asdasd','asdasd']", "rating": 1}| ---
Error Response | { "message": "Some text" } | ---

"/api/v2/posts/:id", method:PUT.

Type | JSON | Headers
--- | --- | ---
Request | { "title": "Title", "description": "Title", "text": "aqweqweqwesd", "tags": "['asdasd','asdasd','asdasd']", "rating": 1} | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "Status": "OK" } | ---
Error Response | { "message": "Some text" } | ---

"/api/v2/posts/:id", method:DELETE.

Type | JSON | Headers
--- | --- | ---
Request | --- | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "Status": "OK" } | ---
Error Response | { "message": "Some text" } | ---

WORKS




"/api/v2/posts/", method:GET.

Type | JSON | Headers
--- | --- | ---
Request | --- | ---
Response | { "data": [ { "title": "title", "description": "description", "text": "text", "tags": "['asdasd', 'asdad']", "technologies": "['qweqw', 'qweqe']", "company": "qwec rewqrq", "price": 2, "experienceLevel": "qweq ", "type_of_job": "qwe ", "invites": 0, "rating": 2, "id": 1 } ] }| ---
Error Response | { "message": "Some text" } | ---

"/api/v2/work/", method:POST.

Type | JSON | Headers
--- | --- | ---
Request | { "title": "title", "description": "description", "text": "text", "tags": "['asdasd', 'asdad']", "technologies": "['qweqw', 'qweqe']", "company": "qwec rewqrq", "price": 2, "experienceLevel": "qweq ", "type_of_job": "qwe ", "invites": 0, "rating": 2 } | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "Status": "OK" }| ---
Error Response | { "message": "Some text" } | ---

"/api/v2/work/:id", method:GET.

Type | JSON | Headers
--- | --- | ---
Request | --- | ---
Response | { "title": "title", "description": "description", "text": "text", "tags": "['asdasd', 'asdad']", "technologies": "['qweqw', 'qweqe']", "company": "qwec rewqrq", "price": 2, "experienceLevel": "qweq ", "type_of_job": "qwe ", "invites": 0, "rating": 2 }| ---
Error Response | { "message": "Some text" } | ---

"/api/v2/work/:id", method:PUT.

Type | JSON | Headers
--- | --- | ---
Request | { "title": "title", "description": "description", "text": "text", "tags": "['asdasd', 'asdad']", "technologies": "['qweqw', 'qweqe']", "company": "qwec rewqrq", "price": 2, "experienceLevel": "qweq ", "type_of_job": "qwe "} | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "Status": "OK" } | ---
Error Response | { "message": "Some text" } | ---

"/api/v2/work/:id", method:DELETE.

Type | JSON | Headers
--- | --- | ---
Request | --- | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "Status": "OK" } | ---
Error Response | { "message": "Some text" } | ---

SUBSCRIBES




"/api/v2/subscribe/buy", method:POST.

Type | JSON | Headers
--- | --- | ---
Request | --- | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "Status": "OK" } | ---
Error Response | { "message": "Some text" } | ---
{ "name":"qweqwe", "id":"qweqew" }

"/api/v2/subscribe/cancel", method:POST.

Type | JSON | Headers
--- | --- | ---
Request | --- | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "Status": "OK" } | ---
Error Response | { "message": "Some text" } | ---

"/api/v2/subscribe/timetoend", method:GET.

Type | JSON | Headers
--- | --- | ---
Request | --- | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "TimeToEnd": -1, "Username": "username"} | ---
Error Response | { "message": "Some text" } | ---

CHAT




"/api/v2/chat/CreateRoom", method:POST

Type | JSON | Headers
--- | --- | ---
Request | { "name":"qweqwe", "id":"qweqew" } | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { "name":"qweqwe", "id":"qweqew" } | ---
Error Response | { "message": "Some text" } | ---

"/api/v2/chat/JoinRoom/:roomId", method:WEBSOCKET

Type | JSON | Headers
--- | --- | ---
Request | --- | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | { --- } | ---
Error Response | { "message": "Some text" } | ---

"/api/v2/chat/GetRooms", method:GET

Type | JSON | Headers
--- | --- | ---
Request | --- | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | [ { "id": "room1", "name": "room1" }...] | ---
Error Response | { "message": "Some text" } | ---

"/api/v2/chat/GetClients/:roomId", method:GET

Type | JSON | Headers
--- | --- | ---
Request | --- | Authorization: "Bearer tokenqw.qweqweqe.qwesaid0@OI#U!sf09a"
Response | [ { "id": "3", "username":"username" }...] | ---
Error Response | { "message": "Some text" } | ---