diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/client_router.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/client/client_router.go b/client/client_router.go index a36ec48..cc9e19d 100644 --- a/client/client_router.go +++ b/client/client_router.go @@ -10,13 +10,24 @@ import ( func Routes(route *gin.Engine) { c := route.Group("/client") { + c.GET("/", func(ctx *gin.Context) { + // TODO: add functionality to filter results + clients, err := client.GetClients(nil) + if err != nil { + ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + log.Printf("ERROR: Failed to read clients from DB: %v\n", err.Error()) + } + + ctx.JSON(http.StatusOK, clients) + }) + c.POST("/", func(ctx *gin.Context) { var x client.Client ctx.Bind(&x) err := x.Save() if err != nil { ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - log.Printf("ERROR: Failed to add new client \"%s\": %v", x.Name, err.Error()) + log.Printf("ERROR: Failed to add new client \"%s\": %v\n", x.Name, err.Error()) } log.Println("Added new client to database: ", x.Name) @@ -29,7 +40,7 @@ func Routes(route *gin.Engine) { err := x.Delete() if err != nil { ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - log.Printf("ERROR: Failed to delete client \"%s\": %v", x.Name, err.Error()) + log.Printf("ERROR: Failed to delete client \"%s\": %v\n", x.Name, err.Error()) } log.Println("Deleted client: ", x.Name) |