Added POST method and form data input and parsing
created the post requests as well as relevant models involved in API responses
This commit is contained in:
parent
36061f27d6
commit
2415b323d5
9
handlers/Admin.go
Normal file
9
handlers/Admin.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/labstack/echo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func View(c echo.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
57
handlers/User.go
Normal file
57
handlers/User.go
Normal file
@ -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"})
|
||||||
|
}
|
5
models/Error.go
Normal file
5
models/Error.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Error struct {
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
15
models/UserReview.go
Normal file
15
models/UserReview.go
Normal file
@ -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
|
||||||
|
}
|
5
models/Valid.go
Normal file
5
models/Valid.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Valid struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
1
mongo/mongo.go
Normal file
1
mongo/mongo.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package mongo
|
Loading…
Reference in New Issue
Block a user