Add missing proposals route

This commit is contained in:
Pierre-Olivier Mercier 2022-02-21 07:16:25 +01:00
parent 6a632238d5
commit d4c809abed

View File

@ -12,6 +12,27 @@ func init() {
func(q Question, u *User, _ []byte) HTTPResponse {
return formatApiResponse(q.GetProposals())
}), loggedUser))
router.POST("/api/questions/:qid/proposals", apiAuthHandler(questionAuthHandler(func(q Question, u *User, body []byte) HTTPResponse {
var new Proposal
if err := json.Unmarshal(body, &new); err != nil {
return APIErrorResponse{err: err}
}
return formatApiResponse(q.NewProposal(new.Label))
}), adminRestricted))
router.PUT("/api/questions/:qid/proposals/:pid", apiAuthHandler(proposalAuthHandler(func(current Proposal, u *User, body []byte) HTTPResponse {
var new Proposal
if err := json.Unmarshal(body, &new); err != nil {
return APIErrorResponse{err: err}
}
new.Id = current.Id
return formatApiResponse(new.Update())
}), adminRestricted))
router.DELETE("/api/questions/:qid/proposals/:pid", apiAuthHandler(proposalAuthHandler(func(p Proposal, u *User, body []byte) HTTPResponse {
return formatApiResponse(p.Delete())
}), adminRestricted))
router.GET("/api/surveys/:sid/questions/:qid/proposals", apiAuthHandler(questionAuthHandler(
func(q Question, u *User, _ []byte) HTTPResponse {
return formatApiResponse(q.GetProposals())