Handles requests for petitions, users and signatures. Can be used for writing small petitions interfaces
For this petitions branch use audit module: https://github.com/zardan4/petition-audit-rabbitmq
CreateUser(user petitions.User) (int, error)
Request bodyad
{
"name": "mark zuckerberg",
"grade": "3",
"password": "secretpassword123"
}
Response
{
"id": newUserId
}
GenerateTokens(name, password, fingerprint string) (core.JWTPair, error)
Request body
{
"name": "mark zuckerberg",
"password": "secretpassword123",
"fingerprint": "your_unique_device_fingerprint"
}
Response
{
"access_token": usersJWT,
"refresh_token": userRefreshToken
}
RefreshTokens(refreshToken, fingerprint string) (core.JWTPair, error)
Request body
{
"fingerprint": "your_unique_device_fingerprint"
}
Cookie
{
"refresh_token": "refresh_token_cookie"
}
Response
{
"access_token": newUsersJWT,
"refresh_token": newUserRefreshToken
}
Logout(refreshToken string) error
Cookie
{
"refresh_token": "refresh_token_cookie"
}
Response
{
"status": "ok"
}
- Refresh session depends on fingerprint too so make unique refresh session from each user's device and don't use the same fingerprint(generate it here)
- Follow this scheme to better understand how to use auth
GetAllPetitions() ([]petitions.Petition, error)
Response
{
"data": [
{
"id": "id",
"title": "title",
"date": "date",
"timeend": "timeend",
"text": "text",
"answer": "answer"
}
]
}
CreatePetition(title, text string, authorId int) (int, error)
Request body
{
"title": "title_example",
"text": "text_example"
}
Response
{
"id": "id"
}
GetPetition(petitionId int) (petitions.Petition, error)
Response
{
"id": "id",
"title": "title",
"date": "date",
"timeend": "timeend",
"text": "text",
"answer": "answer"
}
UpdatePetition(petition petitions.UpdatePetitionInput, petitionId, userId int) error
Request body. Optional fields but at least one
{
"id": "id",
"title": "title",
"date": "date",
"timeend": "timeend",
"text": "text",
"answer": "answer"
}
Response
{
"status": "ok"
}
DeletePetition(petitionId, userId int) error
Response
{
"status": "ok"
}
CheckSignatorie(petitionId, userId int) (bool, error)
Response
{
"signed": bool
}
GetAllSubs(petitionId int) ([]petitions.Sub, error)
Response
{
"data": [
{
"id": "id",
"date": "date",
"userId": "userId",
"name": "username"
}
]
}
CreateSub(petitionId, userId int) (int, error)
Request body
{}
Response
{
"id": "signatureId"
}
DeleteSub(subId, petitionId, userId int) error
Response
{
"status": "ok"
}
Firstly, configure your .env
make run # run containers
make migrate # init tables
make swag # init swagger
docker-composeunit testsswaggerlog out endpoint