Use pointer receiver more offen
This commit is contained in:
parent
6999b4e728
commit
c7569b5e54
59 changed files with 688 additions and 672 deletions
|
|
@ -14,7 +14,7 @@ func init() {
|
|||
router.GET("/api/exercices/:eid", apiHandler(exerciceHandler(showExercice)))
|
||||
}
|
||||
|
||||
func exerciceHandler(f func(QAUser, fic.Exercice, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
func exerciceHandler(f func(QAUser, *fic.Exercice, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(u QAUser, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if eid, err := strconv.ParseInt(string(ps.ByName("eid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -31,6 +31,6 @@ func listExercices(_ QAUser, _ httprouter.Params, body []byte) (interface{}, err
|
|||
return fic.GetExercices()
|
||||
}
|
||||
|
||||
func showExercice(_ QAUser, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showExercice(_ QAUser, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice, nil
|
||||
}
|
||||
|
|
|
|||
30
qa/api/qa.go
30
qa/api/qa.go
|
|
@ -23,9 +23,9 @@ func init() {
|
|||
router.DELETE("/api/qa/:eid/:qid/comments/:cid", apiHandler(qaCommentHandler(deleteQAComment)))
|
||||
}
|
||||
|
||||
func qaHandler(f func(QAUser, fic.QAQuery, fic.Exercice, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
func qaHandler(f func(QAUser, *fic.QAQuery, *fic.Exercice, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(u QAUser, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
return exerciceHandler(func(u QAUser, exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return exerciceHandler(func(u QAUser, exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
if qid, err := strconv.ParseInt(string(ps.ByName("qid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if query, err := exercice.GetQAQuery(qid); err != nil {
|
||||
|
|
@ -37,9 +37,9 @@ func qaHandler(f func(QAUser, fic.QAQuery, fic.Exercice, []byte) (interface{}, e
|
|||
}
|
||||
}
|
||||
|
||||
func qaCommentHandler(f func(QAUser, fic.QAComment, fic.QAQuery, fic.Exercice, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
func qaCommentHandler(f func(QAUser, *fic.QAComment, *fic.QAQuery, *fic.Exercice, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(u QAUser, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
return qaHandler(func(u QAUser, query fic.QAQuery, exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return qaHandler(func(u QAUser, query *fic.QAQuery, exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
if cid, err := strconv.ParseInt(string(ps.ByName("cid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if comment, err := query.GetComment(cid); err != nil {
|
||||
|
|
@ -51,13 +51,13 @@ func qaCommentHandler(f func(QAUser, fic.QAComment, fic.QAQuery, fic.Exercice, [
|
|||
}
|
||||
}
|
||||
|
||||
func getExerciceQA(_ QAUser, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func getExerciceQA(_ QAUser, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice.GetQAQueries()
|
||||
}
|
||||
|
||||
func createExerciceQA(u QAUser, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func createExerciceQA(u QAUser, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
// Create a new query
|
||||
var uq fic.QAQuery
|
||||
var uq *fic.QAQuery
|
||||
if err := json.Unmarshal(body, &uq); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ func createExerciceQA(u QAUser, exercice fic.Exercice, body []byte) (interface{}
|
|||
if qa, err := exercice.NewQAQuery(uq.Subject, &u.TeamId, u.User, uq.State); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
var uc fic.QAComment
|
||||
var uc *fic.QAComment
|
||||
if err := json.Unmarshal(body, &uc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -90,8 +90,8 @@ func createExerciceQA(u QAUser, exercice fic.Exercice, body []byte) (interface{}
|
|||
}
|
||||
}
|
||||
|
||||
func updateExerciceQA(u QAUser, query fic.QAQuery, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uq fic.QAQuery
|
||||
func updateExerciceQA(u QAUser, query *fic.QAQuery, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uq *fic.QAQuery
|
||||
if err := json.Unmarshal(body, &uq); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ func updateExerciceQA(u QAUser, query fic.QAQuery, exercice fic.Exercice, body [
|
|||
}
|
||||
}
|
||||
|
||||
func deleteExerciceQA(u QAUser, query fic.QAQuery, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func deleteExerciceQA(u QAUser, query *fic.QAQuery, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
if u.User != query.User {
|
||||
return nil, errors.New("You can only delete your own entry.")
|
||||
}
|
||||
|
|
@ -117,13 +117,13 @@ func deleteExerciceQA(u QAUser, query fic.QAQuery, exercice fic.Exercice, body [
|
|||
return query.Delete()
|
||||
}
|
||||
|
||||
func getQAComments(_ QAUser, query fic.QAQuery, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func getQAComments(_ QAUser, query *fic.QAQuery, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return query.GetComments()
|
||||
}
|
||||
|
||||
func createQAComment(u QAUser, query fic.QAQuery, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func createQAComment(u QAUser, query *fic.QAQuery, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
// Create a new query
|
||||
var uc fic.QAComment
|
||||
var uc *fic.QAComment
|
||||
if err := json.Unmarshal(body, &uc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -135,7 +135,7 @@ func createQAComment(u QAUser, query fic.QAQuery, exercice fic.Exercice, body []
|
|||
return query.AddComment(uc.Content, &u.TeamId, u.User)
|
||||
}
|
||||
|
||||
func deleteQAComment(u QAUser, comment fic.QAComment, query fic.QAQuery, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func deleteQAComment(u QAUser, comment *fic.QAComment, query *fic.QAQuery, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
if u.User != comment.User {
|
||||
return nil, errors.New("You can only delete your own comment.")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func init() {
|
|||
router.GET("/api/themes/:thid/exercices/:eid", apiHandler(exerciceHandler(showExercice)))
|
||||
}
|
||||
|
||||
func themeHandler(f func(QAUser, fic.Theme, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
func themeHandler(f func(QAUser, *fic.Theme, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(u QAUser, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if thid, err := strconv.ParseInt(string(ps.ByName("thid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -31,13 +31,13 @@ func themeHandler(f func(QAUser, fic.Theme, []byte) (interface{}, error)) func(Q
|
|||
}
|
||||
}
|
||||
|
||||
func getExercice(args []string) (fic.Exercice, error) {
|
||||
func getExercice(args []string) (*fic.Exercice, error) {
|
||||
if tid, err := strconv.ParseInt(string(args[0]), 10, 64); err != nil {
|
||||
return fic.Exercice{}, err
|
||||
return nil, err
|
||||
} else if theme, err := fic.GetTheme(tid); err != nil {
|
||||
return fic.Exercice{}, err
|
||||
return nil, err
|
||||
} else if eid, err := strconv.Atoi(string(args[1])); err != nil {
|
||||
return fic.Exercice{}, err
|
||||
return nil, err
|
||||
} else {
|
||||
return theme.GetExercice(eid)
|
||||
}
|
||||
|
|
@ -51,14 +51,14 @@ func exportThemes(_ QAUser, _ httprouter.Params, _ []byte) (interface{}, error)
|
|||
return fic.ExportThemes()
|
||||
}
|
||||
|
||||
func showTheme(_ QAUser, theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
func showTheme(_ QAUser, theme *fic.Theme, _ []byte) (interface{}, error) {
|
||||
return theme, nil
|
||||
}
|
||||
|
||||
func listThemedExercices(_ QAUser, theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
func listThemedExercices(_ QAUser, theme *fic.Theme, _ []byte) (interface{}, error) {
|
||||
return theme.GetExercices()
|
||||
}
|
||||
|
||||
func showThemedExercice(_ QAUser, theme fic.Theme, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showThemedExercice(_ QAUser, theme *fic.Theme, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func getExerciceTested(u QAUser, ps httprouter.Params, body []byte) (interface{}
|
|||
|
||||
for _, exercice := range exercices {
|
||||
if team.HasAccess(exercice) {
|
||||
if ok, _ := team.HasSolved(exercice); ok {
|
||||
if t := team.HasSolved(exercice); t != nil {
|
||||
ret[exercice.Id] = "solved"
|
||||
} else if cnt, _ := team.CountTries(exercice); cnt > 0 {
|
||||
ret[exercice.Id] = "tried"
|
||||
|
|
@ -74,7 +74,7 @@ func getQATodo(u QAUser, ps httprouter.Params, body []byte) (interface{}, error)
|
|||
} else {
|
||||
for _, exercice := range exercices {
|
||||
if cnt, _ := team.CountTries(exercice); cnt > 0 {
|
||||
todo = append(todo, fic.QATodo{0, team.Id, exercice.Id})
|
||||
todo = append(todo, &fic.QATodo{0, team.Id, exercice.Id})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue