Skip to content

Commit 1a9a5f4

Browse files
committed
first commit
Todo API with Golang
0 parents  commit 1a9a5f4

File tree

18 files changed

+1103
-0
lines changed

18 files changed

+1103
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.env
2+
*.txt

README.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Golang Todo API
2+
3+
This is Golang API to create todo list for user. This app use Gin and Gorm framework.
4+
5+
## Table Of Contents
6+
7+
1. [User Endpoint](#user-endpoint)
8+
1.1 [Sign Up](#sign-up)
9+
1.2 [Login](#login)
10+
1.3 [Get All Todos](#get-all-users)
11+
1.4 [Get User By ID](#get-all-users)
12+
1.5 [Update User](#update-user)
13+
1.6 [Delete User](#delete-user)
14+
2. [Todo Endpoint](#todo-endpoint)
15+
2.1 [Create Todo](#create-todo)
16+
2.2 [Get All Todos By User ID](#get-all-todos)
17+
2.3 [Get All Todos By User ID](#get-all-todos-by-user-id)
18+
2.4 [Update Todo](#update-todo)
19+
2.5 [Delete Todo](#delete-todo)
20+
21+
## User Endpoint
22+
23+
### **Sign Up**
24+
25+
<details>
26+
<summary>
27+
<strong>See Details</strong>
28+
</summary>
29+
30+
- **URL:** `/user/register`
31+
- **Method:** `POST`
32+
- **Description:** Create a new user.
33+
- **Request Body:**
34+
35+
```json
36+
{
37+
"name": "Your name",
38+
"pass": "Your password"
39+
}
40+
```
41+
42+
</details>
43+
44+
### **Login**
45+
46+
<details>
47+
<summary>
48+
<strong>See Details</strong>
49+
</summary>
50+
51+
- **URL:** `/login`
52+
- **Method:** `GET`
53+
- **Description:** logged in to api.
54+
- **Request Body:**
55+
56+
```json
57+
{
58+
"name": "Your name",
59+
"pass": "Your password"
60+
}
61+
```
62+
63+
</details>
64+
65+
### **Logout**
66+
67+
<details>
68+
<summary>
69+
<strong>See Details</strong>
70+
</summary>
71+
72+
- **URL:** `/logout`
73+
- **Method:** `GET`
74+
- **Description:** logged out user from api.
75+
- **Request Body:** -
76+
77+
</details>
78+
79+
### **Get All Users**
80+
81+
<details>
82+
<summary>
83+
<strong>See Details</strong>
84+
</summary>
85+
86+
- **URL:** `/user/all`
87+
- **Method:** `GET`
88+
- **Description:** Get all users data from database.
89+
- **Request Body:** -
90+
91+
</details>
92+
93+
### **Get User By ID**
94+
95+
<details>
96+
<summary>
97+
<strong>See Details</strong>
98+
</summary>
99+
100+
- **URL:** `/user/:id`
101+
- **Method:** `GET`
102+
- **Description:** Get user data by id.
103+
- **Request Body:** -
104+
105+
</details>
106+
107+
### **Update User**
108+
109+
<details>
110+
<summary>
111+
<strong>See Details</strong>
112+
</summary>
113+
114+
- **URL:** `/user`
115+
- **Method:** `PUT`
116+
- **Description:** Update the currently logged in user.
117+
- **Request Body:**
118+
119+
```json
120+
{
121+
"name": "Your name",
122+
"pass": "Your password"
123+
}
124+
```
125+
126+
</details>
127+
128+
### **Delete User**
129+
130+
<details>
131+
<summary>
132+
<strong>See Details</strong>
133+
</summary>
134+
135+
- **URL:** `/user`
136+
- **Method:** `DELETE`
137+
- **Description:** Delete currently logged in user.
138+
- **Request Body:** -
139+
140+
</details>
141+
142+
## Todo Endpoint
143+
144+
### **Create Todo**
145+
146+
<details>
147+
<summary>
148+
<strong>See Details</strong>
149+
</summary>
150+
151+
- **URL:** `/todo`
152+
- **Method:** `POST`
153+
- **Description:** Create a new todo to currently logged user.
154+
- **Request Body:**
155+
156+
```json
157+
{
158+
"todo": "Your todo",
159+
}
160+
```
161+
162+
</details>
163+
164+
### **Get All Todos**
165+
166+
<details>
167+
<summary>
168+
<strong>See Details</strong>
169+
</summary>
170+
171+
- **URL:** `/todo/all`
172+
- **Method:** `GET`
173+
- **Description:** Get all todos from database.
174+
- **Request Body:** -
175+
176+
</details>
177+
178+
### **Get All Todos By User ID**
179+
180+
<details>
181+
<summary>
182+
<strong>See Details</strong>
183+
</summary>
184+
185+
- **URL:** `/todo`
186+
- **Method:** `GET`
187+
- **Description:** Get all todos by by user id.
188+
- **Request Body:** -
189+
190+
</details>
191+
192+
### **Update Todo**
193+
194+
<details>
195+
<summary>
196+
<strong>See Details</strong>
197+
</summary>
198+
199+
- **URL:** `/todo`
200+
- **Method:** `PUT`
201+
- **Description:** Edit your todo parameter, like check and uncheck.
202+
- **Request Body:**
203+
204+
```json
205+
{
206+
"todo": "Your todo",
207+
"isDone": true or false
208+
}
209+
```
210+
211+
</details>
212+
213+
### **Delete Todo**
214+
215+
<details>
216+
<summary>
217+
<strong>See Details</strong>
218+
</summary>
219+
220+
- **URL:** `/todo`
221+
- **Method:** `DELETE`
222+
- **Description:** Delete currently user's todo using todo ID.
223+
- **Request Body:** -
224+
225+
</details>

api/database/database.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package database
2+
3+
import (
4+
"os"
5+
6+
"github.com/errorsolver/Todo-Golang/api/model"
7+
"gorm.io/driver/postgres"
8+
"gorm.io/gorm"
9+
)
10+
11+
var DB *gorm.DB
12+
13+
func InitDB() {
14+
dsn := os.Getenv("PGSQL")
15+
db, err := gorm.Open(postgres.Open(dsn))
16+
if err != nil {
17+
panic("ERRORL: Failed to connect database")
18+
}
19+
20+
db.AutoMigrate(
21+
&model.User{},
22+
&model.Todo{},
23+
)
24+
25+
DB = db
26+
}

0 commit comments

Comments
 (0)