👔 Update answer if the poll answered

This commit is contained in:
2025-02-13 22:19:37 +08:00
parent e16201a3ad
commit a2633e6494
3 changed files with 24 additions and 18 deletions

View File

@ -12,6 +12,22 @@ import (
"github.com/gofiber/fiber/v2"
)
func getMyPollAnswer(c *fiber.Ctx) error {
if err := sec.EnsureAuthenticated(c); err != nil {
return err
}
user := c.Locals("user").(authm.Account)
pollId, _ := c.ParamsInt("pollId")
var answer models.PollAnswer
if err := database.C.Where("poll_id = ? AND account_id = ?", pollId, user.ID).First(&answer).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
return c.JSON(answer)
}
func answerPoll(c *fiber.Ctx) error {
pollId, _ := c.ParamsInt("pollId")

View File

@ -12,22 +12,6 @@ import (
"github.com/gofiber/fiber/v2"
)
func getMyPollAnswer(c *fiber.Ctx) error {
if err := sec.EnsureAuthenticated(c); err != nil {
return err
}
user := c.Locals("user").(authm.Account)
pollId, _ := c.ParamsInt("pollId")
var answer models.PollAnswer
if err := database.C.Where("poll_id = ? AND account_id = ?", pollId, user.ID).First(&answer).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
return c.JSON(answer)
}
func getPoll(c *fiber.Ctx) error {
pollId, _ := c.ParamsInt("pollId")