diff --git a/go.mod b/go.mod index 221ebcb..de11de4 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/jmoiron/sqlx v1.3.5 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.6 // indirect - github.com/leodido/go-urn v1.2.4 // indirect + github.com/leodido/go-urn v1.3.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-sqlite3 v1.14.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/go.sum b/go.sum index 9fef4a8..9b0a676 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,8 @@ github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZY github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.3.0 h1:jX8FDLfW4ThVXctBNZ+3cIWnCSnrACDV73r76dy0aQQ= +github.com/leodido/go-urn v1.3.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= diff --git a/handler.go b/handler.go new file mode 100644 index 0000000..9775489 --- /dev/null +++ b/handler.go @@ -0,0 +1,32 @@ +package main + +import ( + "time" + + _ "github.com/mattn/go-sqlite3" +) + +type Task struct { + TaskID int + UserID string + Category string + TaskName string + Description string + StartTime time.Time + EndTime time.Time + IsCompleted bool + IsRecurring bool + IsAllDay bool +} + +type TaskPreview struct { + TaskID int + UserID string + Category string + TaskName string + StartTime time.Time + EndTime time.Time + IsCompleted bool + IsRecurring bool + IsAllDay bool +} diff --git a/main.go b/main.go index f7b2720..71eebd2 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,15 @@ package main -import "github.com/gin-gonic/gin" -import "net/http" -import "os" -import "github.com/jmoiron/sqlx" -import _"github.com/mattn/go-sqlite3" - import ( + "net/http" + "os" + + "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" + "fmt" + + _ "github.com/mattn/go-sqlite3" ) func main() { @@ -17,27 +19,60 @@ func main() { "message": "pong", }) }) - // exactly the same as the built-in + // exactly the same as the built-in schemacreate, erro := os.ReadFile("schema.sql") - if(erro!=nil){ + if erro != nil { fmt.Println("breaky") } fmt.Println(string(schemacreate)) - db,err := sqlx.Open("sqlite3", ":memory:") - if err != nil{ + db, err := sqlx.Open("sqlite3", ":memory:") + if err != nil { fmt.Println("breaky") } - - // force a connection and test that it worked - swagmoney := db.Ping() + + // force a connection and test that it worked + swagmoney := db.Ping() db.MustExec(string(schemacreate)) - if swagmoney != nil{ + if swagmoney != nil { fmt.Println("breaky") - }else{ + } else { fmt.Println("not breaky") } - - fmt.Println("Running at http://localhost:8080") + + //Router: takes incoming requests and routes them to functions to handle them + //Building a group of routes starting with this path + v1 := r.Group("/main/blah") //TODO: FIX the route and the uri's below + { + v1.GET("tasks", getAllUserTasks) + v1.GET("task/:id", getTaskById) + v1.POST("tasks", createTask) + v1.PUT("tasks/:id", editTask) + v1.DELETE("tasks/:id", deleteTask) + + } + + fmt.Println("Running at http://localhost:8080") r.Run() // listen and serve on 0.0.0.0:8080 } + +func createTask(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"message": "Called createTask"}) +} + +func editTask(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"message": "Called editTask"}) +} + +func deleteTask(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"message": "Called deleteTask"}) +} + +func getAllUserTasks(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"message": "Called getAllUserTasks"}) +} + +func getTaskById(c *gin.Context) { + id := c.Param("id") + c.JSON(http.StatusOK, gin.H{"message": "Called GetTaskById on Id:" + id}) +}