Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

ethicnology/uqac-851-software-engineering-api

Repository files navigation

Integration Backend Deployment Backend Go Report Card BCH compliance

About The Project


This is a school project.
All the specifications are specified in docs/Projet_Pratique.pdf

📂 Directory Structure

.
├── docs
|
├── database
│   ├── model                // ORM models and Generators for database testing
│       └── ...
├── http
│   ├── controller           // Business logic of the application
│   │   └── ...
│   ├── middleware           // Logic executed before or after controllers
│   │   └── ...
│   └── route
│       └── route.go         // Routes definition
│
├── test                     // Unit and Functional tests
|   └── func_test.go
|   └── unit_test.go
|
├── .gitignore
├── config.example.json      // Example config for local development
├── config.test.json         // Config file used for tests
├── docker-compose.yml       // Build local architecture file used for tests
├── docker-compose.test.yml  // Build architecture to execute tests
├── Dockerfile               // API Dockerfile
├── go.mod
└── main.go                  // Application entrypoint

🚀 Getting Started

To get a local copy up and running follow these simple example steps.

📃 Prerequisites

All the project architecture is dockerized : Docker.
You only need docker installed in your OS in order to host all the components without any extra-installation.

👷 Installation

Clone

git clone https://github.com/ethicnology/uqac-851-software-engineering-api.git

Configuration

Copy config.example.json as config.json and add the SMTP password (ask to students).

cp config.example.json config.json

If you want to run the tests, you need to specify the SMTP password in the config.test.json too :

{ ...
      "prix-banque":{
        "smtp_host":"smtp.gmail.com",
        "smtp_port":"587",
        "smtp_user":"prixbanque@gmail.com",
        "smtp_pass":"" //Ask Students For The Password
    }
}

🐳 Run with docker

docker-compose up
# Available on 172.x.x.x:1984

🙏 Tests

docker-compose -f docker-compose.test.yml up --abort-on-container-exit --remove-orphans
# Exit when tests are finished

📚 Documentation

I built a website with Github Pages which contains API documentation
Also, you can find a markdwown version in /docs/README.md

🏃 Usage

Postman

To play with your API, import the collection in /docs in Postman.
All available endpoints are documented with examples.

cURL

Instead you can try it with your CLI using cURL.
On following examples URL is : https://dissidence.dev:9999 you can change this by your docker IP using http without ssl

Windows

Windows force you to mask doublequotes with backslash like this :

curl -d "{\"email\":\"existing@email.pls\",\"password\":\"Str0ng\",\"first_name\":\"Paul\",\"last_name\":\"Lefevbre\"}" -H "Content-Type: application/json" -X POST https://dissidence.dev:9999/auth/register
Linux
curl -d '{"email":"existing@email.pls","password":"Str0ng","first_name":"Paul","last_name":"Lefevbre"}' -H 'Content-Type: application/json' -X POST https://dissidence.dev:9999/auth/register
# {"id":9}
curl -d '{"email":"existing@email.pls","password":"Str0ng"}' -H 'Content-Type: application/json' -X POST https://dissidence.dev:9999/auth/login
# {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTM0NzkyNDQsIm5iZiI6MTYxNzQ3OTI0NCwidXNlcmlkIjoic2Vuc2VpQHVxYWMuY2EifQ.aMRWeebCTfJyUPfsUz5H8Ng1x1L1T10hSKpXoVdyPUY"}
TOKEN=$YourToken;curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -X GET https://dissidence.dev:9999/users/existing@email.pls
# {"created_at":"2021-04-03T19:47:19.718Z","updated_at":"2021-04-03T19:47:19.718Z","deleted_at":null,"id":10,"email":"existing@email.pls","first_name":"Paul","last_name":"Lefebvre"}

🔨 Build from scratch

Prerequisites

If you want to build the project from scratch without docker you need to install few tools.

  • Go 1.13+
  • mariadb-server

Once you've installed Go and MariaDB. You need to create a MariaDB user and a database:

mysql> CREATE USER 'goyave'@'localhost' IDENTIFIED BY 'secret';
mysql> CREATE DATABASE goyave;
mysql> GRANT ALL PRIVILEGES ON 'goyave'.* TO 'goyave'@'localhost';
mysql> FLUSH PRIVILEGES;

You can change theses values but you will need to update config.json.

Build

From root directory, execute :

go build

It will output an executable which have the same name as the project, make it executable :

chmod +X uqac-851-software-engineering-api

Then, run :

./uqac-851-software-engineering-api

🔍 Contact

@ethicnology
Project Link: https://github.com/851-software-engineering