# README
Sword Health Code Challenge
This is a task management application written in Go that provides a REST API for authentication and authorization of users with different roles. The application and its dependencies can be run using Docker Compose.
Features
- Task management: users can create, read, update, and delete tasks
- Role-based authentication: users are assigned different roles (manager and technician) and are authorized to perform certain actions based on their role
- REST API: the application provides a REST API for managing tasks, users and performing authentication and authorization
- Docker Compose: the application and its dependencies can be run using Docker Compose for easy setup and configuration
Prerequisites
- Docker and Docker Compose
Getting Started
Installation
- Clone the repository
git clone https://github.com/PixDale/sh-code-challenge.git
- Navigate to the project directory
cd sh-code-challenge
- Start the application using Docker Compose
docker-compose up
PS: If needed you can clean docker cache before start, using the command make docker_clean
API Endpoints
The API provides the following endpoints for task management and authentication:
- POST
/tasks
: create a new task
{"summary": "Performed a task", "user_id": 1}
*the user_id must match the user id from token
- GET
/tasks
: retrieve a list of tasks- For requests with the Manager role, all tasks will be retrieved
- For requests with the Technician role, only the task from this user will be retrieved
- GET
/tasks/{id}
: retrieve a single task by ID- For requests with the Manager role, the task is retrieved unconditionally
- For requests with the Technician role, the task is retrieved only if it belongs to this user
- PUT
/tasks/{id}
: update an existing task- For requests with the Manager role, the task is updated unconditionally
- For requests with the Technician role, the task is updated only if it belongs to this user
{"summary": "Performed a task", "user_id": 1}
*the user_id must match the user id from token
- DELETE
/tasks/{id}
: delete a task- Requests must have a user token with the Manager role
All user management requests must have a user token with the Manager role
- POST
/users
: register a new user
{"name": "Felipe", "email": "[email protected]", "password": "123", "role": 1}
- GET
/users
: retrieve a list of users - GET
/users/{id}
: retrieve a single user by ID - PUT
/users/{id}
: update an existing user
{"name": "Felipe", "email": "[email protected]", "password": "123", "role": 1}
-
DELETE
/users/{id}
: delete a user -
POST
/login
: login to retrieve a JWT token- Return the JWT Token containing information such as User ID and Role
Authentication
Access to all endpoints except for login, requires a JSON Web Token (JWT) for authentication. The token must be included in the Authorization
header of the request in the following format:
Authorization: Bearer [JWT_TOKEN]
Authorization
There is role based authorization implemented for the API requests. Existing roles:
Manager Role: 1
Technician Role: 2
Notification
This project contains 2 apps, in addition to the main API app, there is also a notification app, which can be found in the root of the repository.
This notification app is responsible for receiving and handling the notification sent by the main API app. It currently only prints the notification to standard output, but it can easily be replaced with another means of generating a notification.
In the main API app, notifications are implemented as a middleware, checking whether the current request comes from a technician, if so, it sends a message to the notification queue, containing the action that this user is performing.
Tests
To run the test environment along with the unit tests run the command:
docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit
Doc
To check the Golang documentation, first you need to have godoc cmd. To install it run:
go install -v golang.org/x/tools/cmd/godoc@latest
After installed, run:
godoc --http=localhost:6060
then access: http://127.0.0.1:6060/pkg/github.com/PixDale/sh-code-challenge/
Kubernetes
To start the kubernetes deployment, first you need to have minikube
and kubectl
installed, then run:
make kube_start
make kube_apply
After that if you want to stop, run:
make kube_stop
License
This project is licensed under the MIT License.