rev cat getter by company id
This commit is contained in:
@@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user