Started with items
This commit is contained in:
34
handlers/project_items.go
Normal file
34
handlers/project_items.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"MiauInv/storage"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ProjectItemRequest struct {
|
||||
ItemID int `json:"item_id"`
|
||||
ProjectID int `json:"project_id"`
|
||||
Quantity int `json:"quantity"`
|
||||
}
|
||||
|
||||
func AllocateToProject(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req ProjectItemRequest
|
||||
|
||||
json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
_, err := storage.DB.Exec(`
|
||||
INSERT INTO project_items(item_id,project_id,quantity)
|
||||
VALUES(?,?,?)
|
||||
`,
|
||||
req.ItemID,
|
||||
req.ProjectID,
|
||||
req.Quantity,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user