dashboard locations and projects will now show items
This commit is contained in:
@@ -21,14 +21,20 @@ func Location(w http.ResponseWriter, r *http.Request) {
|
||||
contentMode := r.URL.Query().Get("content")
|
||||
|
||||
if idStr != "" && contentMode == "true" {
|
||||
_, _ = strconv.Atoi(idStr)
|
||||
locationID, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid location ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT s.item_id, i.name, s.quantity
|
||||
FROM stock s
|
||||
JOIN items i ON s.item_id = i.id
|
||||
WHERE s.location_id = ? AND s.quantity > 0
|
||||
`
|
||||
rows, err := storage.DB.Query(query)
|
||||
SELECT s.item_id, i.name, s.quantity
|
||||
FROM stock s
|
||||
JOIN items i ON s.item_id = i.id
|
||||
WHERE s.location_id = ? AND s.quantity > 0
|
||||
`
|
||||
|
||||
rows, err := storage.DB.Query(query, locationID)
|
||||
if err != nil {
|
||||
http.Error(w, "Database error", http.StatusInternalServerError)
|
||||
return
|
||||
@@ -38,9 +44,13 @@ func Location(w http.ResponseWriter, r *http.Request) {
|
||||
var contents []models.LocationContent
|
||||
for rows.Next() {
|
||||
var c models.LocationContent
|
||||
rows.Scan(&c.ItemID, &c.ItemName, &c.Quantity)
|
||||
if err := rows.Scan(&c.ItemID, &c.ItemName, &c.Quantity); err != nil {
|
||||
http.Error(w, "Row scan error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
contents = append(contents, c)
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"contents": contents})
|
||||
return
|
||||
}
|
||||
@@ -348,14 +358,20 @@ func Project(w http.ResponseWriter, r *http.Request) {
|
||||
detailsMode := r.URL.Query().Get("details")
|
||||
|
||||
if idStr != "" && detailsMode == "true" {
|
||||
_, _ = strconv.Atoi(idStr)
|
||||
projectID, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid project ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT pi.item_id, i.name, pi.quantity
|
||||
FROM project_items pi
|
||||
JOIN items i ON pi.item_id = i.id
|
||||
WHERE pi.project_id = ?
|
||||
`
|
||||
rows, err := storage.DB.Query(query)
|
||||
SELECT pi.item_id, i.name, pi.quantity
|
||||
FROM project_items pi
|
||||
JOIN items i ON pi.item_id = i.id
|
||||
WHERE pi.project_id = ?
|
||||
`
|
||||
|
||||
rows, err := storage.DB.Query(query, projectID)
|
||||
if err != nil {
|
||||
http.Error(w, "Database error", http.StatusInternalServerError)
|
||||
return
|
||||
@@ -365,9 +381,13 @@ func Project(w http.ResponseWriter, r *http.Request) {
|
||||
var details []models.ProjectDetailItem
|
||||
for rows.Next() {
|
||||
var d models.ProjectDetailItem
|
||||
rows.Scan(&d.ItemID, &d.ItemName, &d.Quantity)
|
||||
if err := rows.Scan(&d.ItemID, &d.ItemName, &d.Quantity); err != nil {
|
||||
http.Error(w, "Row scan error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
details = append(details, d)
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"items": details})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user