rev cat getter by company id

This commit is contained in:
zipfriis
2026-03-25 19:07:57 +01:00
parent e056d8a37e
commit 206954fb75
6 changed files with 79 additions and 33 deletions

View File

@@ -1,10 +1,12 @@
package handlers
import (
"Portifolio/internal/database"
"Portifolio/internal/model"
"Portifolio/internal/service"
"database/sql"
"encoding/json"
"fmt"
"net/http"
_ "github.com/mattn/go-sqlite3"
@@ -69,3 +71,25 @@ func GetRevenueReportHandler(db *sql.DB) http.HandlerFunc {
}
}
*/
func GetCompanyRevenueCategories(db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var input struct {
CompanyID int `json:"company_id"`
}
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
http.Error(w, "invalid json", http.StatusBadRequest)
return
}
catlist, err := database.GetCategoriesByCompanyID(db, input.CompanyID)
if err != nil {
http.Error(w, fmt.Sprintf("Could not find categories by that id:%s", err), http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(map[string][]string{"list": catlist})
}
}