From 5fbd5af348cb3352f050fb7ba6ec69a8064c27a0 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 1 May 2022 11:18:08 +0200 Subject: [PATCH 1/7] admin: Display student needing help on home page --- help.go | 24 ++++++++++++++++++++++++ ui/src/lib/users.js | 9 +++++++++ ui/src/routes/index.svelte | 21 +++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/help.go b/help.go index fd891af..654f254 100644 --- a/help.go +++ b/help.go @@ -7,6 +7,9 @@ import ( ) func init() { + router.GET("/api/help", apiAuthHandler(func(u *User, ps httprouter.Params, body []byte) HTTPResponse { + return formatApiResponse(getNeedHelps()) + }, adminRestricted)) router.POST("/api/help", apiAuthHandler(func(u *User, ps httprouter.Params, body []byte) HTTPResponse { return formatApiResponse(u.NewNeedHelp()) }, loggedUser)) @@ -20,6 +23,27 @@ type NeedHelp struct { DateTreated *time.Time `json:"treated,omitempty"` } +func getNeedHelps() (nh []NeedHelp, err error) { + if rows, errr := DBQuery("SELECT id_need_help, id_user, date, comment, date_treated FROM user_need_help"); errr != nil { + return nil, errr + } else { + defer rows.Close() + + for rows.Next() { + var n NeedHelp + if err = rows.Scan(&n.Id, &n.IdUser, &n.Date, &n.Comment, &n.DateTreated); err != nil { + return + } + nh = append(nh, n) + } + if err = rows.Err(); err != nil { + return + } + + return + } +} + func (u *User) NewNeedHelp() (NeedHelp, error) { if res, err := DBExec("INSERT INTO user_need_help (id_user, comment) VALUES (?, ?)", u.Id, ""); err != nil { return NeedHelp{}, err diff --git a/ui/src/lib/users.js b/ui/src/lib/users.js index 51847e2..16eca87 100644 --- a/ui/src/lib/users.js +++ b/ui/src/lib/users.js @@ -51,6 +51,15 @@ export async function getUserScore(uid, survey) { } } +export async function getUserNeedingHelp() { + const res = await fetch(`api/help`, {headers: {'Accept': 'application/json'}}) + if (res.status == 200) { + return await res.json(); + } else { + throw new Error((await res.json()).errmsg); + } +} + export async function getScore(survey) { const res = await fetch(`api/surveys/${survey.id}/score`, {headers: {'Accept': 'application/json'}}) if (res.status == 200) { diff --git a/ui/src/routes/index.svelte b/ui/src/routes/index.svelte index 51dadce..f2090f0 100644 --- a/ui/src/routes/index.svelte +++ b/ui/src/routes/index.svelte @@ -1,5 +1,6 @@ + +
+ {#await req_proposals} +
+
+ Récupération des propositions… +
+ {:then} + {#await req_responses} +
+
+ Récupération des réponses… +
+ {:then} + + {/await} + {/await} +
diff --git a/ui/src/routes/surveys/[sid]/responses/[rid].svelte b/ui/src/routes/surveys/[sid]/responses/[rid].svelte index 1303d6b..c123530 100644 --- a/ui/src/routes/surveys/[sid]/responses/[rid].svelte +++ b/ui/src/routes/surveys/[sid]/responses/[rid].svelte @@ -13,6 +13,7 @@