Completed db rewrite

This commit is contained in:
Manuel Forcén Muñoz 2025-04-16 23:24:23 +02:00
parent 54d7d14ef9
commit cf4b8e0119
19 changed files with 481 additions and 276 deletions

View file

@ -25,7 +25,7 @@ func getPoll(c *gin.Context) {
}
fmt.Println(params)
poll, _ := core.GetPoll(db, *user, params.PollId)
poll, _ := core.PollGet(db, *user, params.PollId)
c.JSON(http.StatusOK, poll)
}
@ -45,9 +45,12 @@ func getPollVotes(c *gin.Context) {
return
}
var votes []core.Vote
db.Where("poll_id = ?", params.PollId).Find(&votes)
c.JSON(http.StatusOK, &votes)
votes, err := core.VotesList(db, int(params.PollId))
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
c.JSON(http.StatusOK, votes)
}
func pollVote(c *gin.Context) {
@ -66,7 +69,7 @@ func pollVote(c *gin.Context) {
return
}
poll, err := core.GetPoll(db, *user, path_params.PollId)
poll, err := core.PollGet(db, *user, path_params.PollId)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
@ -77,7 +80,19 @@ func pollVote(c *gin.Context) {
}
c.Bind(&vote_params)
if err := poll.SetVote(db, *user, vote_params.Vote); err != nil {
plan, err := core.PlanGet(db, poll.PlanId)
if err != nil {
c.String(http.StatusInternalServerError, "Unable to find plan: "+err.Error())
return
}
member, err := user.GetMemberFromPlan(db, *plan)
if err != nil {
c.String(http.StatusInternalServerError, "Unable to find member: "+err.Error())
return
}
if err := poll.SetVote(db, *member, vote_params.Vote); err != nil {
c.String(http.StatusBadRequest, err.Error())
}