diff --git a/handlers/Admin.go b/handlers/Admin.go new file mode 100644 index 0000000..6a0ca4e --- /dev/null +++ b/handlers/Admin.go @@ -0,0 +1,9 @@ +package handlers + +import ( + "github.com/labstack/echo" +) + +func View(c echo.Context) error { + return nil +} diff --git a/handlers/User.go b/handlers/User.go new file mode 100644 index 0000000..b56e8ff --- /dev/null +++ b/handlers/User.go @@ -0,0 +1,57 @@ +package handlers + +import ( + "CSMValetingReviewAPI/models" + "fmt" + "net/http" + "strconv" + + "github.com/labstack/echo" +) + +func Upload(c echo.Context) error { + + //Personal details -- Potentially nil + firstName := c.FormValue("FirstName") + lastName := c.FormValue("LastName") + contactNumber := c.FormValue("ContactNumber") + + //Quality Statistics + service := c.FormValue("Service") + quality, err := strconv.ParseInt(c.FormValue("Quality"), 10, 64) + + if err != nil { + return c.JSON(http.StatusBadRequest, models.Error{Error: err.Error()}) + } + + recommendation, err := strconv.ParseInt(c.FormValue("Recommendation"), 10, 64) + + if err != nil { + return c.JSON(http.StatusBadRequest, models.Error{Error: err.Error()}) + } + + notes := c.FormValue("Notes") + //images, _ := c.FormFile("image") + + // if err != nil { + // return c.JSON(http.StatusBadRequest, "Failed") + // } + + Review := models.UserReview{ + FirstName: firstName, + LastName: lastName, + ContactNumber: contactNumber, + + Service: service, + Quality: quality, + Recommendation: recommendation, + Notes: notes, + //Image: images, + } + + fmt.Println(Review) + + //Upload into MongoDB + + return c.JSON(http.StatusOK, models.Valid{Status: "Valid"}) +} diff --git a/models/Error.go b/models/Error.go new file mode 100644 index 0000000..5cff563 --- /dev/null +++ b/models/Error.go @@ -0,0 +1,5 @@ +package models + +type Error struct { + Error string `json:"error"` +} diff --git a/models/UserReview.go b/models/UserReview.go new file mode 100644 index 0000000..72f4999 --- /dev/null +++ b/models/UserReview.go @@ -0,0 +1,15 @@ +package models + +import "mime/multipart" + +type UserReview struct { + FirstName string + LastName string + ContactNumber string + + Service string + Quality int64 + Recommendation int64 + Notes string + Image *multipart.FileHeader +} diff --git a/models/Valid.go b/models/Valid.go new file mode 100644 index 0000000..1c58994 --- /dev/null +++ b/models/Valid.go @@ -0,0 +1,5 @@ +package models + +type Valid struct { + Status string `json:"status"` +} diff --git a/mongo/mongo.go b/mongo/mongo.go new file mode 100644 index 0000000..af2a1bf --- /dev/null +++ b/mongo/mongo.go @@ -0,0 +1 @@ +package mongo