Can share survey results with a secret shared key
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-12-02 11:48:10 +01:00
commit fff8b821c5
10 changed files with 367 additions and 7 deletions

View file

@ -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 {