35 lines
570 B
Go
35 lines
570 B
Go
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
|
|
}
|
|
}
|