Can filter by project to get a HTTP status code Ok or NotFound
This commit is contained in:
parent
eb6427ec6c
commit
eec4b1b19e
33
main.go
33
main.go
@ -199,12 +199,37 @@ func ServeJSONStudent(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
login := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, "/"), ".json")
|
login := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, "/"), ".json")
|
||||||
|
|
||||||
if j, err := json.Marshal(genStudent(login)); err != nil {
|
var ret []byte
|
||||||
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusInternalServerError)
|
status := http.StatusOK
|
||||||
|
|
||||||
|
if len(r.URL.Query().Get("rendu")) > 0 {
|
||||||
|
limit := r.URL.Query().Get("rendu")
|
||||||
|
for k, v := range genStudent(login) {
|
||||||
|
if limit == k {
|
||||||
|
r, err := json.Marshal(v)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if v == nil {
|
||||||
|
status = http.StatusNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = append(ret, r...)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusOK)
|
var err error
|
||||||
w.Write(j)
|
ret, err = json.Marshal(genStudent(login))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(status)
|
||||||
|
w.Write(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
type arrayFlags []string
|
type arrayFlags []string
|
||||||
|
Reference in New Issue
Block a user