-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fully tested controller & route for GetAllTask route
- Loading branch information
1 parent
0020dd5
commit faa69a6
Showing
5 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/pacholoamit/GO-TASK-MGR/pkg/routes" | ||
) | ||
|
||
func main() { | ||
e := echo.New() | ||
e.GET("/", func(c echo.Context) error { | ||
return c.String(http.StatusOK, "Hello, World!") | ||
}) | ||
routes.TaskRoutes(e) | ||
e.Logger.Fatal(e.Start(":1323")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
package controllers | ||
package controllers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/pacholoamit/GO-TASK-MGR/pkg/models" | ||
) | ||
|
||
|
||
var NewTask models.Task | ||
|
||
func GetAllTasks(c echo.Context) error { | ||
newTasks:=models.GetAllTasks() | ||
return c.JSON(http.StatusOK, newTasks) | ||
} | ||
|
||
func CreateTask(c echo.Context) error { | ||
t := new(models.Task) | ||
if err := c.Bind(t); err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
package models | ||
package models | ||
|
||
import ( | ||
"github.com/pacholoamit/GO-TASK-MGR/pkg/config" | ||
"gorm.io/gorm" | ||
) | ||
|
||
var db *gorm.DB | ||
|
||
type Task struct{ | ||
gorm.Model | ||
Title string `json:"title" form:"title" query:"title" ` | ||
Description string `json:"description" form:"description" query:"description"` | ||
} | ||
|
||
func init() { | ||
config.Connect() | ||
db = config.GetDB() | ||
db.AutoMigrate(&Task{}) | ||
} | ||
|
||
func CreateTask(t *Task) *Task { | ||
db.Create(&t) | ||
return t | ||
} | ||
|
||
func GetAllTasks() []Task { | ||
var Tasks []Task | ||
db.Find(&Tasks) | ||
return Tasks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters