forked from krakowski/ilias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise_comment.go
55 lines (44 loc) · 1.06 KB
/
exercise_comment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ilias
import (
"io/ioutil"
"net/http"
"net/url"
"strings"
)
const (
commentPath = "ilias.php?vw=1&cmd=saveCommentForLearners&cmdClass=ilexercisemanagementgui&cmdNode=c8:o5:c9&baseClass=ilExerciseHandlerGUI&cmdMode=asynch"
)
type CommentParams struct {
Reference string `schema:"ref_id"`
Assignment string `schema:"ass_id"`
}
func (exercise *ExerciseService) UpdateComment(params *CommentParams, correction Correction) error {
// Prepare request url
path, err := addQueryParams(commentPath, params)
if err != nil {
return err
}
values := url.Values{
"ass_id": {params.Assignment},
"mem_id": {correction.Student},
"comm": {correction.Correction},
}
req, err := exercise.client.NewRequest(http.MethodPost, path, values)
if err != nil {
return err
}
// Retrieve the HTML source
resp, err := exercise.client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
if !strings.HasPrefix(string(body), "{\"result\":true") {
return ErrUpdate
}
return nil
}