This is a Go web application for the Savannah e-Shop project, built using Go standard library, go-chi and OAuth authentication. The application also uses Africa's Talking for sending SMS notifications and Azure for hosting.
- Create and manage customer records.
- Create and manage order records.
- Demo callback endpoint for OAuth2 authentication.
- Send SMS notifications using Africa's Talking.
- PostgreSQL database
- Circle ci pipeline
- Azure
To run this application locally, follow this step:
-
Clone the repository:
git clone [email protected]:0xAckerMan/Savanah.git
-
Create a savannah.env file in the root directory and set the following environment variables:
ENVIRONMENT=<dev|stag|prod>
DATABASE_DSN="host=<host> user=<dbusername> password=<dbpassword> dbname=<dbname> port=<dbport> sslmode="
JWT_SECRET=
TOKEN_EXPIRES_IN=
TOKEN_MAXAGE=
GOOGLE_OAUTH_CLIENT_ID=
GOOGLE_OAUTH_CLIENT_SECRET=
GOOGLE_OAUTH_REDIRECT_URL=
AFRICASTALKING_APIKEY=
AFRICASTALKING_USERNAME=
-
Install dependencies:
go mod tidy
-
Run the application:
go run ./cmd/api
-
/
GET - home{ "message": "Welcome to Savanah API" }
-
/api/v1/healthcheck
GET -return the health status of the api{ "health": { "environment": "production", "status": "active", "version": "1.0.0" } }
-
/api/v1/register
POST - Creates customer and admin ifis_admin = true
{ "first_name": "John", "last_name": "Doe", "email": "[email protected]", "phone_number": "+254712345678", "password": "password", "is_admin": true }
{ "customer": { "ID": 1, "CreatedAt": "2024-02-22T16:56:21.727300812+03:00", "UpdatedAt": "2024-02-22T16:56:21.727300812+03:00", "DeletedAt": null, "first_name": "John", "last_name": "Doe", "email": "[email protected]", "phone_number": "+254712345678", "Orders": null } }
-
/api/v1/login
POST - Users login to the system and token is setted in cookies{ "email": "[email protected]", "password": "password" }
{ "token": "##############################################" }
-
/api/v1/logout
GET - Logs out a user from the system -
/api/v1/admin/products
POST - creates a product and returns a response of the created product{ "product_name": "Headphone", "description": "A blue Headphone", "price": 4000 }
{ "product": { "ID": 1, "CreatedAt": "2024-02-22T17:52:36.965522494+03:00", "UpdatedAt": "2024-02-22T17:52:36.965522494+03:00", "DeletedAt": null, "product_name": "Headphone", "description": "A blue Headphone", "price": 4000, "version": 1 } }
-
/api/v1/admin/products/1
PATCH - Performs both partial and full delete and updates the version of the product to avoid data race{ "product_name": "UBL Headphone", "description": "A blue high-end Headphone" }
{ "product": { "ID": 1, "CreatedAt": "2024-02-22T17:52:36.965522+03:00", "UpdatedAt": "2024-02-22T17:57:09.675743505+03:00", "DeletedAt": null, "product_name": "UBL Headphone", "description": "A blue high-end Headphone", "price": 4000, "version": 2 } }
-
/api/v1/admin/customers
GET - gets all customers who are not admin{ "customers": [ { "ID": 2, "CreatedAt": "2024-02-22T17:02:28.749401+03:00", "UpdatedAt": "2024-02-22T17:02:28.749401+03:00", "DeletedAt": null, "first_name": "Jane", "last_name": "smith", "email": "[email protected]", "phone_number": "+254722345678", "Orders": [] }, { "ID": 4, "CreatedAt": "2024-02-22T18:19:51.768231+03:00", "UpdatedAt": "2024-02-22T18:19:51.768231+03:00", "DeletedAt": null, "first_name": "John", "last_name": "smith", "email": "[email protected]", "phone_number": "+254712234568", "Orders": [] } ] }
/api/v1/orders
POST - a customer can make an order. Gets the current logged in user.{ "product_id": 1, "quantity": 2 }
#### response
```json
{
"order": {
"ID": 5,
"CreatedAt": "2024-02-22T19:15:29.934709087+03:00",
"UpdatedAt": "2024-02-22T19:15:29.934709087+03:00",
"DeletedAt": null,
"customer_id": 2,
"product_id": 1,
"quantity": 2,
"order_status": "placed",
"version": 1,
"Customer": null,
"Product": null
}
}
/api/v1/customers/me
GET - Gets a customer profile{ "customer": { "ID": 2, "CreatedAt": "2024-02-22T17:02:28.749401+03:00", "UpdatedAt": "2024-02-22T17:02:28.749401+03:00", "DeletedAt": null, "first_name": "Jane", "last_name": "smith", "email": "[email protected]", "phone_number": "+254722345678", "Orders": [ { "ID": 1, "CreatedAt": "2024-02-22T19:05:40.451318+03:00", "UpdatedAt": "2024-02-22T19:05:40.451318+03:00", "DeletedAt": null, "customer_id": 2, "product_id": 1, "quantity": 2, "order_status": "placed", "version": 1, "Customer": null, "Product": { "ID": 1, "CreatedAt": "2024-02-22T17:52:36.965522+03:00", "UpdatedAt": "2024-02-22T17:57:09.675743+03:00", "DeletedAt": null, "product_name": "UBL Headphone", "description": "A blue high-end Headphone", "price": 4000, "version": 2 } } ] } }
- Africa's Talking Go SDK: SDK for Africa's Talking SMS and other services.