summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-25 16:11:32 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-25 16:11:32 +0530
commit3637ed7f0a50e36f3acfbacc0f81bb7141e7a2d4 (patch)
tree0d122424ba991675fe05ff3bac5f23984be05d8c /client
parent511cd255e8754e54b0c3edc71e045f1bd7034ecf (diff)
added GET routes
Diffstat (limited to 'client')
-rw-r--r--client/client_router.go15
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)