Categorygithub.com/pierre-lecocq/todayornever-api
repositorypackage
1.1.3
Repository: https://github.com/pierre-lecocq/todayornever-api.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Today or never

  

This program is a service to manage your tasks, with a focus on what you can do today.

It is a REST API implementing the following features:

  • JSON responses
  • JWT authentication
  • CORS protection
  • Rate limiting
  • Request logging
  • Observability

🛠️ Installation

Create a configuration file

Create a .env file with the following content and adapt the values
# Service configuration
SERVICE_HOST=localhost
SERVICE_PORT=8080

# Database configuration
DATABASE_ENGINE=sqlite3
DATABASE_DSN=./todayorneverd.db

# Logger minimum level
# See https://github.com/rs/zerolog?tab=readme-ov-file#leveled-logging
LOGGER_LEVEL=0

# JWT based authentication
AUTH_ISSUER=todayornever-api
AUTH_SECRET=<REDACTED> # a long and random string
AUTH_EXPIRES=1 # in hours

Compiling

Compiling requires the installation of make, golang and SQLite3

make

Running

./todayornever-api

🎯 API endpoints

Authentication

POST /users/signup (create a new user)
Parameters
namelocationdata typemandatorydescription
usernameJSON bodystringyesA valid string with 3 characters minimum
emailJSON bodystringyesA valid email
passwordJSON bodystringyesA valid password
Responses
http codecontent-typeresponse
200application/jsonA user object
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -X POST -H "Content-Type: application/json" --data '{"username": "example", "email": "[email protected]", "password": "P4sSw0rd~"}' http://localhost:8080/users/signup
POST /users/login (login with an existing user)
Parameters
namelocationdata typemandatorydescription
emailJSON bodystringyesA valid email
passwordJSON bodystringyesA valid password
Responses
http codecontent-typeresponse
200application/json{"token": "<token>", "expires": "<timestamp>"}
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -X POST -H "Content-Type: application/json" --data '{"email": "[email protected]", "password": "P4sSw0rd~"}' http://localhost:8080/users/login

Projects

GET /projects (list all projects)
Responses
http codecontent-typeresponse
200application/jsonAn array of project objects
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -H "Authorization: Bearer <token>" http://localhost:8080/projects
GET /projects/{id} (Fetch a project identified by {id})
Parameters
namelocationdata typemandatorydescription
idURInumericyesA valid integer
Responses
http codecontent-typeresponse
200application/jsonA project object
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -H "Authorization: Bearer <token>" http://localhost:8080/projects/1
POST /projects (create a new project)
Parameters
namelocationdata typemandatorydescription
nameJSON bodystringyesA valid string of 3 characters minimum
descriptionJSON bodystringnoA valid string of 3 characters minimum
Responses
http codecontent-typeresponse
201application/jsonA project object
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -X POST -H "Authorization: Bearer <token>" -H "Content-Type: application/json" --data '{"name": "Project 1"}' http://localhost:8080/projects
PATCH /projects/{id} (update a project identified by {id})
Parameters
namelocationdata typemandatorydescription
idURInumericyesA valid integer
nameJSON bodystringnoA valid string of 3 characters minimum
descriptionJSON bodystringnoA valid string of 3 characters minimum
Responses
http codecontent-typeresponse
200application/jsonA project object
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -X PATH -H "Authorization: Bearer <token>" -H "Content-Type: application/json" --data '{"name": "Edited project 1"}' http://localhost:8080/projects/1
DELETE /projects/{id} (delete a project identified by {id})
Parameters
namelocationdata typemandatorydescription
idURInumericyesA valid integer
Responses
http codecontent-typeresponse
204application/jsonNo Content
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -X DELETE -H "Authorization: Bearer <token>" http://localhost:8080/projects/1

Tasks

GET /tasks (list all tasks)
Responses
http codecontent-typeresponse
200application/jsonAn array of task objects
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -H "Authorization: Bearer <token>" http://localhost:8080/tasks
GET /tasks/{id} (Fetch a task identified by {id})
Parameters
namelocationdata typemandatorydescription
idURInumericyesA valid integer
Responses
http codecontent-typeresponse
200application/jsonA task object
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -H "Authorization: Bearer <token>" http://localhost:8080/tasks/1
POST /tasks (create a new task)
Parameters
namelocationdata typemandatorydescription
titleJSON bodystringyesA valid string of 3 characters minimum
descriptionJSON bodystringnoA valid string of 3 characters minimum
Responses
http codecontent-typeresponse
201application/jsonA task object
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -X POST -H "Authorization: Bearer <token>" -H "Content-Type: application/json" --data '{"title": "Task 1"}' http://localhost:8080/tasks
PATCH /tasks/{id} (update a task identified by {id})
Parameters
namelocationdata typemandatorydescription
idURInumericyesA valid integer
titleJSON bodystringnoA valid string of 3 characters minimum
descriptionJSON bodystringnoA valid string of 3 characters minimum
Responses
http codecontent-typeresponse
200application/jsonA task object
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -X PATH -H "Authorization: Bearer <token>" -H "Content-Type: application/json" --data '{"title": "Edited task 1"}' http://localhost:8080/tasks/1
DELETE /tasks/{id} (delete a task identified by {id})
Parameters
namelocationdata typemandatorydescription
idURInumericyesA valid integer
Responses
http codecontent-typeresponse
204application/jsonNo Content
400application/json{"code":"400","message":"Bad Request"}
401application/json{"code":"401","message":"Unauthorized"}
Example
curl -X DELETE -H "Authorization: Bearer <token>" http://localhost:8080/tasks/1

💾 Data model

User model
propertytypedescription
idnumericAn identifier generated at the creation
usernamestring
emailstring
password_hashstringGenerated at creation
saltstringGenerated at creation
statestring
created_atdatetime
updated_atdatetime
Project model
propertytypedescription
idnumericAn identifier generated at the creation
user_idnumericA reference to the owner
namestring
descriptionstring
positionnumeric
created_atdatetime
updated_atdatetime
Task model
propertytypedescription
idnumericAn identifier generated at the creation
user_idnumericA reference to the owner
project_idnumericA reference to the associated project
parent_task_idnumericA reference to the parent task
titlestring
descriptionstring
statestring
positionnumeric
overdueboolean
due_atdatetime
created_atdatetime
updated_atdatetime

📡 Observability

The logger is configured to send events to OpenObserve if the appropriate configuration variables are set.


🔖 License

This software is distributed under the MIT license.