Skip to content
Snippets Groups Projects
Commit 8512ebd1 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

fix(MonthlyReport): acces to monthlyReport using query params

parent 6eb63808
No related branches found
No related tags found
2 merge requests!14feat: addprices + subject managment,!11feat: Add partners issue info
Pipeline #17912 passed
...@@ -3,6 +3,7 @@ package models ...@@ -3,6 +3,7 @@ package models
import ( import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"strconv"
"time" "time"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/common" "forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/common"
...@@ -32,8 +33,16 @@ type MonthlyReport struct { ...@@ -32,8 +33,16 @@ type MonthlyReport struct {
func (dh *DataHandler) GetMonthlyReport(w http.ResponseWriter, r *http.Request) { func (dh *DataHandler) GetMonthlyReport(w http.ResponseWriter, r *http.Request) {
year, month, err := common.YearMonthFromRequest(r) year, month, err := common.YearMonthFromRequest(r)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) year, err = strconv.Atoi(r.URL.Query().Get("year"))
return if err != nil {
http.Error(w, "year in query is not an integer", http.StatusBadRequest)
return
}
month, err = strconv.Atoi(r.URL.Query().Get("month"))
if err != nil {
http.Error(w, "month in query is not an integer", http.StatusBadRequest)
return
}
} }
monthlyReport, err := dh.getMonthlyReport(year, month) monthlyReport, err := dh.getMonthlyReport(year, month)
......
...@@ -36,7 +36,7 @@ func CreateRootMux() RootMux { ...@@ -36,7 +36,7 @@ func CreateRootMux() RootMux {
r.HandleFunc("/Logout", m.HandleLogout) r.HandleFunc("/Logout", m.HandleLogout)
r.Handle("/api/common/WhoAmI", auth.ValidateAuthMiddleware(auth.WhoAmI(), []string{"*"}, false)) r.Handle("/api/common/WhoAmI", auth.ValidateAuthMiddleware(auth.WhoAmI(), []string{"*"}, false))
r.HandleFunc("/api/common/monthlyReport", dh.GetCurrentMonthlyReport).Methods(http.MethodGet) r.HandleFunc("/api/common/monthlyReport", dh.GetMonthlyReport).Methods(http.MethodGet)
r.HandleFunc("/api/common/monthlyReport/{year}/{month}", dh.GetMonthlyReport).Methods(http.MethodGet) r.HandleFunc("/api/common/monthlyReport/{year}/{month}", dh.GetMonthlyReport).Methods(http.MethodGet)
apiAdmin := r.PathPrefix("/api/admin").Subrouter() apiAdmin := r.PathPrefix("/api/admin").Subrouter()
......
...@@ -94,8 +94,10 @@ func unloggedTests(t *testing.T) { ...@@ -94,8 +94,10 @@ func unloggedTests(t *testing.T) {
// Try to create a monthlyNews (must fail) // Try to create a monthlyNews (must fail)
do("PUT", "/api/admin/monthlyNews", noH, monthlyNewsStr, http.StatusUnauthorized, "error extracting token") do("PUT", "/api/admin/monthlyNews", noH, monthlyNewsStr, http.StatusUnauthorized, "error extracting token")
// Try to get the most recent monthlyReport (must fail because not found) // Try to get a monthlyReport (must fail because no parameters are given)
do("GET", "/api/common/monthlyReport", noH, "", http.StatusNotFound, "") do("GET", "/api/common/monthlyReport", noH, "", http.StatusBadRequest, "")
// Try to get a monthlyReport (must fail because not found)
do("GET", "/api/common/monthlyReport?year=2021&month=12", noH, "", http.StatusNotFound, "")
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment