Task-List-Service is a simple Go service utilising hexagonal architecture design with Gorilla Mux & Postgres.
- Database table structure
- Running the service
- Return task by UUID
- Return all tasks created by user
- Creates task
- Update a task
To run a postgres instance through docker : docker run --name pg-docker -e POSTGRES_PASSWORD= -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
Here is a good article to run up postgres locally through a docker container.
CREATE TABLE "public"."todo_list" (
"id" SERIAL NOT NULL,
"uuid" varchar NOT NULL,
"task" varchar(10000) NOT NULL,
"completed" bool NOT NULL,
"createdby" varchar(100) NOT NULL,
"modifiedby" varchar(100) NOT NULL,
"modifiedon" timestamp NOT NULL,
PRIMARY KEY ("id")
);
Service will runs on : http://127.0.0.1:9100
Update main.go with the postgres password chosen in the above step.
go run main.go
Retreives a task specified by a Uuid.
GET /task/{uuid}
Headers : content-type=application/json
Headers : content-type=application/json
{
"Id": 19,
"Uuid": "335979c6-b5b2-4e6d-87da-4bdf8bc5d5f8",
"Task": "Hello, Task World!",
"Completed": false,
"CreatedBy": "AyZee",
"ModifiedBy": "AyZee",
"ModifiedOn": "2022-02-22T23:46:19.286798Z"
}
Retreives all tasks created by the supplied user.
GET /task/{user}
Headers : content-type=application/json
Headers : content-type=application/json
[
{
"Id": 19,
"Uuid": "335979c6-b5b2-4e6d-87da-4bdf8bc5d5f8",
"Task": "Hello, Task World!",
"Completed": false,
"CreatedBy": "AyZee",
"ModifiedBy": "AyZee",
"ModifiedOn": "2022-02-22T23:46:19.286798Z"
},
{
"Id": 20,
"Uuid": "c55bdb8f-d80b-4179-a9ed-952554a8dce0",
"Task": "Hello, Task World 2!",
"Completed": false,
"CreatedBy": "AyZee",
"ModifiedBy": "AyZee",
"ModifiedOn": "2022-02-23T00:09:54.389178Z"
},
{
"Id": 21,
"Uuid": "68935ecf-d44e-48ab-a1a5-5f616ca2bf4b",
"Task": "Hello, Task World 3!",
"Completed": false,
"CreatedBy": "AyZee",
"ModifiedBy": "AyZee",
"ModifiedOn": "2022-02-23T00:09:58.7378Z"
}
]
Create a task to persist to the database. Returns UUID of task.
POST /task/
Headers : content-type=application/json
{
"Task": "Hello, Task World!",
"Completed": false
}
Headers : content-type=application/json
335979c6-b5b2-4e6d-87da-4bdf8bc5d5f8
Updates a task by specifying Uuid and completion status.
POST /task/update
Headers : content-type=application/json
{
"Uuid": "335979c6-b5b2-4e6d-87da-4bdf8bc5d5f8",
"Completed": true
}
204 - No Content