Can share survey results with a secret shared key
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9fd73ce235
commit
fff8b821c5
10 changed files with 367 additions and 7 deletions
28
surveys.go
28
surveys.go
|
|
@ -204,6 +204,33 @@ func declareAPIAdminSurveysRoutes(router *gin.RouterGroup) {
|
|||
}
|
||||
})
|
||||
|
||||
surveysRoutes.GET("shares", func(c *gin.Context) {
|
||||
survey := c.MustGet("survey").(*Survey)
|
||||
|
||||
if sh, err := survey.getShares(); err != nil {
|
||||
log.Println("Unable to getShares survey:", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("An error occurs during survey shares listing: %s", err.Error())})
|
||||
return
|
||||
} else {
|
||||
c.JSON(http.StatusOK, sh)
|
||||
}
|
||||
})
|
||||
surveysRoutes.POST("shares", func(c *gin.Context) {
|
||||
survey := c.MustGet("survey").(*Survey)
|
||||
|
||||
if sh, err := survey.Share(); err != nil {
|
||||
log.Println("Unable to Share survey:", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("An error occurs during survey sharing: %s", err.Error())})
|
||||
return
|
||||
} else if url, err := sh.GetURL(); err != nil {
|
||||
log.Println("Unable to GetURL share:", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("An error occurs during survey sharing: %s", err.Error())})
|
||||
return
|
||||
} else {
|
||||
c.JSON(http.StatusOK, url.String())
|
||||
}
|
||||
})
|
||||
|
||||
declareAPIAdminAsksRoutes(surveysRoutes)
|
||||
declareAPIAdminDirectRoutes(surveysRoutes)
|
||||
declareAPIAdminQuestionsRoutes(surveysRoutes)
|
||||
|
|
@ -364,6 +391,7 @@ func (s *Survey) Update() (*Survey, error) {
|
|||
}
|
||||
|
||||
func (s Survey) Delete() (int64, error) {
|
||||
DBExec("DELETE FROM survey_shared WHERE id_survey = ?", s.Id)
|
||||
if res, err := DBExec("DELETE FROM surveys WHERE id_survey = ?", s.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
|
|
|
|||
Reference in a new issue