todo-app

command module
v0.0.0-...-323d3c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 17 Imported by: 0

README

todo_app

About

This repository will create a web application that is an API server for managing TODO tasks with authentication.

[!WARNING] The authentication feature is currently under development.

Endpoint

HTTP Method Path Overview
POST /register Register a new user
POST /login Obtain an access token with registered user information
POST /tasks Register tasks using an access token
GET /tasks List tasks using an access token
GET /admin Only users with administrative privileges can access

Makefile

Docker Compose is used to launch the API server, MySQL, and Redis. The commands that will mainly be executed are pre-defined in the Makefile.

$ make
build                Build docker image to deploy
build-local          Build docker image to local development
up                   Do docker compose up with hot reload
down                 Do docker compose down
logs                 Tail docker compose logs
ps                   Check container status
test                 Execute tests
dry-migrate          Try migration
migrate              Execute migration
generate             Generate codes
help                 Show options
How to check operation

This is the procedure to check if the code in this repository can be executed locally.

Start the server

Create a Docker image in advance.

$ make build-local

Use Docker Compose to start each service.

$ make up

Perform a migration to MySQL.

$ make migrate

Create a user.

$ curl -X POST localhost:18000/register -d '{"name": "budou", "password":"test", "role":"admin"}'
{"id":37}

Register some tasks using the user's authentication information.

$ curl -i -XPOST -H "Authorization: Bearer $(curl -XPOST localhost:18000/login -d '{"user_name": "budou", "password":"test"}' | jq ".access_token" | sed "s/\"//g")" localhost:18000/tasks -d @./handler/testdata/add_task/ok_req.json.golden
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100  1023  100   982  100    41   7756    323 --:--:-- --:--:-- --:--:--  8525
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Wed, 20 Jul 2022 17:21:03 GMT
Content-Length: 9

{"id":76}%

$ curl -XPOST -H "Authorization: Bearer $(curl -XPOST localhost:18000/login -d '{"user_name": "budou", "password":"test"}' | jq ".access_token" | sed "s/\"//g")" localhost:18000/tasks -d @./handler/testdata/add_task/ok_req.json.golden
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100  1023  100   982  100    41   8634    360 --:--:-- --:--:-- --:--:--  9560
{"id":77}%

Display the tasks, and if the registered tasks are displayed, it is working as expected.

$ curl -XGET -H "Authorization: Bearer $(curl -XPOST localhost:18000/login -d '{"user_name": "budou", "password":"test"}' | jq ".access_token" | sed "s/\"//g")" localhost:18000/tasks | jq
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100  1023  100   982  100    41   8158    340 --:--:-- --:--:-- --:--:--  9133
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100   113  100   113    0     0  13450      0 --:--:-- --:--:-- --:--:-- 28250
[
{
"id": 76,
"title": "Implement a handler",
"status": "todo"
},
{
"id": 77,
"title": "Implement a handler",
"status": "todo"
}
]

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL